Skip to content

Commit

Permalink
Merge pull request #10287 from MishaDemianenko/3.4-corrupted-logs-it
Browse files Browse the repository at this point in the history
Generate positive random bytes to get expected error in RecoveryCorruptedTransactionLogIT
  • Loading branch information
MishaDemianenko committed Oct 20, 2017
2 parents 3848ee6 + dbca826 commit db6cd2e
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
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 db6cd2e

Please sign in to comment.