diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java index ff77dda94d5ff..4a4ad0d51a84e 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/CompositeIndexAccessorCompatibility.java @@ -1121,7 +1121,8 @@ private void shouldSeekInOrderExactWithRange( IndexOrder order, Object o0, Objec SimpleNodeValueClient client = new SimpleNodeValueClient(); try ( AutoCloseable ignored = query( client, order, exact, range ) ) { - assertOrder( client, order, 6 ); + List seenIds = assertOrder( client, order ); + assertThat( seenIds.size(), equalTo( 6 ) ); } } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/IndexAccessorCompatibility.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/IndexAccessorCompatibility.java index d68d2c767a0c8..8111032b77c85 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/IndexAccessorCompatibility.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/IndexAccessorCompatibility.java @@ -23,6 +23,7 @@ import org.junit.Assert; import org.junit.Before; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -46,7 +47,6 @@ import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.Values; -import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.junit.Assert.assertThat; @@ -133,14 +133,16 @@ protected AutoCloseable query( SimpleNodeValueClient client, IndexOrder order, I return reader; } - void assertOrder( SimpleNodeValueClient client, IndexOrder order, int expectedCount ) + List assertOrder( SimpleNodeValueClient client, IndexOrder order ) { + List seenIds = new ArrayList<>(); Value[] prevValues = null; Value[] values; int count = 0; while ( client.next() ) { count++; + seenIds.add( client.reference ); values = client.values; if ( order == IndexOrder.ASCENDING ) { @@ -156,7 +158,7 @@ else if ( order == IndexOrder.DESCENDING ) } prevValues = values; } - assertThat( "correct number of hits", count, equalTo( expectedCount ) ); + return seenIds; } IndexOrder[] orderCapability( IndexQuery... predicates ) diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java index 5501267113544..19c78b05154d4 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleIndexAccessorCompatibility.java @@ -815,7 +815,8 @@ private void shouldRangeSeekInOrder( IndexOrder order, Object o0, Object o1, Obj SimpleNodeValueClient client = new SimpleNodeValueClient(); try ( AutoCloseable ignored = query( client, order, range ) ) { - assertOrder( client, order, 6 ); + List seenIds = assertOrder( client, order ); + assertThat( seenIds.size(), equalTo( 6 ) ); } } diff --git a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleRandomizedIndexAccessorCompatibility.java b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleRandomizedIndexAccessorCompatibility.java index 68fe38fd962ce..2b0befb22e505 100644 --- a/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleRandomizedIndexAccessorCompatibility.java +++ b/community/community-it/kernel-it/src/test/java/org/neo4j/kernel/api/index/SimpleRandomizedIndexAccessorCompatibility.java @@ -30,8 +30,10 @@ import java.util.TreeSet; import java.util.stream.Collectors; +import org.neo4j.internal.kernel.api.IndexOrder; import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; +import org.neo4j.storageengine.api.schema.SimpleNodeValueClient; import org.neo4j.values.storable.RandomValues; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Values; @@ -74,7 +76,7 @@ public void testExactMatchOnRandomValues() throws Exception } @Test - public void testRangeMatchOnRandomValues() throws Exception + public void testRangeMatchInOrderOnRandomValues() throws Exception { Assume.assumeTrue( "Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries() ); // given @@ -87,6 +89,7 @@ public void testRangeMatchOnRandomValues() throws Exception for ( int i = 0; i < 100; i++ ) { + // Construct a random range query of random value type RandomValues.Type type = random.among( types ); Value from = random.randomValues().nextValueOfType( type ); Value to = random.randomValues().nextValueOfType( type ); @@ -99,20 +102,43 @@ public void testRangeMatchOnRandomValues() throws Exception boolean fromInclusive = random.nextBoolean(); boolean toInclusive = random.nextBoolean(); - // when - List expectedIds = sortedValues.subSet( add( 0, descriptor.schema(), from ), fromInclusive, add( 0, descriptor.schema(), to ), toInclusive ) - .stream() - .map( IndexEntryUpdate::getEntityId ) - .collect( Collectors.toList() ); - List actualIds = query( IndexQuery.range( 0, from, fromInclusive, to, toInclusive ) ); - expectedIds.sort( Long::compare ); - actualIds.sort( Long::compare ); + // Expected result based on query + IndexQuery.RangePredicate predicate = IndexQuery.range( 0, from, fromInclusive, to, toInclusive ); + List expectedIds = expectedIds( sortedValues, from, to, fromInclusive, toInclusive ); - // then - assertThat( actualIds, equalTo( expectedIds ) ); + // Depending on order capabilities we verify ids or order and ids. + IndexOrder[] indexOrders = indexProvider.getCapability().orderCapability( predicate.valueGroup().category() ); + for ( IndexOrder order : indexOrders ) + { + List actualIds; + if ( order == IndexOrder.NONE ) + { + actualIds = query( predicate ); + } + else + { + SimpleNodeValueClient client = new SimpleNodeValueClient(); + try ( AutoCloseable ignore = query( client, order, predicate ) ) + { + actualIds = assertOrder( client, order ); + } + } + actualIds.sort( Long::compare ); + // then + assertThat( actualIds, equalTo( expectedIds ) ); + } } } + private List expectedIds( TreeSet sortedValues, Value from, Value to, boolean fromInclusive, boolean toInclusive ) + { + return sortedValues.subSet( add( 0, descriptor.schema(), from ), fromInclusive, add( 0, descriptor.schema(), to ), toInclusive ) + .stream() + .map( IndexEntryUpdate::getEntityId ) + .sorted( Long::compare ) + .collect( Collectors.toList() ); + } + private List generateValuesFromType( RandomValues.Type[] types ) { List values = new ArrayList<>();