diff --git a/community/kernel/src/test/java/org/neo4j/kernel/RecoveryCorruptedTransactionLogIT.java b/community/kernel/src/test/java/org/neo4j/kernel/RecoveryCorruptedTransactionLogIT.java index a8a9a47253cbe..0d1e095565576 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/RecoveryCorruptedTransactionLogIT.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/RecoveryCorruptedTransactionLogIT.java @@ -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; @@ -130,7 +130,7 @@ public void evenTruncateNewerTransactionLogFile() throws IOException lastClosedTrandactionBeforeStart; database.shutdown(); removeLastCheckpointRecordFromLastLogFile(); - addRandomLongsToLastLogFile(); + addRandomBytesToLastLogFile( this::randomBytes ); database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); database.shutdown(); @@ -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 ) ); @@ -170,7 +170,7 @@ public void truncateNewerTransactionLogFileWhenForced() throws IOException database.shutdown(); removeLastCheckpointRecordFromLastLogFile(); - addRandomLongsToLastLogFile(); + addRandomBytesToLastLogFile( this::randomBytes ); database = (GraphDatabaseAPI) databaseFactory.newEmbeddedDatabase( storeDir ); database.shutdown(); @@ -454,7 +454,7 @@ private void truncateBytesFromLastLogFile( long bytesToTrim ) throws IOException } } - private void addRandomLongsToLastLogFile() throws IOException + private void addRandomBytesToLastLogFile( Supplier byteSource ) throws IOException { PositiveLogFilesBasedLogVersionRepository versionRepository = new PositiveLogFilesBasedLogVersionRepository( logFiles ); @@ -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 {