Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2002-2014 "Neo Technology," Network Engine for Objects in Lund AB [http://neotechnology.com] This file is part of Neo4j. Neo4j is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 package recovery;
 
 import static java.nio.ByteBuffer.allocate;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 import static org.neo4j.helpers.collection.MapUtil.stringMap;
 import static org.neo4j.kernel.impl.transaction.xaframework.VersionAwareLogEntryReader.readLogHeader;
 import static recovery.CreateTransactionsAndDie.produceNonCleanDbWhichWillRecover2PCsOnStartup;
 
 import java.io.File;
 
 import org.junit.Test;
 
 {
     private static class TestGraphDatabase extends InternalAbstractGraphDatabase
     {
         private final RecoveryVerifier verifier;
 
         TestGraphDatabaseString dirRecoveryVerifier recoveryVerifier )
         {
             superdirstringMap(), new DefaultGraphDatabaseDependencies() );
             this. = recoveryVerifier;
             run();
         }
 
         @Override
         protected RecoveryVerifier createRecoveryVerifier()
         {
             return this.;
         }
     }
 
     @Test
     {
         int count = 2;
         String dir = produceNonCleanDbWhichWillRecover2PCsOnStartup"count"count );
         CountingRecoveryVerifier countingVerifier = new CountingRecoveryVerifier();
         GraphDatabaseService db = new TestGraphDatabasedircountingVerifier );
         assertEquals( 2, countingVerifier.count2PC );
         db.shutdown();
     }
 
     @Test
     {
         String dir = produceNonCleanDbWhichWillRecover2PCsOnStartup"fail", 2 );
         RecoveryVerifier failingVerifier = new RecoveryVerifier()
         {
             @Override
             public boolean isValidTransactionInfo txInfo )
             {
                 return false;
             }
         };
 
         try
         {
             new TestGraphDatabasedirfailingVerifier );
             fail"Was expecting recovery exception" );
        }
        catch ( RuntimeException e )
        {
            assertEqualse.getMessage(), RecoveryVerificationException.classe.getCause().getClass() );
        }
    }
    @Test
    {
        int count = 10;
        String dir = produceNonCleanDbWhichWillRecover2PCsOnStartup"order"count );
        // Just make it recover
                .. ).newGraphDatabase().shutdown();
        verifyOrderedRecordsdircount );
    }
    private void verifyOrderedRecordsString storeDirint expectedCount ) throws IOException
    {
        /* Look in the .v0 log for the 2PC records and that they are ordered by txId */
        RandomAccessFile file = new RandomAccessFilenew FilestoreDir"nioneo_logical.log.v0" ), "r" );
        ByteBuffer buffer = allocate( 10000 );
        try
        {
            FileChannel channel = file.getChannel();
            readLogHeaderbufferchanneltrue );
            final AtomicInteger counted = new AtomicInteger(  );
            LogDeserializer deserializer = new LogDeserializerbuffer. );
            Consumer<LogEntryIOExceptionconsumer = new Consumer<LogEntryIOException>()
            {
                long lastOne = -1;
                @Override
                public boolean acceptLogEntry entry ) throws IOException
                {
                    if ( entry instanceof LogEntry.TwoPhaseCommit )
                    {
                        long txId = ((LogEntry.TwoPhaseCommitentry).getTxId();
                        if (  != -1 )
                        {
                            assertEquals + 1, txId );
                        }
                         = txId;
                        counted.incrementAndGet();
                    }
                    return true;
                }
            };
            Cursor<LogEntryIOExceptionc = deserializer.cursorchannel );
            while ( c.nextconsumer ) );
            assertEqualsexpectedCountcounted.get() );
        }
        finally
        {
            file.close();
        }
    }
    private static class CountingRecoveryVerifier implements RecoveryVerifier
    {
        private int count2PC;
        @Override
        public boolean isValidTransactionInfo txInfo )
        {
            if ( !txInfo.isOnePhase() )
            {
                ++;
            }
            return true;
        }
    }
New to GrepCode? Check out our FAQ X