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 466cad41b46a..d4737b99fb4a 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 @@ -35,6 +35,8 @@ 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; @@ -140,7 +142,17 @@ IndexEntryUpdate[] someUpdatesWithDuplicateValues() return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); } - private IndexEntryUpdate[] generateAddUpdatesFor( Number[] values ) + IndexEntryUpdate[] someSpatialUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( SOME_POINTS ); + } + + IndexEntryUpdate[] someSpatialUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( SOME_POINTS, SOME_POINTS ) ); + } + + private IndexEntryUpdate[] generateAddUpdatesFor( Object[] values ) { @SuppressWarnings( "unchecked" ) IndexEntryUpdate[] indexEntryUpdates = new IndexEntryUpdate[values.length]; @@ -151,6 +163,14 @@ private IndexEntryUpdate[] generateAddUpdatesFor( Number[] valu 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 ) + }; + private static final Number[] ALL_EXTREME_VALUES = new Number[] { Byte.MAX_VALUE, diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutTestUtil.java new file mode 100644 index 000000000000..f03952a24905 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutTestUtil.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.impl.index.schema; + +import org.neo4j.gis.spatial.index.Envelope; +import org.neo4j.gis.spatial.index.curves.HilbertSpaceFillingCurve2D; +import org.neo4j.gis.spatial.index.curves.SpaceFillingCurve; +import org.neo4j.index.internal.gbptree.Layout; +import org.neo4j.internal.kernel.api.IndexQuery; +import org.neo4j.kernel.api.index.IndexEntryUpdate; +import org.neo4j.kernel.api.schema.index.IndexDescriptor; +import org.neo4j.kernel.api.schema.index.IndexDescriptorFactory; +import org.neo4j.values.storable.CoordinateReferenceSystem; +import org.neo4j.values.storable.PointValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +class SpatialLayoutTestUtil extends LayoutTestUtil +{ + private CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84; + private SpaceFillingCurve curve = new HilbertSpaceFillingCurve2D( new Envelope( -180, 180, -90, 90 ) ); + + SpatialLayoutTestUtil() + { + super( IndexDescriptorFactory.forLabel( 42, 666 ) ); + } + + @Override + Layout createLayout() + { + return new SpatialLayoutNonUnique( crs, curve ); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someSpatialUpdatesWithDuplicateValues(); + } + + @Override + protected double fractionDuplicates() + { + return 0.1; + } + + @Override + IndexQuery rangeQuery( Number from, boolean fromInclusive, Number to, boolean toInclusive ) + { + return IndexQuery.range( 0, (PointValue) asValue( from ), fromInclusive, (PointValue) asValue( to ), toInclusive ); + } + + @Override + Value asValue( Number value ) + { + return Values.pointValue( CoordinateReferenceSystem.WGS84, value.doubleValue(), value.doubleValue() ); + } + + // TODO fix this comparison + @Override + int compareIndexedPropertyValue( SpatialSchemaKey key1, SpatialSchemaKey key2 ) + { + int typeCompare = Byte.compare( key1.type, key2.type ); + if ( typeCompare == 0 ) + { + return Long.compare( key1.rawValueBits, key2.rawValueBits ); + } + return typeCompare; + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 000000000000..d4462ac34f54 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.impl.index.schema; + +public class SpatialNonUniqueSchemaIndexAccessorTest extends SpatialSchemaIndexAccessorTest +{ + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new SpatialLayoutTestUtil(); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialSchemaIndexAccessorTest.java new file mode 100644 index 000000000000..7d5992c22728 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialSchemaIndexAccessorTest.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2002-2018 "Neo Technology," + * Network Engine for Objects in Lund AB [http://neotechnology.com] + * + * This file is part of Neo4j. + * + * Neo4j is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.neo4j.kernel.impl.index.schema; + +import java.io.IOException; + +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public abstract class SpatialSchemaIndexAccessorTest + extends NativeSchemaIndexAccessorTest +{ + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + return new SpatialSchemaIndexAccessor<>( pageCache, fs, indexFile, layout, IMMEDIATE, monitor, indexDescriptor, indexId, samplingConfig ); + } +}