Skip to content

Commit

Permalink
Added spatial fusion tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYtterbrink committed Feb 14, 2018
1 parent d011eba commit cd00c9e
Show file tree
Hide file tree
Showing 11 changed files with 1,284 additions and 27 deletions.
Expand Up @@ -55,7 +55,7 @@ public class SpatialKnownIndex


public interface Factory public interface Factory
{ {
SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, Value... values ); SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, Value value );


SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, CoordinateReferenceSystem crs ); SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, CoordinateReferenceSystem crs );
} }
Expand Down
Expand Up @@ -128,7 +128,10 @@ public void markAsFailed( String failure ) throws IOException
@Override @Override
public void includeSample( IndexEntryUpdate<?> update ) public void includeSample( IndexEntryUpdate<?> update )
{ {
indexFactory.selectAndCreate( indexMap, indexId, update.values() ).getPopulator( descriptor, samplingConfig ).includeSample( update ); Value[] values = update.values();
assert values.length == 1;
SpatialKnownIndex index = indexFactory.selectAndCreate( indexMap, indexId, values[0] );
index.getPopulator( descriptor, samplingConfig ).includeSample( update );
} }


@Override @Override
Expand Down
Expand Up @@ -21,6 +21,7 @@


import java.util.Map; import java.util.Map;


import org.neo4j.collection.primitive.PrimitiveLongResourceCollections;
import org.neo4j.collection.primitive.PrimitiveLongResourceIterator; import org.neo4j.collection.primitive.PrimitiveLongResourceIterator;
import org.neo4j.internal.kernel.api.IndexOrder; import org.neo4j.internal.kernel.api.IndexOrder;
import org.neo4j.internal.kernel.api.IndexQuery; import org.neo4j.internal.kernel.api.IndexQuery;
Expand Down Expand Up @@ -95,9 +96,23 @@ public IndexSampler createSampler()
@Override @Override
public PrimitiveLongResourceIterator query( IndexQuery... predicates ) throws IndexNotApplicableKernelException public PrimitiveLongResourceIterator query( IndexQuery... predicates ) throws IndexNotApplicableKernelException
{ {
NodeValueIterator nodeValueIterator = new NodeValueIterator(); if ( predicates[0] instanceof ExistsPredicate )
query( nodeValueIterator, IndexOrder.NONE, predicates ); {
return nodeValueIterator; PrimitiveLongResourceIterator[] iterators = new PrimitiveLongResourceIterator[readerMap.size()];
int i = 0;
for ( IndexReader reader : readerMap.values() )
{
iterators[i] = reader.query( predicates[0] );
++i;
}
return PrimitiveLongResourceCollections.concat( iterators );
}
else
{
NodeValueIterator nodeValueIterator = new NodeValueIterator();
query( nodeValueIterator, IndexOrder.NONE, predicates );
return nodeValueIterator;
}
} }


private IndexReader selectIf( IndexQuery... predicates ) throws IndexNotApplicableKernelException private IndexReader selectIf( IndexQuery... predicates ) throws IndexNotApplicableKernelException
Expand Down
Expand Up @@ -35,6 +35,8 @@
import org.neo4j.values.storable.PointValue; import org.neo4j.values.storable.PointValue;
import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Value;


import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexUtils.forAll;

class SpatialFusionIndexUpdater implements IndexUpdater class SpatialFusionIndexUpdater implements IndexUpdater
{ {
private final Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap; private final Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap;
Expand Down Expand Up @@ -136,10 +138,7 @@ public void close() throws IOException, IndexEntryConflictException
{ {
while ( !currentUpdaters.isEmpty() ) while ( !currentUpdaters.isEmpty() )
{ {
for ( IndexUpdater updater : currentUpdaters.values() ) forAll( updater -> ((IndexUpdater) updater).close(), currentUpdaters.values().toArray() );
{
updater.close();
}
currentUpdaters.clear(); currentUpdaters.clear();
} }
} }
Expand Down
Expand Up @@ -91,7 +91,7 @@ public IndexAccessor getOnlineAccessor( long indexId, IndexDescriptor descriptor
return new SpatialFusionIndexAccessor( indexesFor( indexId ), indexId, descriptor, samplingConfig, this ); return new SpatialFusionIndexAccessor( indexesFor( indexId ), indexId, descriptor, samplingConfig, this );
} }


private Map<CoordinateReferenceSystem,SpatialKnownIndex> indexesFor( long indexId ) Map<CoordinateReferenceSystem,SpatialKnownIndex> indexesFor( long indexId )
{ {
return indexes.computeIfAbsent( indexId, k -> new HashMap<>() ); return indexes.computeIfAbsent( indexId, k -> new HashMap<>() );
} }
Expand Down Expand Up @@ -170,10 +170,9 @@ public StoreMigrationParticipant storeMigrationParticipant( FileSystemAbstractio
} }


@Override @Override
public SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, Value... values ) public SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialKnownIndex> indexMap, long indexId, Value value )
{ {
assert values.length == 1; PointValue pointValue = (PointValue) value;
PointValue pointValue = (PointValue) values[0];
CoordinateReferenceSystem crs = pointValue.getCoordinateReferenceSystem(); CoordinateReferenceSystem crs = pointValue.getCoordinateReferenceSystem();
return selectAndCreate( indexMap, indexId, crs ); return selectAndCreate( indexMap, indexId, crs );
} }
Expand All @@ -188,7 +187,12 @@ public SpatialKnownIndex selectAndCreate( Map<CoordinateReferenceSystem,SpatialK
private void findAndCreateKnownSpatialIndexes() private void findAndCreateKnownSpatialIndexes()
{ {
Pattern pattern = Pattern.compile( "(\\d+)-(\\d+)" ); Pattern pattern = Pattern.compile( "(\\d+)-(\\d+)" );
File[] files = this.directoryStructure().rootDirectory().listFiles(); File rootDirectory = this.directoryStructure().rootDirectory();
if (rootDirectory == null)
{
return;
}
File[] files = rootDirectory.listFiles();
if ( files != null ) if ( files != null )
{ {
for ( File file : files ) for ( File file : files )
Expand Down
Expand Up @@ -417,50 +417,50 @@ public void allEntriesReaderMustReportFusionMaxCountOfNativeAndLucene()
assertThat( fusionAllEntriesReader.maxCount(), is( 6L ) ); assertThat( fusionAllEntriesReader.maxCount(), is( 6L ) );
} }


private void assertResultContainsAll( Set<Long> result, long[] nativeEntries ) static void assertResultContainsAll( Set<Long> result, long[] nativeEntries )
{ {
for ( long nativeEntry : nativeEntries ) for ( long nativeEntry : nativeEntries )
{ {
assertTrue( "Expected to contain " + nativeEntry + ", but was " + result, result.contains( nativeEntry ) ); assertTrue( "Expected to contain " + nativeEntry + ", but was " + result, result.contains( nativeEntry ) );
} }
} }


private void mockAllEntriesReaders( long[] nativeEntries, long[] luceneEntries ) static BoundedIterable<Long> mockSingleAllEntriesReader( IndexAccessor targetAccessor, long[] entries )
{
mockSingleAllEntriesReader( nativeAccessor, nativeEntries );
mockSingleAllEntriesReader( spatialAccessor, nativeEntries );
mockSingleAllEntriesReader( luceneAccessor, luceneEntries );
}

private BoundedIterable<Long> mockSingleAllEntriesReader( IndexAccessor targetAccessor, long[] entries )
{ {
BoundedIterable<Long> allEntriesReader = mockedAllEntriesReader( entries ); BoundedIterable<Long> allEntriesReader = mockedAllEntriesReader( entries );
when( targetAccessor.newAllEntriesReader() ).thenReturn( allEntriesReader ); when( targetAccessor.newAllEntriesReader() ).thenReturn( allEntriesReader );
return allEntriesReader; return allEntriesReader;
} }


private BoundedIterable<Long> mockedAllEntriesReader( long... entries ) static BoundedIterable<Long> mockedAllEntriesReader( long... entries )
{ {
return mockedAllEntriesReader( true, entries ); return mockedAllEntriesReader( true, entries );
} }


private BoundedIterable<Long> mockSingleAllEntriesReaderWithUnknownMaxCount( IndexAccessor targetAccessor, long[] entries ) static BoundedIterable<Long> mockSingleAllEntriesReaderWithUnknownMaxCount( IndexAccessor targetAccessor, long[] entries )
{ {
BoundedIterable<Long> allEntriesReader = mockedAllEntriesReaderUnknownMaxCount( entries ); BoundedIterable<Long> allEntriesReader = mockedAllEntriesReaderUnknownMaxCount( entries );
when( targetAccessor.newAllEntriesReader() ).thenReturn( allEntriesReader ); when( targetAccessor.newAllEntriesReader() ).thenReturn( allEntriesReader );
return allEntriesReader; return allEntriesReader;
} }


private BoundedIterable<Long> mockedAllEntriesReaderUnknownMaxCount( long... entries ) static BoundedIterable<Long> mockedAllEntriesReaderUnknownMaxCount( long... entries )
{ {
return mockedAllEntriesReader( false, entries ); return mockedAllEntriesReader( false, entries );
} }


private BoundedIterable<Long> mockedAllEntriesReader( boolean knownMaxCount, long... entries ) static BoundedIterable<Long> mockedAllEntriesReader( boolean knownMaxCount, long... entries )
{ {
BoundedIterable<Long> mockedAllEntriesReader = mock( BoundedIterable.class ); BoundedIterable<Long> mockedAllEntriesReader = mock( BoundedIterable.class );
when( mockedAllEntriesReader.maxCount() ).thenReturn( knownMaxCount ? entries.length : BoundedIterable.UNKNOWN_MAX_COUNT ); when( mockedAllEntriesReader.maxCount() ).thenReturn( knownMaxCount ? entries.length : BoundedIterable.UNKNOWN_MAX_COUNT );
when( mockedAllEntriesReader.iterator() ).thenReturn( Iterators.asIterator(entries ) ); when( mockedAllEntriesReader.iterator() ).thenReturn( Iterators.asIterator(entries ) );
return mockedAllEntriesReader; return mockedAllEntriesReader;
} }

private void mockAllEntriesReaders( long[] nativeEntries, long[] luceneEntries )
{
mockSingleAllEntriesReader( nativeAccessor, nativeEntries );
mockSingleAllEntriesReader( spatialAccessor, nativeEntries );
mockSingleAllEntriesReader( luceneAccessor, luceneEntries );
}
} }

0 comments on commit cd00c9e

Please sign in to comment.