From a854a21c6467ee319c20243c1aa9e28d14e052f2 Mon Sep 17 00:00:00 2001 From: Anton Persson Date: Wed, 18 Oct 2017 10:53:47 +0200 Subject: [PATCH] Cleanup --- ...erationsFacadeSchemaIndexIteratorTest.java | 104 +++++------------- 1 file changed, 29 insertions(+), 75 deletions(-) diff --git a/community/lucene-index/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeSchemaIndexIteratorTest.java b/community/lucene-index/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeSchemaIndexIteratorTest.java index 837169a95d2ca..76efb6b3bf4d3 100644 --- a/community/lucene-index/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeSchemaIndexIteratorTest.java +++ b/community/lucene-index/src/test/java/org/neo4j/kernel/impl/api/OperationsFacadeSchemaIndexIteratorTest.java @@ -54,6 +54,7 @@ import org.neo4j.test.rule.RandomRule; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; import static org.junit.Assert.assertThat; /** @@ -295,27 +296,7 @@ public void multipleIteratorsNestedInterleavedExists() throws Exception List actual2 = new ArrayList<>(); // Interleave - while ( iter1.hasNext() && iter2.hasNext() ) - { - if ( rnd.nextBoolean() ) - { - actual1.add( iter1.next() ); - } - else - { - actual2.add( iter2.next() ); - } - } - - // Empty the rest - while ( iter1.hasNext() ) - { - actual1.add( iter1.next() ); - } - while ( iter2.hasNext() ) - { - actual2.add( iter2.next() ); - } + exhaustInterleaved( iter1, actual1, iter2, actual2 ); // then indexCoordinator.assertExistsResult( actual1 ); @@ -338,27 +319,7 @@ public void multipleIteratorsNestedInterleavedExact() throws Exception List actual2 = new ArrayList<>(); // Interleave - while ( iter1.hasNext() && iter2.hasNext() ) - { - if ( rnd.nextBoolean() ) - { - actual1.add( iter1.next() ); - } - else - { - actual2.add( iter2.next() ); - } - } - - // Empty the rest - while ( iter1.hasNext() ) - { - actual1.add( iter1.next() ); - } - while ( iter2.hasNext() ) - { - actual2.add( iter2.next() ); - } + exhaustInterleaved( iter1, actual1, iter2, actual2 ); // then indexCoordinator.assertExactResult( actual1 ); @@ -382,27 +343,7 @@ public void multipleIteratorsNestedInterleavedRange() throws Exception List actual2 = new ArrayList<>(); // Interleave - while ( iter1.hasNext() && iter2.hasNext() ) - { - if ( rnd.nextBoolean() ) - { - actual1.add( iter1.next() ); - } - else - { - actual2.add( iter2.next() ); - } - } - - // Empty the rest - while ( iter1.hasNext() ) - { - actual1.add( iter1.next() ); - } - while ( iter2.hasNext() ) - { - actual2.add( iter2.next() ); - } + exhaustInterleaved( iter1, actual1, iter2, actual2 ); // then indexCoordinator.assertRangeResult( actual1 ); @@ -411,15 +352,30 @@ public void multipleIteratorsNestedInterleavedRange() throws Exception } } - // multipleIteratorsNotNestedExists - // multipleIteratorsNotNestedExact - // multipleIteratorsNotNestedRange - // multipleIteratorsNestedInnerNewExists - // multipleIteratorsNestedInnerNewExact - // multipleIteratorsNestedInnerNewRange - // multipleIteratorsNestedInterleavedExists - // multipleIteratorsNestedInterleavedExact - // multipleIteratorsNestedInterleavedRange + private void exhaustInterleaved( PrimitiveLongIterator source1, List target1, PrimitiveLongIterator source2, List target2 ) + { + while ( source1.hasNext() && source2.hasNext() ) + { + if ( rnd.nextBoolean() ) + { + target1.add( source1.next() ); + } + else + { + target2.add( source2.next() ); + } + } + + // Empty the rest + while ( source1.hasNext() ) + { + target1.add( source1.next() ); + } + while ( source2.hasNext() ) + { + target2.add( source2.next() ); + } + } private static class StringCompositeIndexCoordinator extends IndexCoordinator { @@ -807,9 +763,7 @@ void assertExistsResult( List actual ) void assertSameContent( List actual, List expected ) { - actual.sort( Long::compareTo ); - expected.sort( Long::compareTo ); - assertThat( actual, is( expected ) ); + assertThat( actual, is( containsInAnyOrder( expected.toArray() ) ) ); } abstract void assertExactResult( List result );