Skip to content

Commit

Permalink
Deduplicated test code block
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Sep 13, 2016
1 parent 5b41b7d commit 275acbf
Showing 1 changed file with 21 additions and 43 deletions.
64 changes: 21 additions & 43 deletions community/kernel/src/test/java/org/neo4j/kernel/RecoveryTest.java
Expand Up @@ -288,41 +288,11 @@ public boolean visit( Pair<LogEntryWriter,Consumer<LogPositionMarker>> pair ) th
}
} );

LifeSupport life = new LifeSupport();
Recovery.Monitor monitor = mock( Recovery.Monitor.class );
final AtomicBoolean recoveryRequired = new AtomicBoolean();
try
{
StorageEngine storageEngine = mock( StorageEngine.class );
final LogEntryReader<ReadableClosablePositionAwareChannel> reader = new VersionAwareLogEntryReader<>();
LatestCheckPointFinder finder = new LatestCheckPointFinder( logFiles, fs, reader );

TransactionMetadataCache metadataCache = new TransactionMetadataCache( 100 );
LogHeaderCache logHeaderCache = new LogHeaderCache( 10 );
LogFile logFile = life.add( new PhysicalLogFile( fs, logFiles, 50,
() -> transactionIdStore.getLastCommittedTransactionId(), logVersionRepository,
mock( PhysicalLogFile.Monitor.class ), logHeaderCache ) );
LogicalTransactionStore txStore = new PhysicalLogicalTransactionStore( logFile, metadataCache, reader );

life.add( new Recovery( new DefaultRecoverySPI( storageEngine,
logFiles, fs, logVersionRepository, finder, transactionIdStore, txStore )
{
@Override
public Visitor<CommittedTransactionRepresentation,Exception> startRecovery()
{
recoveryRequired.set( true );
return super.startRecovery();
}
}, monitor ) );
// WHEN
boolean recoveryRequired = recover( logFiles );

life.start();
}
finally
{
life.shutdown();
}

assertTrue( recoveryRequired.get() );
// THEN
assertTrue( recoveryRequired );
assertEquals( marker.getByteOffset(), file.length() );
}

Expand Down Expand Up @@ -356,6 +326,22 @@ public boolean visit( Pair<LogEntryWriter,Consumer<LogPositionMarker>> pair ) th
}
} );

// WHEN
boolean recoveryRequired = recover( logFiles );

// THEN
assertTrue( recoveryRequired );
long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
assertEquals( transactionId, lastClosedTransaction[0] );
assertEquals( LogEntryStart.checksum( additionalHeaderData, masterId, authorId ),
transactionIdStore.getLastCommittedTransaction().checksum() );
assertEquals( commitTimestamp, transactionIdStore.getLastCommittedTransaction().commitTimestamp() );
assertEquals( logVersion, lastClosedTransaction[1] );
assertEquals( marker.getByteOffset(), lastClosedTransaction[2] );
}

private boolean recover( PhysicalLogFiles logFiles )
{
LifeSupport life = new LifeSupport();
Recovery.Monitor monitor = mock( Recovery.Monitor.class );
final AtomicBoolean recoveryRequired = new AtomicBoolean();
Expand Down Expand Up @@ -389,15 +375,7 @@ public Visitor<CommittedTransactionRepresentation,Exception> startRecovery()
{
life.shutdown();
}

assertTrue( recoveryRequired.get() );
long[] lastClosedTransaction = transactionIdStore.getLastClosedTransaction();
assertEquals( transactionId, lastClosedTransaction[0] );
assertEquals( LogEntryStart.checksum( additionalHeaderData, masterId, authorId ),
transactionIdStore.getLastCommittedTransaction().checksum() );
assertEquals( commitTimestamp, transactionIdStore.getLastCommittedTransaction().commitTimestamp() );
assertEquals( logVersion, lastClosedTransaction[1] );
assertEquals( marker.getByteOffset(), lastClosedTransaction[2] );
return recoveryRequired.get();
}

private void writeSomeData( File file, Visitor<Pair<LogEntryWriter,Consumer<LogPositionMarker>>,IOException> visitor ) throws IOException
Expand Down

0 comments on commit 275acbf

Please sign in to comment.