Skip to content

Commit

Permalink
Use RandomValues in NumberFullScanNonUniqueIndexSamplerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Oct 3, 2018
1 parent 48c62fd commit 29c4335
Showing 1 changed file with 15 additions and 14 deletions.
Expand Up @@ -26,23 +26,23 @@
import org.neo4j.index.internal.gbptree.GBPTree;
import org.neo4j.index.internal.gbptree.Writer;
import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.storageengine.api.schema.IndexDescriptor;
import org.neo4j.storageengine.api.schema.IndexSample;
import org.neo4j.values.storable.Values;
import org.neo4j.values.storable.NumberValue;
import org.neo4j.values.storable.RandomValues;
import org.neo4j.values.storable.Value;
import org.neo4j.values.storable.ValueGroup;

import static org.junit.Assert.assertEquals;
import static org.neo4j.kernel.impl.index.schema.LayoutTestUtil.countUniqueValues;
import static org.neo4j.kernel.impl.index.schema.NativeIndexKey.Inclusion.NEUTRAL;
import static org.neo4j.values.storable.Values.values;

public class NumberFullScanNonUniqueIndexSamplerTest extends NativeIndexTestUtil<NumberIndexKey,NativeIndexValue>
{
@Test
public void shouldIncludeAllValuesInTree() throws Exception
{
// GIVEN
Number[] values = generateNumberValues();
Value[] values = generateNumberValues();
buildTree( values );

// WHEN
Expand All @@ -60,18 +60,19 @@ public void shouldIncludeAllValuesInTree() throws Exception
assertEquals( values.length, sample.indexSize() );
}

private Number[] generateNumberValues()
private Value[] generateNumberValues()
{
IndexEntryUpdate<IndexDescriptor>[] updates = layoutUtil.someUpdates();
Number[] result = new Number[updates.length];
for ( int i = 0; i < updates.length; i++ )
RandomValues.Type[] numberTypes = RandomValues.including( t -> t.valueGroup == ValueGroup.NUMBER );
int size = 20;
Value[] result = new NumberValue[size];
for ( int i = 0; i < size; i++ )
{
result[i] = (Number) updates[i].values()[0].asObject();
result[i] = randomValues.nextValueOfTypes( numberTypes );
}
return result;
}

private void buildTree( Number[] values ) throws IOException
private void buildTree( Value[] values ) throws IOException
{
try ( GBPTree<NumberIndexKey,NativeIndexValue> gbpTree = getTree() )
{
Expand All @@ -80,11 +81,11 @@ private void buildTree( Number[] values ) throws IOException
NumberIndexKey key = layout.newKey();
NativeIndexValue value = layout.newValue();
long nodeId = 0;
for ( Number number : values )
for ( Value number : values )
{
key.initialize( nodeId );
key.initFromValue( 0, Values.of( number ), NEUTRAL );
value.from( values( number ) );
key.initFromValue( 0, number, NEUTRAL );
value.from( number );
writer.put( key, value );
nodeId++;
}
Expand Down

0 comments on commit 29c4335

Please sign in to comment.