Skip to content

Commit

Permalink
Move native index reader test to new query api
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Nov 16, 2017
1 parent 570e29b commit 3f13eb0
Showing 1 changed file with 29 additions and 20 deletions.
Expand Up @@ -45,6 +45,7 @@
import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.schema.index.IndexDescriptor;
Expand Down Expand Up @@ -314,7 +315,7 @@ public void shouldReturnAllEntriesForExistsPredicate() throws Exception

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query( IndexQuery.exists( 0 ) );
PrimitiveLongIterator result = query( reader, IndexQuery.exists( 0 ) );

// then
assertEntityIdHits( extractEntityIds( updates, alwaysTrue() ), result );
Expand All @@ -325,7 +326,7 @@ public void shouldReturnNoEntriesForExistsPredicateForEmptyIndex() throws Except
{
// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query( IndexQuery.exists( 0 ) );
PrimitiveLongIterator result = query( reader, IndexQuery.exists( 0 ) );

// then
long[] actual = PrimitiveLongCollections.asArray( result );
Expand All @@ -344,7 +345,7 @@ public void shouldReturnMatchingEntriesForExactPredicate() throws Exception
for ( IndexEntryUpdate<IndexDescriptor> update : updates )
{
Value value = update.values()[0];
PrimitiveLongIterator result = reader.query( IndexQuery.exact( 0, value ) );
PrimitiveLongIterator result = query( reader, IndexQuery.exact( 0, value ) );
assertEntityIdHits( extractEntityIds( updates, in( value ) ), result );
}
}
Expand All @@ -359,7 +360,7 @@ public void shouldReturnNoEntriesForMismatchingExactPredicate() throws Exception
// when
IndexReader reader = accessor.newReader();
Object value = NON_EXISTENT_VALUE;
PrimitiveLongIterator result = reader.query( IndexQuery.exact( 0, value ) );
PrimitiveLongIterator result = query( reader, IndexQuery.exact( 0, value ) );
assertEntityIdHits( EMPTY_LONG_ARRAY, result );
}

Expand All @@ -372,7 +373,7 @@ public void shouldReturnMatchingEntriesForRangePredicateWithInclusiveStartAndExc

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query(
PrimitiveLongIterator result = query( reader,
IndexQuery.range( 0, Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, false ) );
assertEntityIdHits( extractEntityIds( updates, lessThan( Double.POSITIVE_INFINITY ) ), result );
}
Expand All @@ -386,7 +387,7 @@ public void shouldReturnMatchingEntriesForRangePredicateWithInclusiveStartAndInc

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query(
PrimitiveLongIterator result = query( reader,
IndexQuery.range( 0, Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true ) );
assertEntityIdHits( extractEntityIds( updates, alwaysTrue() ), result );
}
Expand All @@ -400,7 +401,7 @@ public void shouldReturnMatchingEntriesForRangePredicateWithExclusiveStartAndExc

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query(
PrimitiveLongIterator result = query( reader,
IndexQuery.range( 0, Double.NEGATIVE_INFINITY, false, Double.POSITIVE_INFINITY, false ) );
assertEntityIdHits( extractEntityIds( updates,
all( greaterThan( Double.NEGATIVE_INFINITY ), lessThan( Double.POSITIVE_INFINITY ) ) ), result );
Expand All @@ -415,19 +416,20 @@ public void shouldReturnMatchingEntriesForRangePredicateWithExclusiveStartAndInc

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query(
PrimitiveLongIterator result = query( reader,
IndexQuery.range( 0, Double.NEGATIVE_INFINITY, false, Double.POSITIVE_INFINITY, true ) );
assertEntityIdHits( extractEntityIds( updates,
all( greaterThan( Double.NEGATIVE_INFINITY ), greaterThan( Double.NEGATIVE_INFINITY ) ) ), result );
}

// <READER ordering>

@Test
public void throwForUnsupportedIndexOrder() throws Exception
{
// given
// Unsupported index order for query
IndexReader indexReader = accessor.newReader();
IndexReader reader = accessor.newReader();
IndexOrder unsupportedOrder = IndexOrder.DESCENDING;
IndexQuery.ExactPredicate unsupportedQuery = IndexQuery.exact( 0, "Legolas" );

Expand All @@ -439,7 +441,7 @@ public void throwForUnsupportedIndexOrder() throws Exception
CoreMatchers.containsString( unsupportedQuery.toString() ) ) );

// when
indexReader.query( new SimpleNodeValueClient(), unsupportedOrder, unsupportedQuery );
reader.query( new SimpleNodeValueClient(), unsupportedOrder, unsupportedQuery );
}

@Test
Expand All @@ -451,23 +453,23 @@ public void respectIndexOrder() throws Exception
Value[] expectedValues = layoutUtil.extractValuesFromUpdates( someUpdates );

// when
IndexReader indexReader = accessor.newReader();
IndexReader reader = accessor.newReader();
IndexQuery.NumberRangePredicate supportedQuery =
IndexQuery.range( 0, Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true );

for ( IndexOrder supportedOrder : NativeSchemaNumberIndexProvider.CAPABILITY.orderCapability( ValueGroup.NUMBER ) )
{
if ( IndexOrder.ASCENDING.equals( supportedOrder ) )
if ( supportedOrder == IndexOrder.ASCENDING )
{
Arrays.sort( expectedValues, Values.COMPARATOR );
}
if ( IndexOrder.DESCENDING.equals( supportedOrder ) )
if ( supportedOrder == IndexOrder.DESCENDING )
{
Arrays.sort( expectedValues, Values.COMPARATOR.reversed() );
}

SimpleNodeValueClient client = new SimpleNodeValueClient();
indexReader.query( client, supportedOrder, supportedQuery );
reader.query( client, supportedOrder, supportedQuery );
int i = 0;
while ( client.next() )
{
Expand All @@ -488,7 +490,7 @@ public void shouldReturnNoEntriesForRangePredicateOutsideAnyMatch() throws Excep

// when
IndexReader reader = accessor.newReader();
PrimitiveLongIterator result = reader.query(
PrimitiveLongIterator result = query( reader,
IndexQuery.range( 0, NON_EXISTENT_VALUE, true, NON_EXISTENT_VALUE + 10, true ) );
assertEntityIdHits( EMPTY_LONG_ARRAY, result );
}
Expand Down Expand Up @@ -516,12 +518,12 @@ public void mustHandleNestedQueries() throws Exception
long[] expectedOuter = new long[]{2, 3};
long[] expectedInner = new long[]{0, 1};

PrimitiveLongIterator outerIter = reader.query( outerQuery );
PrimitiveLongIterator outerIter = query( reader, outerQuery );
Collection<Long> outerResult = new ArrayList<>();
while ( outerIter.hasNext() )
{
outerResult.add( outerIter.next() );
PrimitiveLongIterator innerIter = reader.query( innerQuery );
PrimitiveLongIterator innerIter = query( reader, innerQuery );
assertEntityIdHits( expectedInner, innerIter );
}
assertEntityIdHits( expectedOuter, outerResult );
Expand Down Expand Up @@ -555,19 +557,19 @@ public void mustHandleMultipleNestedQueries() throws Exception
long[] expected3 = new long[]{0, 1};

Collection<Long> result1 = new ArrayList<>();
PrimitiveLongIterator iter1 = reader.query( query1 );
PrimitiveLongIterator iter1 = query( reader, query1 );
while ( iter1.hasNext() )
{
result1.add( iter1.next() );

Collection<Long> result2 = new ArrayList<>();
PrimitiveLongIterator iter2 = reader.query( query2 );
PrimitiveLongIterator iter2 = query( reader, query2 );
while ( iter2.hasNext() )
{
result2.add( iter2.next() );

Collection<Long> result3 = new ArrayList<>();
PrimitiveLongIterator iter3 = reader.query( query3 );
PrimitiveLongIterator iter3 = query( reader, query3 );
while ( iter3.hasNext() )
{
result3.add( iter3.next() );
Expand Down Expand Up @@ -768,6 +770,13 @@ public void shouldSeeNoEntriesInAllEntriesReaderOnEmptyIndex() throws Exception
assertEquals( expectedIds, ids );
}

private PrimitiveLongIterator query( IndexReader reader, IndexQuery query ) throws IndexNotApplicableKernelException
{
NodeValueIterator client = new NodeValueIterator();
reader.query( client, IndexOrder.NONE, query );
return client;
}

private static int compare( Value value, Number other )
{
return COMPARATOR.compare( value, Values.of( other ) );
Expand Down

0 comments on commit 3f13eb0

Please sign in to comment.