Skip to content

Commit

Permalink
Code cleanup around schema
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Feb 15, 2018
1 parent 98c3635 commit a08a84c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 98 deletions.
Expand Up @@ -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 )
Expand Down
Expand Up @@ -28,7 +28,7 @@
public class DummyIndexExtensionFactory extends KernelExtensionFactory<DummyIndexExtensionFactory.Dependencies>
{
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()
{
Expand Down
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -126,12 +122,7 @@ Value[] extractValuesFromUpdates( IndexEntryUpdate<IndexDescriptor>[] updates )

abstract IndexEntryUpdate<IndexDescriptor>[] someUpdatesWithDuplicateValues();

IndexEntryUpdate<IndexDescriptor>[] someSpatialUpdatesWithDuplicateValues()
{
return generateAddUpdatesFor( ArrayUtils.addAll( SOME_POINTS, SOME_POINTS ) );
}

protected IndexEntryUpdate<IndexDescriptor>[] generateAddUpdatesFor( Object[] values )
IndexEntryUpdate<IndexDescriptor>[] generateAddUpdatesFor( Object[] values )
{
@SuppressWarnings( "unchecked" )
IndexEntryUpdate<IndexDescriptor>[] indexEntryUpdates = new IndexEntryUpdate[values.length];
Expand All @@ -142,14 +133,6 @@ protected IndexEntryUpdate<IndexDescriptor>[] 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<IndexDescriptor> add( long nodeId, Value value )
{
return IndexEntryUpdate.add( nodeId, indexDescriptor, value );
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -713,7 +714,7 @@ private Value generateUniqueValue( IndexEntryUpdate<IndexDescriptor>[] updates )
private static Predicate<IndexEntryUpdate<IndexDescriptor>> skipExisting( IndexEntryUpdate<IndexDescriptor>[] existing )
{
Set<IndexEntryUpdate<IndexDescriptor>> set = new HashSet<>( Arrays.asList( existing ) );
return candidate -> set.add( candidate );
return set::add;
}

private Object valueOf( IndexEntryUpdate<IndexDescriptor> update )
Expand Down Expand Up @@ -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<Value> lessThan( Value other )
{
return t -> compare( t, other ) < 0;
}

private static Predicate<Value> lessThanOrEqual( Value other )
{
return t -> compare( t, other ) <= 0;
}

private static Predicate<Value> greaterThan( Value other )
{
return t -> compare( t, other ) > 0;
}

private void assertEntityIdHits( long[] expected, PrimitiveLongIterator result )
{
long[] actual = PrimitiveLongCollections.asArray( result );
Expand Down
Expand Up @@ -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();
Expand Down Expand Up @@ -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 ) );

Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -51,7 +51,7 @@

public class FusionIndexPopulatorTest
{
private IndexPopulator nativePopulator;
private IndexPopulator numberPopulator;
private IndexPopulator spatialPopulator;
private IndexPopulator lucenePopulator;
private IndexPopulator[] allPopulators;
Expand All @@ -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 */
Expand All @@ -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();
}
Expand All @@ -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, () ->
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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, () ->
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -224,7 +224,7 @@ public void addMustSelectCorrectPopulator() throws Exception
private void verifyAddWithCorrectPopulator( IndexPopulator correctPopulator, Value... numberValues )
throws IndexEntryConflictException, IOException
{
Collection<IndexEntryUpdate<LabelSchemaDescriptor>> update = asList( add( numberValues ) );
Collection<IndexEntryUpdate<LabelSchemaDescriptor>> update = Collections.singletonList( add( numberValues ) );
fusionIndexPopulator.add( update );
verify( correctPopulator, times( 1 ) ).add( update );
for ( IndexPopulator populator : allPopulators )
Expand All @@ -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, () ->
{
Expand Down Expand Up @@ -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 );
}
Expand All @@ -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, () ->
{
Expand Down Expand Up @@ -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 );
}

Expand All @@ -389,15 +389,15 @@ 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
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
Expand All @@ -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() );

Expand All @@ -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 );
}
Expand All @@ -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, () ->
Expand Down Expand Up @@ -506,37 +506,22 @@ public void shouldIncludeSampleOnCorrectPopulator()
Value[] spatialValues = FusionIndexTestHelp.valuesSupportedBySpatial();
Value[] otherValues = FusionIndexTestHelp.valuesNotSupportedByNativeOrSpatial();

for ( Value value : numberValues )
{
// when
IndexEntryUpdate<LabelSchemaDescriptor> update = add( value );
fusionIndexPopulator.includeSample( update );

// then
verify( nativePopulator ).includeSample( update );
reset( nativePopulator );
}

for ( Value value : spatialValues )
{
// when
IndexEntryUpdate<LabelSchemaDescriptor> 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<LabelSchemaDescriptor> update = add( value );
fusionIndexPopulator.includeSample( update );

// then
verify( lucenePopulator ).includeSample( update );
reset( lucenePopulator );
verify( populator ).includeSample( update );
reset( populator );
}
}
}
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a08a84c

Please sign in to comment.