diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutUnique.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutUnique.java index 7e6ea3a02755a..69dfe100562a0 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutUnique.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutUnique.java @@ -29,8 +29,8 @@ public class SpatialLayoutUnique extends SpatialLayout { private static final String IDENTIFIER_NAME = "UPI"; - public static final int MAJOR_VERSION = 0; - public static final int MINOR_VERSION = 1; + private static final int MAJOR_VERSION = 0; + private static final int MINOR_VERSION = 1; public static long IDENTIFIER = Layout.namedIdentifier( IDENTIFIER_NAME, NativeSchemaValue.SIZE ); SpatialLayoutUnique( CoordinateReferenceSystem crs, SpaceFillingCurve curve ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/DummyIndexExtensionFactory.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/DummyIndexExtensionFactory.java index 33a4bb3d801e7..6b229381ec20a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/DummyIndexExtensionFactory.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/DummyIndexExtensionFactory.java @@ -28,7 +28,7 @@ public class DummyIndexExtensionFactory extends KernelExtensionFactory { public static final String IDENTIFIER = "test-dummy-neo-index"; - public static final String KEY_FAIL_ON_MUTATE = "fail_on_mutate"; + static final String KEY_FAIL_ON_MUTATE = "fail_on_mutate"; public DummyIndexExtensionFactory() { diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LayoutTestUtil.java index 2f18f879adbef..255e0e731abd7 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LayoutTestUtil.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LayoutTestUtil.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import org.apache.commons.lang3.ArrayUtils; - import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -37,8 +35,6 @@ import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.schema.index.IndexDescriptor; import org.neo4j.test.rule.RandomRule; -import org.neo4j.values.storable.CoordinateReferenceSystem; -import org.neo4j.values.storable.PointValue; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Values; @@ -126,12 +122,7 @@ Value[] extractValuesFromUpdates( IndexEntryUpdate[] updates ) abstract IndexEntryUpdate[] someUpdatesWithDuplicateValues(); - IndexEntryUpdate[] someSpatialUpdatesWithDuplicateValues() - { - return generateAddUpdatesFor( ArrayUtils.addAll( SOME_POINTS, SOME_POINTS ) ); - } - - protected IndexEntryUpdate[] generateAddUpdatesFor( Object[] values ) + IndexEntryUpdate[] generateAddUpdatesFor( Object[] values ) { @SuppressWarnings( "unchecked" ) IndexEntryUpdate[] indexEntryUpdates = new IndexEntryUpdate[values.length]; @@ -142,14 +133,6 @@ protected IndexEntryUpdate[] generateAddUpdatesFor( Object[] va return indexEntryUpdates; } - private static final PointValue[] SOME_POINTS = new PointValue[] - { - Values.pointValue( CoordinateReferenceSystem.WGS84, 12.5, 56.8 ), - Values.pointValue( CoordinateReferenceSystem.WGS84, -38.5, 36.8 ), - Values.pointValue( CoordinateReferenceSystem.WGS84, 30.0, -40.0 ), - Values.pointValue( CoordinateReferenceSystem.WGS84, -50, -25 ) - }; - protected IndexEntryUpdate add( long nodeId, Value value ) { return IndexEntryUpdate.add( nodeId, indexDescriptor, value ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexAccessorTest.java index c0156dab3507b..636ca1710f2df 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexAccessorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexAccessorTest.java @@ -24,6 +24,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; + import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -55,6 +56,7 @@ import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.storageengine.api.schema.IndexSampler; import org.neo4j.values.storable.Value; + import static java.lang.String.format; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -69,7 +71,6 @@ import static org.neo4j.kernel.api.index.IndexEntryUpdate.remove; import static org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE; import static org.neo4j.kernel.impl.index.schema.LayoutTestUtil.countUniqueValues; -import static org.neo4j.values.storable.Values.COMPARATOR; import static org.neo4j.values.storable.Values.of; /** @@ -713,7 +714,7 @@ private Value generateUniqueValue( IndexEntryUpdate[] updates ) private static Predicate> skipExisting( IndexEntryUpdate[] existing ) { Set> set = new HashSet<>( Arrays.asList( existing ) ); - return candidate -> set.add( candidate ); + return set::add; } private Object valueOf( IndexEntryUpdate update ) @@ -757,26 +758,6 @@ private PrimitiveLongIterator query( IndexReader reader, IndexQuery query ) thro return client; } - private static int compare( Value value, Value other ) - { - return COMPARATOR.compare( value, other ); - } - - private static Predicate lessThan( Value other ) - { - return t -> compare( t, other ) < 0; - } - - private static Predicate lessThanOrEqual( Value other ) - { - return t -> compare( t, other ) <= 0; - } - - private static Predicate greaterThan( Value other ) - { - return t -> compare( t, other ) > 0; - } - private void assertEntityIdHits( long[] expected, PrimitiveLongIterator result ) { long[] actual = PrimitiveLongCollections.asArray( result ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialKnownIndexTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialKnownIndexTest.java index 0ab89549055f5..bb72840288f7a 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialKnownIndexTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialKnownIndexTest.java @@ -56,7 +56,7 @@ public class SpatialKnownIndexTest { - final FileSystemRule fsRule = new EphemeralFileSystemRule(); + private final FileSystemRule fsRule = new EphemeralFileSystemRule(); private final TestDirectory directory = TestDirectory.testDirectory( getClass(), fsRule.get() ); private final PageCacheRule pageCacheRule = new PageCacheRule( config().withAccessChecks( true ) ); protected final RandomRule random = new RandomRule(); @@ -184,7 +184,7 @@ public void shouldGetUpdaterWhenOnline() throws IOException, IndexEntryConflictE } @Test - public void shouldGetUpdaterWhenPopuating() throws IOException, IndexEntryConflictException + public void shouldGetUpdaterWhenPopulating() throws IOException, IndexEntryConflictException { assertThat( fs.listFiles( storeDir ).length, equalTo( 0 ) ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java index a65d5ed898a14..bd4ec25da81cf 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexPopulatorTest.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Collections; import org.neo4j.internal.kernel.api.schema.LabelSchemaDescriptor; import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException; @@ -33,7 +34,6 @@ import org.neo4j.kernel.impl.index.schema.fusion.FusionSchemaIndexProvider.DropAction; import org.neo4j.values.storable.Value; -import static java.util.Arrays.asList; import static org.hamcrest.Matchers.sameInstance; import static org.hamcrest.core.AnyOf.anyOf; import static org.junit.Assert.assertThat; @@ -51,7 +51,7 @@ public class FusionIndexPopulatorTest { - private IndexPopulator nativePopulator; + private IndexPopulator numberPopulator; private IndexPopulator spatialPopulator; private IndexPopulator lucenePopulator; private IndexPopulator[] allPopulators; @@ -62,11 +62,11 @@ public class FusionIndexPopulatorTest @Before public void mockComponents() { - nativePopulator = mock( IndexPopulator.class ); + numberPopulator = mock( IndexPopulator.class ); spatialPopulator = mock( IndexPopulator.class ); lucenePopulator = mock( IndexPopulator.class ); - allPopulators = new IndexPopulator[]{nativePopulator, spatialPopulator, lucenePopulator}; - fusionIndexPopulator = new FusionIndexPopulator( nativePopulator, spatialPopulator, lucenePopulator, new NativeSelector(), indexId, dropAction ); + allPopulators = new IndexPopulator[]{numberPopulator, spatialPopulator, lucenePopulator}; + fusionIndexPopulator = new FusionIndexPopulator( numberPopulator, spatialPopulator, lucenePopulator, new NativeSelector(), indexId, dropAction ); } /* create */ @@ -78,7 +78,7 @@ public void createMustCreateBothNativeAndLucene() throws Exception fusionIndexPopulator.create(); // then - verify( nativePopulator, times( 1 ) ).create(); + verify( numberPopulator, times( 1 ) ).create(); verify( spatialPopulator, times( 1 ) ).create(); verify( lucenePopulator, times( 1 ) ).create(); } @@ -88,7 +88,7 @@ public void createMustThrowIfCreateNativeThrow() throws Exception { // given IOException failure = new IOException( "fail" ); - doThrow( failure ).when( nativePopulator ).create(); + doThrow( failure ).when( numberPopulator ).create(); verifyCallFail( failure, () -> { @@ -134,7 +134,7 @@ public void dropMustDropBothNativeAndLucene() throws Exception fusionIndexPopulator.drop(); // then - verify( nativePopulator, times( 1 ) ).drop(); + verify( numberPopulator, times( 1 ) ).drop(); verify( spatialPopulator, times( 1 ) ).drop(); verify( lucenePopulator, times( 1 ) ).drop(); verify( dropAction ).drop( indexId ); @@ -145,7 +145,7 @@ public void dropMustThrowIfDropNativeThrow() throws Exception { // given IOException failure = new IOException( "fail" ); - doThrow( failure ).when( nativePopulator ).drop(); + doThrow( failure ).when( numberPopulator ).drop(); verifyCallFail( failure, () -> { @@ -196,7 +196,7 @@ public void addMustSelectCorrectPopulator() throws Exception // Add with native for number values for ( Value numberValue : numberValues ) { - verifyAddWithCorrectPopulator( nativePopulator, numberValue ); + verifyAddWithCorrectPopulator( numberPopulator, numberValue ); } // Add with spatial for geometric values @@ -224,7 +224,7 @@ public void addMustSelectCorrectPopulator() throws Exception private void verifyAddWithCorrectPopulator( IndexPopulator correctPopulator, Value... numberValues ) throws IndexEntryConflictException, IOException { - Collection> update = asList( add( numberValues ) ); + Collection> update = Collections.singletonList( add( numberValues ) ); fusionIndexPopulator.add( update ); verify( correctPopulator, times( 1 ) ).add( update ); for ( IndexPopulator populator : allPopulators ) @@ -243,7 +243,7 @@ public void verifyDeferredConstraintsMustThrowIfNativeThrow() throws Exception { // given IndexEntryConflictException failure = mock( IndexEntryConflictException.class ); - doThrow( failure ).when( nativePopulator ).verifyDeferredConstraints( any() ); + doThrow( failure ).when( numberPopulator ).verifyDeferredConstraints( any() ); verifyCallFail( failure, () -> { @@ -301,7 +301,7 @@ private void closeAndVerifyPropagation( boolean populationCompletedSuccessfully fusionIndexPopulator.close( populationCompletedSuccessfully ); // then - verify( nativePopulator, times( 1 ) ).close( populationCompletedSuccessfully ); + verify( numberPopulator, times( 1 ) ).close( populationCompletedSuccessfully ); verify( spatialPopulator, times( 1 ) ).close( populationCompletedSuccessfully ); verify( lucenePopulator, times( 1 ) ).close( populationCompletedSuccessfully ); } @@ -311,7 +311,7 @@ public void closeMustThrowIfCloseNativeThrow() throws Exception { // given IOException failure = new IOException( "fail" ); - doThrow( failure ).when( nativePopulator ).close( anyBoolean() ); + doThrow( failure ).when( numberPopulator ).close( anyBoolean() ); verifyCallFail( failure, () -> { @@ -366,7 +366,7 @@ public void closeMustCloseOthersIfLuceneThrow() throws Exception } // then - verify( nativePopulator, times( 1 ) ).close( true ); + verify( numberPopulator, times( 1 ) ).close( true ); verify( spatialPopulator, times( 1 ) ).close( true ); } @@ -389,7 +389,7 @@ public void closeMustCloseOthersIfSpatialThrow() throws Exception // then verify( lucenePopulator, times( 1 ) ).close( true ); - verify( nativePopulator, times( 1 ) ).close( true ); + verify( numberPopulator, times( 1 ) ).close( true ); } @Test @@ -397,7 +397,7 @@ public void closeMustCloseOthersIfNativeThrow() throws Exception { // given IOException failure = new IOException( "fail" ); - doThrow( failure ).when( nativePopulator ).close( anyBoolean() ); + doThrow( failure ).when( numberPopulator ).close( anyBoolean() ); // when try @@ -421,7 +421,7 @@ public void closeMustThrowIfAllThrow() throws Exception IOException nativeFailure = new IOException( "native" ); IOException spatialFailure = new IOException( "spatial" ); IOException luceneFailure = new IOException( "lucene" ); - doThrow( nativeFailure ).when( nativePopulator ).close( anyBoolean() ); + doThrow( nativeFailure ).when( numberPopulator ).close( anyBoolean() ); doThrow( spatialFailure ).when( spatialPopulator ).close( anyBoolean() ); doThrow( luceneFailure ).when( lucenePopulator).close( anyBoolean() ); @@ -448,7 +448,7 @@ public void markAsFailedMustMarkAll() throws Exception fusionIndexPopulator.markAsFailed( failureMessage ); // then - verify( nativePopulator, times( 1 ) ).markAsFailed( failureMessage ); + verify( numberPopulator, times( 1 ) ).markAsFailed( failureMessage ); verify( spatialPopulator, times( 1 ) ).markAsFailed( failureMessage ); verify( lucenePopulator, times( 1 ) ).markAsFailed( failureMessage ); } @@ -458,7 +458,7 @@ public void markAsFailedMustThrowIfNativeThrow() throws Exception { // given IOException failure = new IOException( "fail" ); - doThrow( failure ).when( nativePopulator ).markAsFailed( anyString() ); + doThrow( failure ).when( numberPopulator ).markAsFailed( anyString() ); // then verifyCallFail( failure, () -> @@ -506,37 +506,22 @@ public void shouldIncludeSampleOnCorrectPopulator() Value[] spatialValues = FusionIndexTestHelp.valuesSupportedBySpatial(); Value[] otherValues = FusionIndexTestHelp.valuesNotSupportedByNativeOrSpatial(); - for ( Value value : numberValues ) - { - // when - IndexEntryUpdate update = add( value ); - fusionIndexPopulator.includeSample( update ); - - // then - verify( nativePopulator ).includeSample( update ); - reset( nativePopulator ); - } - - for ( Value value : spatialValues ) - { - // when - IndexEntryUpdate update = add( value ); - fusionIndexPopulator.includeSample( update ); - - // then - verify( spatialPopulator ).includeSample( update ); - reset( spatialPopulator ); - } + verifySampleToCorrectPopulator( numberValues, numberPopulator ); + verifySampleToCorrectPopulator( spatialValues, spatialPopulator ); + verifySampleToCorrectPopulator( otherValues, lucenePopulator ); + } - for ( Value value : otherValues ) + private void verifySampleToCorrectPopulator( Value[] values, IndexPopulator populator ) + { + for ( Value value : values ) { // when IndexEntryUpdate update = add( value ); fusionIndexPopulator.includeSample( update ); // then - verify( lucenePopulator ).includeSample( update ); - reset( lucenePopulator ); + verify( populator ).includeSample( update ); + reset( populator ); } } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexTestHelp.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexTestHelp.java index 0764a65349156..58fa364fe1a62 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexTestHelp.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexTestHelp.java @@ -32,7 +32,6 @@ import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.schema.SchemaDescriptorFactory; import org.neo4j.values.storable.CoordinateReferenceSystem; -import org.neo4j.values.storable.PointValue; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Values; @@ -92,16 +91,11 @@ static Value[] valuesSupportedBySpatial() return pointValues; } - static Value[] valuesNotSupportedByNative() + private static Value[] valuesNotSupportedByNative() { return ArrayUtils.addAll( pointValues, otherValues ); } - static Value[] valuesNotSupportedBySpatial() - { - return ArrayUtils.addAll( numberValues, otherValues ); - } - static Value[] valuesNotSupportedByNativeOrSpatial() { return otherValues; diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/SpatialFusionIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/SpatialFusionIndexPopulatorTest.java index ff4a8291a7067..1f89467bae069 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/SpatialFusionIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/fusion/SpatialFusionIndexPopulatorTest.java @@ -42,9 +42,7 @@ import static org.hamcrest.core.AnyOf.anyOf; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset;