Skip to content

Commit

Permalink
Generate positive random bytes to get expected error in RecoveryCorru…
Browse files Browse the repository at this point in the history
…ptedTransactionLogIT

Use random rule generator only, generate random positive bytes to be
able to fail always version selection.
  • Loading branch information
MishaDemianenko committed Oct 20, 2017
1 parent c493c64 commit dbca826
Showing 1 changed file with 16 additions and 7 deletions.
Expand Up @@ -32,7 +32,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;

import org.neo4j.graphdb.DependencyResolver;
import org.neo4j.graphdb.GraphDatabaseService;
Expand Down Expand Up @@ -130,7 +130,7 @@ public void evenTruncateNewerTransactionLogFile() throws IOException
lastClosedTrandactionBeforeStart;
database.shutdown();
removeLastCheckpointRecordFromLastLogFile();
addRandomLongsToLastLogFile();
addRandomBytesToLastLogFile( this::randomBytes );

database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir );
database.shutdown();
Expand All @@ -148,7 +148,7 @@ public void doNotTruncateNewerTransactionLogFileWhenFailOnError() throws IOExcep
}
database.shutdown();
removeLastCheckpointRecordFromLastLogFile();
addRandomLongsToLastLogFile();
addRandomBytesToLastLogFile( this::randomPositiveBytes );

FeatureToggles.set( NeoStoreDataSource.class, "failOnCorruptedLogFiles", true );
expectedException.expectCause( new RootCauseMatcher<>( UnsupportedLogVersionException.class ) );
Expand All @@ -170,7 +170,7 @@ public void truncateNewerTransactionLogFileWhenForced() throws IOException
database.shutdown();

removeLastCheckpointRecordFromLastLogFile();
addRandomLongsToLastLogFile();
addRandomBytesToLastLogFile( this::randomBytes );

database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir );
database.shutdown();
Expand Down Expand Up @@ -454,7 +454,7 @@ private void truncateBytesFromLastLogFile( long bytesToTrim ) throws IOException
}
}

private void addRandomLongsToLastLogFile() throws IOException
private void addRandomBytesToLastLogFile( Supplier<Byte> byteSource ) throws IOException
{
PositiveLogFilesBasedLogVersionRepository versionRepository =
new PositiveLogFilesBasedLogVersionRepository( logFiles );
Expand All @@ -466,14 +466,23 @@ private void addRandomLongsToLastLogFile() throws IOException
lifespan.add( physicalLogFile );

FlushablePositionAwareChannel logFileWriter = physicalLogFile.getWriter();
ThreadLocalRandom current = ThreadLocalRandom.current();
for ( int i = 0; i < 10; i++ )
{
logFileWriter.putLong( current.nextLong() );
logFileWriter.put( byteSource.get() );
}
}
}

private byte randomPositiveBytes()
{
return (byte) random.nextInt( 0, Byte.MAX_VALUE );
}

private byte randomBytes()
{
return (byte) random.nextInt( Byte.MIN_VALUE, Byte.MAX_VALUE );
}

private PositiveLogFilesBasedLogVersionRepository addCorruptedCommandsToLastLogFile()
throws IOException
{
Expand Down

0 comments on commit dbca826

Please sign in to comment.