Skip to content

Commit

Permalink
Fix MergingBlockEntryReaderTest
Browse files Browse the repository at this point in the history
Use unique keys so that order of value is always deterministic.
  • Loading branch information
burqen committed Feb 18, 2019
1 parent 74b4420 commit fe3858e
Showing 1 changed file with 14 additions and 6 deletions.
Expand Up @@ -26,7 +26,9 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.neo4j.index.internal.gbptree.SimpleLongLayout;
import org.neo4j.test.extension.Inject;
Expand All @@ -53,7 +55,7 @@ void shouldMergeSingleReader() throws IOException
{
// given
MergingBlockEntryReader<MutableLong,MutableLong> merger = new MergingBlockEntryReader<>( layout );
List<BlockEntry<MutableLong,MutableLong>> data = someBlockEntries();
List<BlockEntry<MutableLong,MutableLong>> data = someBlockEntries( new HashSet<>() );

// when
merger.addSource( newReader( data ) );
Expand Down Expand Up @@ -83,11 +85,12 @@ void shouldMergeMultipleReaders() throws IOException
// given
MergingBlockEntryReader<MutableLong,MutableLong> merger = new MergingBlockEntryReader<>( layout );
List<List<BlockEntry<MutableLong,MutableLong>>> datas = new ArrayList<>();
Set<MutableLong> uniqueKeys = new HashSet<>();
int nbrOfReaders = rnd.nextInt( 10 ) + 1;
for ( int i = 0; i < nbrOfReaders; i++ )
{
// when
List<BlockEntry<MutableLong,MutableLong>> data = someBlockEntries();
List<BlockEntry<MutableLong,MutableLong>> data = someBlockEntries( uniqueKeys );
datas.add( data );
merger.addSource( newReader( data ) );
}
Expand All @@ -103,7 +106,7 @@ void shouldCloseAllReaderEvenEmpty() throws IOException
// given
MergingBlockEntryReader<MutableLong,MutableLong> merger = new MergingBlockEntryReader<>( layout );
CloseTrackingBlockEntryCursor empty = newReader( emptyList() );
CloseTrackingBlockEntryCursor nonEmpty = newReader( someBlockEntries() );
CloseTrackingBlockEntryCursor nonEmpty = newReader( someBlockEntries( new HashSet<>() ) );
merger.addSource( empty );
merger.addSource( nonEmpty );

Expand All @@ -121,7 +124,7 @@ void shouldCloseAllReaderEvenEmptyAndExhausted() throws IOException
// given
MergingBlockEntryReader<MutableLong,MutableLong> merger = new MergingBlockEntryReader<>( layout );
CloseTrackingBlockEntryCursor empty = newReader( emptyList() );
CloseTrackingBlockEntryCursor nonEmpty = newReader( someBlockEntries() );
CloseTrackingBlockEntryCursor nonEmpty = newReader( someBlockEntries( new HashSet<>() ) );
merger.addSource( empty );
merger.addSource( nonEmpty );

Expand Down Expand Up @@ -164,12 +167,17 @@ private static CloseTrackingBlockEntryCursor newReader( List<BlockEntry<MutableL
return new CloseTrackingBlockEntryCursor( expected );
}

private List<BlockEntry<MutableLong,MutableLong>> someBlockEntries()
private List<BlockEntry<MutableLong,MutableLong>> someBlockEntries( Set<MutableLong> uniqueKeys )
{
List<BlockEntry<MutableLong,MutableLong>> entries = new ArrayList<>();
for ( int i = 0; i < rnd.nextInt( 10 ); i++ )
{
MutableLong key = layout.key( rnd.nextLong( 10_000 ) );
MutableLong key;
do
{
key = layout.key( rnd.nextLong( 10_000 ) );
}
while ( !uniqueKeys.add( key ) );
MutableLong value = layout.value( rnd.nextLong( 10_000 ) );
entries.add( new BlockEntry<>( key, value ) );
}
Expand Down

0 comments on commit fe3858e

Please sign in to comment.