Skip to content

Commit

Permalink
SeekCursorTest cleanup don't rely on long values
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Jan 16, 2018
1 parent 94a1503 commit 86609db
Showing 1 changed file with 34 additions and 23 deletions.
Expand Up @@ -341,16 +341,16 @@ public void mustFindKeysWhenGivenRangeStartingOutsideStartOfDataBackwards() thro
// [ 0 1... maxKeyCount-1]
long maxKeyCount = fullLeaf();

long expectedkey = maxKeyCount - 1;
long expectedKey = maxKeyCount - 1;
try ( SeekCursor<MutableLong,MutableLong> seekCursor = seekCursor( maxKeyCount, 0 ) )
{
while ( seekCursor.next() )
{
assertKeyAndValue( seekCursor, expectedkey );
expectedkey--;
assertKeyAndValue( seekCursor, expectedKey );
expectedKey--;
}
}
assertEquals( expectedkey, 0 );
assertEquals( expectedKey, 0 );
}

@Test
Expand All @@ -360,16 +360,16 @@ public void mustFindKeysWhenGivenRangeEndingOutsideEndOfData() throws Exception
// [ 0 1... maxKeyCount-1]
long maxKeyCount = fullLeaf();

long expectedkey = 0;
long expectedKey = 0;
try ( SeekCursor<MutableLong,MutableLong> seekCursor = seekCursor( 0, maxKeyCount + 1 ) )
{
while ( seekCursor.next() )
{
assertKeyAndValue( seekCursor, expectedkey );
expectedkey++;
assertKeyAndValue( seekCursor, expectedKey );
expectedKey++;
}
}
assertEquals( expectedkey, maxKeyCount );
assertEquals( expectedKey, maxKeyCount );
}

@Test
Expand All @@ -379,16 +379,16 @@ public void mustFindKeysWhenGivenRangeEndingOutsideEndOfDataBackwards() throws E
// [ 0 1... maxKeyCount-1]
long maxKeyCount = fullLeaf();

long expectedkey = maxKeyCount - 1;
long expectedKey = maxKeyCount - 1;
try ( SeekCursor<MutableLong,MutableLong> seekCursor = seekCursor( maxKeyCount - 1, -2 ) )
{
while ( seekCursor.next() )
{
assertKeyAndValue( seekCursor, expectedkey );
expectedkey--;
assertKeyAndValue( seekCursor, expectedKey );
expectedKey--;
}
}
assertEquals( expectedkey, -1 );
assertEquals( expectedKey, -1 );
}

@Test
Expand Down Expand Up @@ -485,8 +485,8 @@ private void assertExactMatch( long i ) throws IOException
{
// then
assertTrue( seeker.next() );
assertEquals( i, seeker.get().key().longValue() );
assertEquals( value( i ), seeker.get().value() );
assertEqualsKey( key( i ), seeker.get().key() );
assertEqualsValue( value( i ), seeker.get().value() );
assertFalse( seeker.next() );
}
}
Expand Down Expand Up @@ -1185,7 +1185,7 @@ public void mustRereadHeadersOnRetry() throws Exception
{
// reading a couple of keys
assertTrue( cursor.next() );
assertEquals( 0, cursor.get().key().longValue() );
assertEquals( key( 0 ), cursor.get().key() );

// and WHEN a change happens
append( keyCount );
Expand All @@ -1195,11 +1195,11 @@ public void mustRereadHeadersOnRetry() throws Exception
assertTrue( cursor.next() );

// and the new key should be found in the end as well
assertEquals( 1, cursor.get().key().longValue() );
assertEquals( key( 1 ), cursor.get().key() );
long lastFoundKey = 1;
while ( cursor.next() )
{
assertEquals( lastFoundKey + 1, cursor.get().key().longValue() );
assertEquals( key( lastFoundKey + 1 ), cursor.get().key() );
lastFoundKey = cursor.get().key().longValue();
}
assertEquals( keyCount, lastFoundKey );
Expand Down Expand Up @@ -1594,13 +1594,13 @@ public void shouldRereadSuccessorIfReadFailureCausedByCheckpointInLeaf() throws
checkpoint();
PageAwareByteArrayCursor duplicate = cursor.duplicate( currentNode );
duplicate.next();
insert( 2, 2, duplicate ); // Create successor of leaf
insert( i, i, duplicate ); // Create successor of leaf
expected.add( i );

while ( seek.next() )
{
Hit<MutableLong,MutableLong> hit = seek.get();
actual.add( hit.key().getValue() );
actual.add( layout.getSeed( hit.key() ) );
}
}

Expand Down Expand Up @@ -2207,13 +2207,24 @@ private void assertKeyAndValue( SeekCursor<MutableLong,MutableLong> cursor, long
assertKeyAndValue( cursor, key, value );
}

private static void assertKeyAndValue( SeekCursor<MutableLong,MutableLong> cursor,
MutableLong expectedKey, MutableLong expectedValue )
private void assertKeyAndValue( SeekCursor<MutableLong,MutableLong> cursor, MutableLong expectedKey, MutableLong expectedValue )
{
MutableLong foundKey = cursor.get().key();
MutableLong foundValue = cursor.get().value();
assertEquals( expectedKey, foundKey );
assertEquals( expectedValue, foundValue );
assertEqualsKey( expectedKey, foundKey );
assertEqualsValue( expectedValue, foundValue );
}

private void assertEqualsKey( MutableLong expected, MutableLong actual )
{
assertTrue( String.format( "expected equal, expected=%s, actual=%s", expected.toString(), actual.toString() ),
layout.compare( expected, actual ) == 0 );
}

private void assertEqualsValue( MutableLong expected, MutableLong actual )
{
assertTrue( String.format( "expected equal, expected=%s, actual=%s", expected.toString(), actual.toString() ),
layout.compareValue( expected, actual ) == 0 );
}

private void insertKeysAndValues( int keyCount )
Expand Down

0 comments on commit 86609db

Please sign in to comment.