Skip to content

Commit

Permalink
Different key contention in GBPTreeRecoveryTest
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Mar 10, 2017
1 parent af84007 commit 1aa4130
Showing 1 changed file with 37 additions and 6 deletions.
Expand Up @@ -36,7 +36,6 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.test.rule.PageCacheRule;
import org.neo4j.test.rule.RandomRule;
import org.neo4j.test.rule.RandomRule.Seed;
import org.neo4j.test.rule.TestDirectory;
import org.neo4j.test.rule.fs.EphemeralFileSystemRule;

Expand Down Expand Up @@ -68,6 +67,10 @@ public class GBPTreeRecoveryTest
private final MutableLong key = new MutableLong();
private final MutableLong value = new MutableLong();

/* Global variables for recoverFromAnything test */
private boolean recoverFromAnythingInitialized;
private int keyRange;

@Test
public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
{
Expand Down Expand Up @@ -97,6 +100,7 @@ public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
{
// this is the mimic:ed recovery
index.prepareForRecovery();
index.completeRecovery();

try ( Writer<MutableLong,MutableLong> writer = index.writer() )
{
Expand All @@ -120,20 +124,47 @@ public void shouldRecoverFromCrashBeforeFirstCheckpoint() throws Exception
}

@Test
public void shouldRecoverFromAnythingReplayExactFromCheckpoint() throws Exception
public void shouldRecoverFromAnythingReplayExactFromCheckpointHighKeyContention() throws Exception
{
initializeRecoveryFromAnythingTest( 100 );
doShouldRecoverFromAnything( true );
}

@Test
public void shouldRecoverFromAnythingReplayFromBeforeLastCheckpointHighKeyContention() throws Exception
{
initializeRecoveryFromAnythingTest( 100 );
doShouldRecoverFromAnything( false );
}

@Test
public void shouldRecoverFromAnythingReplayExactFromCheckpointLowKeyContention() throws Exception
{
initializeRecoveryFromAnythingTest( 1_000_000 );
doShouldRecoverFromAnything( true );
}

@Seed( 1488879322788L )
@Test
public void shouldRecoverFromAnythingReplayFromBeforeLastCheckpoint() throws Exception
public void shouldRecoverFromAnythingReplayFromBeforeLastCheckpointLowKeyContention() throws Exception
{
initializeRecoveryFromAnythingTest( 1_000_000 );
doShouldRecoverFromAnything( false );
}

private void initializeRecoveryFromAnythingTest( int keyRange )
{
recoverFromAnythingInitialized = true;
this.keyRange = keyRange;
}

private void assertInitialized()
{
assertTrue( recoverFromAnythingInitialized );
}

private void doShouldRecoverFromAnything( boolean replayRecoveryExactlyFromCheckpoint ) throws Exception
{
assertInitialized();
// GIVEN
// a tree which has had random updates and checkpoints in it, load generated with specific seed
File file = directory.file( "index" );
Expand Down Expand Up @@ -357,8 +388,8 @@ private long[] modificationData( int min, int max )
long[] data = new long[count * 2];
for ( int i = 0, c = 0; i < count; i++ )
{
data[c++] = random.intBetween( 0, 1_000_000 ); // key
data[c++] = random.intBetween( 0, 1_000_000 ); // value
data[c++] = random.intBetween( 0, keyRange ); // key
data[c++] = random.intBetween( 0, keyRange ); // value
}
return data;
}
Expand Down

0 comments on commit 1aa4130

Please sign in to comment.