Skip to content

Commit

Permalink
Acceptance test for SeekCursor tripCounter
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Mar 13, 2019
1 parent 835f7ef commit 19b91f8
Showing 1 changed file with 38 additions and 1 deletion.
Expand Up @@ -87,7 +87,9 @@ public long getAsLong()
private static long unstableGeneration = stableGeneration + 1;

private long rootId;
private long rootGeneration;
private int numberOfRootSplits;
private Supplier<Root> realRootCatchup = () -> new Root( rootId, rootGeneration );

@Before
public void setUp() throws IOException
Expand Down Expand Up @@ -121,6 +123,7 @@ private static void goTo( PageCursor cursor, long pageId ) throws IOException
private void updateRoot()
{
rootId = cursor.getCurrentPageId();
rootGeneration = unstableGeneration;
treeLogic.initialize( cursor );
}

Expand Down Expand Up @@ -957,6 +960,34 @@ public void mustNotFindKeyRemovedInFrontOfSeeker() throws Exception
}
}

/* INCONSISTENCY */

@Test( timeout = 10_000L )
public void mustThrowIfStuckInInfiniteBeginFromRootLoop() throws IOException
{
// given
rootWithTwoLeaves();

// Find left child and corrupt it by overwriting type to make it look like freelist node instead of tree node.
goTo( utilCursor, rootId );
long leftChild = node.childAt( utilCursor, 0, stableGeneration, unstableGeneration );
goTo( utilCursor, leftChild );
utilCursor.putByte( TreeNode.BYTE_POS_NODE_TYPE, TreeNode.NODE_TYPE_FREE_LIST_NODE );

// when
try ( SeekCursor<KEY, VALUE> ignore = seekCursor( 0, 0, cursor, stableGeneration, unstableGeneration, realRootCatchup ) )
{
fail( "Expected to throw." );
}
catch ( TreeInconsistencyException e )
{
// then
assertThat( e.getMessage(), containsString(
"Index traversal aborted due to being stuck in infinite loop. This is most likely caused by an inconsistency in the index. " +
"Loop occurred when restarting search from root from page " + leftChild ) );
}
}

private long fullLeaf( List<Long> expectedSeeds )
{
return fullLeaf( 0, expectedSeeds );
Expand Down Expand Up @@ -2195,9 +2226,15 @@ private SeekCursor<KEY,VALUE> seekCursor( long fromInclusive, long toExclusive,

private SeekCursor<KEY,VALUE> seekCursor( long fromInclusive, long toExclusive,
PageCursor pageCursor, long stableGeneration, long unstableGeneration ) throws IOException
{
return seekCursor( fromInclusive, toExclusive, pageCursor, stableGeneration, unstableGeneration, failingRootCatchup );
}

private SeekCursor<KEY,VALUE> seekCursor( long fromInclusive, long toExclusive,
PageCursor pageCursor, long stableGeneration, long unstableGeneration, Supplier<Root> rootCatchup ) throws IOException
{
return new SeekCursor<>( pageCursor, node, key( fromInclusive ), key( toExclusive ), layout, stableGeneration, unstableGeneration,
generationSupplier, failingRootCatchup, unstableGeneration , exceptionDecorator, random.nextInt( 1, DEFAULT_MAX_READ_AHEAD ) );
generationSupplier, rootCatchup, unstableGeneration , exceptionDecorator, random.nextInt( 1, DEFAULT_MAX_READ_AHEAD ) );
}

/**
Expand Down

0 comments on commit 19b91f8

Please sign in to comment.