diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/IndexSamplerWrapper.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/IndexSamplerWrapper.java new file mode 100644 index 0000000000000..51a42307fcaca --- /dev/null +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/IndexSamplerWrapper.java @@ -0,0 +1,74 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptor; +import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.kernel.impl.api.index.sampling.UniqueIndexSampler; +import org.neo4j.storageengine.api.schema.IndexSample; +import org.neo4j.values.storable.Value; + +class IndexSamplerWrapper +{ + private final DefaultNonUniqueIndexSampler generalSampler; + private final UniqueIndexSampler uniqueSampler; + + IndexSamplerWrapper( SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) + { + switch ( descriptor.type() ) + { + case GENERAL: + generalSampler = new DefaultNonUniqueIndexSampler( samplingConfig.sampleSizeLimit() ); + uniqueSampler = null; + break; + case UNIQUE: + generalSampler = null; + uniqueSampler = new UniqueIndexSampler(); + break; + default: + throw new UnsupportedOperationException( "Unexpected index type " + descriptor.type() ); + } + } + + void includeSample( Value[] values ) + { + if ( uniqueSampler != null ) + { + uniqueSampler.increment( 1 ); + } + else + { + generalSampler.include( SamplingUtil.encodedStringValuesForSampling( (Object[]) values ) ); + } + } + + IndexSample sampleResult() + { + if ( uniqueSampler != null ) + { + return uniqueSampler.result(); + } + else + { + return generalSampler.result(); + } + } +} diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java index a65e1a72ee7b5..3884b5eda5658 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexAccessor.java @@ -206,6 +206,7 @@ static class PartAccessor extends NativeSchemaIndexAccessor newReader() { + assertOpen(); return new SpatialIndexPartReader<>( tree, layout, samplingConfig, descriptor, searchConfiguration ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexFiles.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexFiles.java index 756a7134cd693..837768d787b57 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexFiles.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexFiles.java @@ -96,7 +96,7 @@ static class SpatialFileLayout private final CoordinateReferenceSystem crs; Layout layout; - private SpatialFileLayout( CoordinateReferenceSystem crs, SpaceFillingCurveSettings settings, File indexDirectory ) + SpatialFileLayout( CoordinateReferenceSystem crs, SpaceFillingCurveSettings settings, File indexDirectory ) { this.crs = crs; this.settings = settings; diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java index 6b87b45892daa..715e7bbda2fdf 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/SpatialIndexPopulator.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.stream.StreamSupport; import java.util.Map; import org.neo4j.gis.spatial.index.curves.SpaceFillingCurveConfiguration; @@ -37,9 +38,7 @@ import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor; -import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; -import org.neo4j.kernel.impl.api.index.sampling.UniqueIndexSampler; import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSample; @@ -48,11 +47,10 @@ import org.neo4j.values.storable.Value; import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexBase.forAll; +import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexSampler.combineSamples; class SpatialIndexPopulator extends SpatialIndexCache implements IndexPopulator { - private final IndexSamplerWrapper sampler; - SpatialIndexPopulator( long indexId, SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, @@ -63,7 +61,6 @@ class SpatialIndexPopulator extends SpatialIndexCache update ) { - sampler.includeSample( update.values() ); + Value[] values = update.values(); + assert values.length == 1; + uncheckedSelect( ((PointValue) values[0]).getCoordinateReferenceSystem() ).includeSample( update ); } @Override public IndexSample sampleResult() { - return sampler.sampleResult(); - } - - private static class IndexSamplerWrapper - { - private final DefaultNonUniqueIndexSampler generalSampler; - private final UniqueIndexSampler uniqueSampler; - - IndexSamplerWrapper( SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) - { - switch ( descriptor.type() ) - { - case GENERAL: - generalSampler = new DefaultNonUniqueIndexSampler( samplingConfig.sampleSizeLimit() ); - uniqueSampler = null; - break; - case UNIQUE: - generalSampler = null; - uniqueSampler = new UniqueIndexSampler(); - break; - default: - throw new UnsupportedOperationException( "Unexpected index type " + descriptor.type() ); - } - } - - void includeSample( Value[] values ) - { - if ( uniqueSampler != null ) - { - uniqueSampler.increment( 1 ); - } - else - { - generalSampler.include( SamplingUtil.encodedStringValuesForSampling( (Object[]) values ) ); - } - } - - IndexSample sampleResult() - { - if ( uniqueSampler != null ) - { - return uniqueSampler.result(); - } - else - { - return generalSampler.result(); - } - } + IndexSample[] indexSamples = StreamSupport.stream( this.spliterator(), false ) + .map( PartPopulator::sampleResult ) + .toArray( IndexSample[]::new ); + return combineSamples( indexSamples ); } static class PartPopulator extends NativeSchemaIndexPopulator { private final SpaceFillingCurveConfiguration configuration; private final SpaceFillingCurveSettings settings; + private final IndexSamplerWrapper sampler; PartPopulator( PageCache pageCache, FileSystemAbstraction fs, SpatialIndexFiles.SpatialFileLayout fileLayout, IndexProvider.Monitor monitor, SchemaIndexDescriptor descriptor, long indexId, IndexSamplingConfig samplingConfig, @@ -197,6 +153,7 @@ static class PartPopulator extends NativeSchemaIndexPopulator update ) { - throw new UnsupportedOperationException( "please to not get here!" ); + sampler.includeSample( update.values() ); } @Override public IndexSample sampleResult() { - throw new UnsupportedOperationException( "this sampling code needs a rewrite." ); + return sampler.sampleResult(); } @Override diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java index ac7ccc43b33e1..b2aab992c5922 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexAccessor.java @@ -193,6 +193,7 @@ static class PartAccessor> extends NativeSchema @Override public TemporalIndexPartReader newReader() { + assertOpen(); return new TemporalIndexPartReader<>( tree, layout, samplingConfig, descriptor ); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java index a488922197260..d90ea94f26e20 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/TemporalIndexPopulator.java @@ -24,6 +24,7 @@ import java.util.Collection; import java.util.HashMap; import java.util.List; +import java.util.stream.StreamSupport; import java.util.Map; import java.util.concurrent.atomic.AtomicReference; @@ -36,20 +37,17 @@ import org.neo4j.kernel.api.index.IndexUpdater; import org.neo4j.kernel.api.index.PropertyAccessor; import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor; -import org.neo4j.kernel.impl.api.index.sampling.DefaultNonUniqueIndexSampler; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; -import org.neo4j.kernel.impl.api.index.sampling.UniqueIndexSampler; import org.neo4j.storageengine.api.schema.IndexReader; import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.ValueGroup; import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexBase.forAll; +import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexSampler.combineSamples; class TemporalIndexPopulator extends TemporalIndexCache> implements IndexPopulator { - private final IndexSamplerWrapper sampler; - TemporalIndexPopulator( long indexId, SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig, @@ -59,7 +57,6 @@ class TemporalIndexPopulator extends TemporalIndexCache update ) { - sampler.includeSample( update.values() ); + Value[] values = update.values(); + assert values.length == 1; + uncheckedSelect( values[0].valueGroup() ).includeSample( update ); } @Override public IndexSample sampleResult() { - return sampler.sampleResult(); - } - - private static class IndexSamplerWrapper - { - private final DefaultNonUniqueIndexSampler generalSampler; - private final UniqueIndexSampler uniqueSampler; - - IndexSamplerWrapper( SchemaIndexDescriptor descriptor, IndexSamplingConfig samplingConfig ) - { - switch ( descriptor.type() ) - { - case GENERAL: - generalSampler = new DefaultNonUniqueIndexSampler( samplingConfig.sampleSizeLimit() ); - uniqueSampler = null; - break; - case UNIQUE: - generalSampler = null; - uniqueSampler = new UniqueIndexSampler(); - break; - default: - throw new UnsupportedOperationException( "Unexpected index type " + descriptor.type() ); - } - } - - void includeSample( Value[] values ) - { - if ( uniqueSampler != null ) - { - uniqueSampler.increment( 1 ); - } - else - { - generalSampler.include( SamplingUtil.encodedStringValuesForSampling( (Object[]) values ) ); - } - } - - IndexSample sampleResult() - { - if ( uniqueSampler != null ) - { - return uniqueSampler.result(); - } - else - { - return generalSampler.result(); - } - } + IndexSample[] indexSamples = StreamSupport.stream( this.spliterator(), false ) + .map( PartPopulator::sampleResult ) + .toArray( IndexSample[]::new ); + return combineSamples( indexSamples ); } static class PartPopulator> extends NativeSchemaIndexPopulator { + private final IndexSamplerWrapper sampler; + PartPopulator( PageCache pageCache, FileSystemAbstraction fs, TemporalIndexFiles.FileLayout fileLayout, IndexProvider.Monitor monitor, SchemaIndexDescriptor descriptor, long indexId, IndexSamplingConfig samplingConfig ) { super( pageCache, fs, fileLayout.indexFile, fileLayout.layout, monitor, descriptor, indexId, samplingConfig ); + this.sampler = new IndexSamplerWrapper( descriptor, samplingConfig ); } @Override @@ -197,13 +155,13 @@ IndexReader newReader() @Override public void includeSample( IndexEntryUpdate update ) { - throw new UnsupportedOperationException( "please to not get here!" ); + sampler.includeSample( update.values() ); } @Override public IndexSample sampleResult() { - throw new UnsupportedOperationException( "this sampling code needs a rewrite." ); + return sampler.sampleResult(); } } diff --git a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexSampler.java b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexSampler.java index 89ee8cf1a1ca7..9a1a76c5a6d6c 100644 --- a/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexSampler.java +++ b/community/kernel/src/main/java/org/neo4j/kernel/impl/index/schema/fusion/FusionIndexSampler.java @@ -19,8 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema.fusion; -import java.util.Arrays; - import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.storageengine.api.schema.IndexSample; import org.neo4j.storageengine.api.schema.IndexSampler; @@ -45,11 +43,17 @@ public IndexSample sampleIndex() throws IndexNotFoundKernelException return combineSamples( samples ); } - static IndexSample combineSamples( IndexSample... samples ) + public static IndexSample combineSamples( IndexSample... samples ) { - return new IndexSample( - Arrays.stream( samples ).mapToLong( IndexSample::indexSize ).sum(), - Arrays.stream( samples ).mapToLong( IndexSample::uniqueValues ).sum(), - Arrays.stream( samples ).mapToLong( IndexSample::sampleSize ).sum() ); + long indexSize = 0; + long uniqueValues = 0; + long sampleSize = 0; + for ( IndexSample sample : samples ) + { + indexSize += sample.indexSize(); + uniqueValues += sample.uniqueValues(); + sampleSize += sample.sampleSize(); + } + return new IndexSample( indexSize, uniqueValues, sampleSize ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateLayoutTestUtil.java new file mode 100644 index 0000000000000..e5e031eb5ea76 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateLayoutTestUtil.java @@ -0,0 +1,102 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.time.LocalDate; +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.DateValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +public class DateLayoutTestUtil extends LayoutTestUtil +{ + private static final LocalDate[] ALL_EXTREME_VALUES = new LocalDate[] + { + LocalDate.of( -999999999, 1, 1), + LocalDate.of( 999999999, 12, 31), + LocalDate.of( 0, 1, 1), + LocalDate.of( 0, 1, 2), + LocalDate.of( 0, 1, 3), + LocalDate.of( -1, 12, 31) + }; + + DateLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new DateLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (DateValue) from, fromInclusive, (DateValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( DateSchemaKey key1, DateSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + DateValue candidate; + do + { + candidate = DateValue.epochDate( random.nextLong( (-999_999_999L - 1970) * 365, (999_999_999L - 1970) * 365) ); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..5ff7fb27079bf --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DateNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DATE ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DateLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..ca2ce4f3d7818 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DateNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DATE ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DateLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeLayoutTestUtil.java new file mode 100644 index 0000000000000..55cb4b7a06781 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeLayoutTestUtil.java @@ -0,0 +1,107 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.DateTimeValue; +import org.neo4j.values.storable.TemporalValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +import static java.time.ZoneOffset.UTC; + +public class DateTimeLayoutTestUtil extends LayoutTestUtil +{ + private static final ZonedDateTime[] ALL_EXTREME_VALUES = new ZonedDateTime[] + { + ZonedDateTime.of( -999999999, 1, 1, 0, 0, 0, 0, ZoneOffset.ofHours( -18 ) ), + ZonedDateTime.of( 999999999, 12, 31, 23, 59, 59, 999_999_999, ZoneOffset.ofHours( 18 ) ), + ZonedDateTime.of( 0, 1, 1, 0,0,0,0, UTC ), + ZonedDateTime.of( 0, 1, 1, 0,0,0,0, ZoneOffset.ofHours( -18 ) ), + ZonedDateTime.of( 0, 1, 1, 0,0,0,0, ZoneOffset.ofHours( 18 ) ), + ZonedDateTime.of( -1, 12, 31, 23,59,59,999_999_999, UTC ) + }; + + DateTimeLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new ZonedDateTimeLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (DateTimeValue) from, fromInclusive, (DateTimeValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( ZonedDateTimeSchemaKey key1, ZonedDateTimeSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + DateTimeValue candidate; + do + { + candidate = DateTimeValue.datetime( random.nextLong( (-999_999_999L - 1970) * 365 * 24 * 60 * 60, (999_999_999L - 1970) * 365 * 24 * 60 * 60 ), 0, + UTC ); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..4023c30529361 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DateTimeNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_DATE_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..fc3ccc8e1c4dd --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DateTimeNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_DATE_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..6957f83342ae2 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DateTimeUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_DATE_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( new DateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..4266432144d73 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateTimeUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DateTimeUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_DATE_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new DateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..29d482852ead0 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,46 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DateUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DATE ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new DateLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..c36012834b18c --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DateUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DateUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DATE ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new DateLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationLayoutTestUtil.java new file mode 100644 index 0000000000000..61fddc68b3cfc --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationLayoutTestUtil.java @@ -0,0 +1,106 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.DurationValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +public class DurationLayoutTestUtil extends LayoutTestUtil +{ + private static final DurationValue[] ALL_EXTREME_VALUES = new DurationValue[] + { + DurationValue.duration( -999999999L * 12, 0, 0, 0), + DurationValue.duration( 999999999L * 12, 0, 0, 0), + DurationValue.duration( 0, -999999999L * 12 * 28, 0, 0), + DurationValue.duration( 0, 999999999L * 12 * 28, 0, 0), + DurationValue.duration( 0, 0, Long.MIN_VALUE, 0), + DurationValue.duration( 0, 0, Long.MAX_VALUE, 0), + DurationValue.duration( 0, 0, 0, Long.MIN_VALUE), + DurationValue.duration( 0, 0, 0, Long.MAX_VALUE), + }; + + DurationLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new DurationLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (DurationValue) from, fromInclusive, (DurationValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( DurationSchemaKey key1, DurationSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + DurationValue candidate; + do + { + candidate = DurationValue.duration( random.nextLong( -999_999_999L * 12, 999_999_999L * 12), + random.nextLong( -999_999_999L * 12 * 28, 999_999_999L * 12 * 28), + random.nextLong(), + random.nextLong() ); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..270158e36c504 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DurationNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DURATION ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DurationLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..cbcf918f430a8 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DurationNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DURATION ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new DurationLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..11e6becba5b17 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,46 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class DurationUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_DATE_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new DurationLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..aab47d3b86196 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/DurationUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class DurationUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.DURATION ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new DurationLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} 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 0d510fdd8677a..9998f8780beca 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 @@ -54,7 +54,10 @@ abstract class LayoutTestUtil, VALUE extends Na abstract IndexEntryUpdate[] someUpdates(); - protected abstract double fractionDuplicates(); + protected double fractionDuplicates() + { + return 0.1; + } abstract IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeLayoutTestUtil.java new file mode 100644 index 0000000000000..4a3b6fe31aa6a --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeLayoutTestUtil.java @@ -0,0 +1,103 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.LocalDateTimeValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +public class LocalDateTimeLayoutTestUtil extends LayoutTestUtil +{ + private static final LocalDateTime[] ALL_EXTREME_VALUES = new LocalDateTime[] + { + LocalDateTime.of( -999999999, 1, 1, 0, 0, 0, 0), + LocalDateTime.of( 999999999, 12, 31, 23, 59, 59, 999_999_999), + LocalDateTime.of( 0, 1, 1, 0,0,0,0 ), + LocalDateTime.of( 0, 1, 1, 0,0,0,1), + LocalDateTime.of( 0, 1, 1, 0,0,0,2), + LocalDateTime.of( -1, 12, 31, 23,59,59,999_999_999 ) + }; + + LocalDateTimeLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new LocalDateTimeLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (LocalDateTimeValue) from, fromInclusive, (LocalDateTimeValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( LocalDateTimeSchemaKey key1, LocalDateTimeSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + LocalDateTimeValue candidate; + do + { + candidate = LocalDateTimeValue.localDateTime( + random.nextLong( (-999_999_999L - 1970) * 365 * 24 * 60 * 60, (999_999_999L - 1970) * 365 * 24 * 60 * 60 ), 0 ); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..7670e6e4810c9 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class LocalDateTimeNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_DATE_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new LocalDateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..caac9df3b6a49 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class LocalDateTimeNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_DATE_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new LocalDateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..a6a7986fb4907 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class LocalDateTimeUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_DATE_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( new LocalDateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..ff48c9d69911b --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalDateTimeUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class LocalDateTimeUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_DATE_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new LocalDateTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeLayoutTestUtil.java new file mode 100644 index 0000000000000..f9d61eff21c6b --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeLayoutTestUtil.java @@ -0,0 +1,104 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.time.LocalTime; +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.LocalTimeValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +import static org.neo4j.kernel.impl.index.schema.TimeLayoutTestUtil.MAX_NANOS_PER_DAY; + +public class LocalTimeLayoutTestUtil extends LayoutTestUtil +{ + private static final LocalTime[] ALL_EXTREME_VALUES = new LocalTime[] + { + LocalTime.of(0, 0, 0, 0), + LocalTime.of(0,0,0,1 ), + LocalTime.of(0,0,0,2 ), + LocalTime.of(0,0,0,3 ), + LocalTime.of(23,59,59,999_999_998 ), + LocalTime.of(23,59,59,999_999_999 ) + }; + + LocalTimeLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new LocalTimeLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (LocalTimeValue) from, fromInclusive, (LocalTimeValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( LocalTimeSchemaKey key1, LocalTimeSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + LocalTimeValue candidate; + do + { + candidate = LocalTimeValue.localTime(random.nextLong( 0, MAX_NANOS_PER_DAY ) ); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..e9d21c9a0c209 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class LocalTimeNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new LocalTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..e17c56fe4c6c3 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class LocalTimeNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new LocalTimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..ba121d020ec88 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,46 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class LocalTimeUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new LocalTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..5a7098a6945fe --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/LocalTimeUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class LocalTimeUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.LOCAL_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new LocalTimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} 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 9836dc8574042..8feac94ba7a55 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 @@ -582,7 +582,7 @@ public void snapshotFilesShouldReturnIndexFile() // then assertTrue( files.hasNext() ); - assertEquals( indexFile, files.next() ); + assertEquals( getIndexFile(), files.next() ); assertFalse( files.hasNext() ); } @@ -697,7 +697,7 @@ public void shouldNotSeeFilteredEntries() throws Exception // when NodeValueIterator iter = new NodeValueIterator(); - IndexQuery.ExactPredicate filter = IndexQuery.exact( 0, valueOf( updates[1] ) ); + IndexQuery.ExactPredicate filter = IndexQuery.exact( 0, updates[1].values()[0].asObjectCopy() ); IndexQuery rangeQuery = layoutUtil.rangeQuery( valueOf( updates[0] ), true, valueOf( updates[2] ), true ); IndexProgressor.NodeValueClient filterClient = filterClient( iter, filter ); reader.query( filterClient, IndexOrder.NONE, rangeQuery ); @@ -730,7 +730,7 @@ private static Predicate> skipExisting( private Object valueOf( IndexEntryUpdate update ) { - return update.values()[0].asObject(); + return update.values()[0]; } private IndexProgressor.NodeValueClient filterClient( final NodeValueIterator iter, final IndexQuery.ExactPredicate filter ) diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java index 8a51ac1396d3b..4f54f46ec9162 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexPopulatorTest.java @@ -74,14 +74,13 @@ public abstract class NativeSchemaIndexPopulatorTest populator; @Before - public void setupPopulator() + public void setupPopulator() throws IOException { IndexSamplingConfig samplingConfig = new IndexSamplingConfig( Config.defaults() ); - populator = createPopulator( pageCache, fs, indexFile, layout, samplingConfig ); + populator = createPopulator( samplingConfig ); } - abstract NativeSchemaIndexPopulator createPopulator( PageCache pageCache, FileSystemAbstraction fs, File indexFile, - Layout layout, IndexSamplingConfig samplingConfig ); + abstract NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) throws IOException; @Test public void createShouldCreateFile() throws Exception @@ -107,7 +106,7 @@ public void createShouldClearExistingFile() throws Exception populator.create(); // then - try ( StoreChannel r = fs.open( indexFile, OpenMode.READ ) ) + try ( StoreChannel r = fs.open( getIndexFile(), OpenMode.READ ) ) { byte[] firstBytes = new byte[someBytes.length]; r.readAll( ByteBuffer.wrap( firstBytes ) ); @@ -237,7 +236,7 @@ public void successfulCloseMustCloseGBPTree() throws Exception { // given populator.create(); - Optional existingMapping = pageCache.getExistingMapping( indexFile ); + Optional existingMapping = pageCache.getExistingMapping( getIndexFile() ); if ( existingMapping.isPresent() ) { existingMapping.get().close(); @@ -251,7 +250,7 @@ public void successfulCloseMustCloseGBPTree() throws Exception populator.close( true ); // then - existingMapping = pageCache.getExistingMapping( indexFile ); + existingMapping = pageCache.getExistingMapping( getIndexFile() ); assertFalse( existingMapping.isPresent() ); } @@ -283,7 +282,7 @@ public void unsuccessfulCloseMustCloseGBPTree() throws Exception { // given populator.create(); - Optional existingMapping = pageCache.getExistingMapping( indexFile ); + Optional existingMapping = pageCache.getExistingMapping( getIndexFile() ); if ( existingMapping.isPresent() ) { existingMapping.get().close(); @@ -297,7 +296,7 @@ public void unsuccessfulCloseMustCloseGBPTree() throws Exception populator.close( false ); // then - existingMapping = pageCache.getExistingMapping( indexFile ); + existingMapping = pageCache.getExistingMapping( getIndexFile() ); assertFalse( existingMapping.isPresent() ); } @@ -514,7 +513,7 @@ private int interleaveLargeAmountOfUpdates( Random updaterRandom, private void assertHeader( boolean online, String failureMessage, boolean messageTruncated ) throws IOException { NativeSchemaIndexHeaderReader headerReader = new NativeSchemaIndexHeaderReader(); - try ( GBPTree ignored = new GBPTree<>( pageCache, indexFile, layout, 0, GBPTree.NO_MONITOR, + try ( GBPTree ignored = new GBPTree<>( pageCache, getIndexFile(), layout, 0, GBPTree.NO_MONITOR, headerReader, NO_HEADER_WRITER, RecoveryCleanupWorkCollector.IMMEDIATE ) ) { if ( online ) @@ -599,7 +598,8 @@ private void verifyUpdates( Iterator> in private byte[] fileWithContent() throws IOException { int size = 1000; - try ( StoreChannel storeChannel = fs.create( indexFile ) ) + fs.mkdirs( getIndexFile().getParentFile() ); + try ( StoreChannel storeChannel = fs.create( getIndexFile() ) ) { byte[] someBytes = new byte[size]; random.nextBytes( someBytes ); diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexTestUtil.java index 48d5272ad6d1e..2d3ee9bd2190f 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexTestUtil.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeSchemaIndexTestUtil.java @@ -67,7 +67,7 @@ public abstract class NativeSchemaIndexTestUtil SchemaIndexDescriptor schemaIndexDescriptor; LayoutTestUtil layoutUtil; Layout layout; - File indexFile; + private File indexFile; PageCache pageCache; IndexProvider.Monitor monitor = IndexProvider.Monitor.EMPTY; long indexId = 1; @@ -82,6 +82,11 @@ public void setup() pageCache = pageCacheRule.getPageCache( fs ); } + public File getIndexFile() + { + return indexFile; + } + abstract LayoutTestUtil createLayoutTestUtil(); private void copyValue( VALUE value, VALUE intoValue ) @@ -120,7 +125,7 @@ void verifyUpdates( IndexEntryUpdate[] updates ) GBPTree getTree() throws IOException { - return new GBPTree<>( pageCache, indexFile, layout, 0, GBPTree.NO_MONITOR, + return new GBPTree<>( pageCache, getIndexFile(), layout, 0, GBPTree.NO_MONITOR, NO_HEADER_READER, NO_HEADER_WRITER, RecoveryCleanupWorkCollector.IMMEDIATE ); } @@ -182,11 +187,11 @@ private Hit hit( final KEY key, final VALUE value ) void assertFilePresent() { - assertTrue( fs.fileExists( indexFile ) ); + assertTrue( fs.fileExists( getIndexFile() ) ); } void assertFileNotPresent() { - assertFalse( fs.fileExists( indexFile ) ); + assertFalse( fs.fileExists( getIndexFile() ) ); } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberLayoutTestUtil.java index 32fe874140981..c0fe47879838e 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberLayoutTestUtil.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberLayoutTestUtil.java @@ -28,6 +28,7 @@ import org.neo4j.kernel.api.index.IndexEntryUpdate; import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptor; import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.NumberValue; import org.neo4j.values.storable.Value; import org.neo4j.values.storable.Values; @@ -63,7 +64,7 @@ abstract class NumberLayoutTestUtil extends LayoutTestUtil { @Override - NativeSchemaIndexPopulator createPopulator( PageCache pageCache, FileSystemAbstraction fs, - File indexFile, Layout layout, IndexSamplingConfig samplingConfig ) + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) { - return new NumberSchemaIndexPopulator( pageCache, fs, indexFile, layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + return new NumberSchemaIndexPopulator( pageCache, fs, getIndexFile(), layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } @Override diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberSchemaIndexAccessorTest.java index f2970829e9c12..07f3738f290ea 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberSchemaIndexAccessorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberSchemaIndexAccessorTest.java @@ -44,7 +44,7 @@ public abstract class NumberSchemaIndexAccessorTest extends NativeSchemaIndexAcc @Override NumberSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException { - return new NumberSchemaIndexAccessor( pageCache, fs, indexFile, layout, IMMEDIATE, monitor, + return new NumberSchemaIndexAccessor( pageCache, fs, getIndexFile(), layout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberUniqueSchemaIndexPopulatorTest.java index 554dc2074f52f..03531e23db8ae 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberUniqueSchemaIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NumberUniqueSchemaIndexPopulatorTest.java @@ -19,20 +19,14 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.File; -import org.neo4j.index.internal.gbptree.Layout; -import org.neo4j.io.fs.FileSystemAbstraction; -import org.neo4j.io.pagecache.PageCache; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; public class NumberUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest { @Override - NativeSchemaIndexPopulator createPopulator( - PageCache pageCache, FileSystemAbstraction fs, File indexFile, - Layout layout, IndexSamplingConfig samplingConfig ) + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) { - return new NumberSchemaIndexPopulator( pageCache, fs, indexFile, layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + return new NumberSchemaIndexPopulator( pageCache, fs, getIndexFile(), layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } @Override 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 0000000000000..500166c6fc6c9 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialLayoutTestUtil.java @@ -0,0 +1,118 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; +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; + +import static org.neo4j.values.storable.CoordinateReferenceSystem.WGS84; + +class SpatialLayoutTestUtil extends LayoutTestUtil +{ + private static final PointValue[] ALL_EXTREME_VALUES = new PointValue[] + { + Values.pointValue( WGS84, -180, -90 ), + Values.pointValue( WGS84, -180, 90 ), + Values.pointValue( WGS84, 0, 0 ), + Values.pointValue( WGS84, -1, 1 ), + Values.pointValue( WGS84, 180, 90 ), + Values.pointValue( WGS84, 180, -90 ), + }; + + private final CoordinateReferenceSystem crs; + private final SpaceFillingCurve curve; + + SpatialLayoutTestUtil( SchemaIndexDescriptor descriptor, SpaceFillingCurveSettings settings, CoordinateReferenceSystem crs ) + { + super( descriptor ); + this.curve = settings.curve(); + this.crs = crs; + // The layout is the same, but we might consider supporting other CRS here, too. + assert crs == CoordinateReferenceSystem.WGS84; + } + + @Override + Layout createLayout() + { + return new SpatialLayout( crs, curve ); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (PointValue) from , fromInclusive, (PointValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( SpatialSchemaKey key1, SpatialSchemaKey key2 ) + { + return Long.compare( key1.rawValueBits, key2.rawValueBits ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + double x, y; + PointValue pointValue; + Long compareValue; + do + { + x = random.nextDouble() * 360 - 180; + y = random.nextDouble() * 180 - 90; + pointValue = Values.pointValue( crs, x, y ); + compareValue = curve.derivedValueFor( pointValue.coordinate() ); + } + while ( !uniqueCompareValues.add( compareValue ) ); + uniqueValues.add( pointValue ); + return pointValue; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} 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 0000000000000..bbc09058a4f9e --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,63 @@ +/* + * 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.File; +import java.io.IOException; + +import org.neo4j.gis.spatial.index.curves.StandardConfiguration; +import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.configuration.Config; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettingsFactory; +import org.neo4j.values.storable.CoordinateReferenceSystem; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class SpatialNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + private static final CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84; + private static final SpaceFillingCurveSettings settings = new SpaceFillingCurveSettingsFactory( Config.defaults() ).settingsFor( crs ); + + SpatialIndexFiles.SpatialFileLayout fileLayout; + + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + fileLayout = new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + SpatialIndexFiles.SpatialFileLayout fileLayout = + new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + return new SpatialIndexAccessor.PartAccessor( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig, + new StandardConfiguration() ); + } + + @Override + public File getIndexFile() + { + return fileLayout.indexFile; + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new SpatialLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ), settings, crs ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..15c7dbd58b738 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,58 @@ +/* + * 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.File; + +import org.neo4j.gis.spatial.index.curves.StandardConfiguration; +import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.configuration.Config; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettingsFactory; +import org.neo4j.values.storable.CoordinateReferenceSystem; + +public class SpatialNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + private static final CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84; + private static final SpaceFillingCurveSettings settings = new SpaceFillingCurveSettingsFactory( Config.defaults() ).settingsFor( crs ); + + private SpatialIndexFiles.SpatialFileLayout fileLayout; + + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + fileLayout = new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + return new SpatialIndexPopulator.PartPopulator( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig, + new StandardConfiguration() ); + } + + @Override + public File getIndexFile() + { + return fileLayout.indexFile; + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new SpatialLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ), settings, crs ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..5bf617a4cf8cd --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,63 @@ +/* + * 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.File; +import java.io.IOException; + +import org.neo4j.gis.spatial.index.curves.StandardConfiguration; +import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.configuration.Config; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettingsFactory; +import org.neo4j.values.storable.CoordinateReferenceSystem; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class SpatialUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + private static final CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84; + private static final SpaceFillingCurveSettings settings = new SpaceFillingCurveSettingsFactory( Config.defaults() ).settingsFor( crs ); + + SpatialIndexFiles.SpatialFileLayout fileLayout; + + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + fileLayout = new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + SpatialIndexFiles.SpatialFileLayout fileLayout = + new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + return new SpatialIndexAccessor.PartAccessor( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig, + new StandardConfiguration() ); + } + + @Override + public File getIndexFile() + { + return fileLayout.indexFile; + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( new SpatialLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ), settings, crs ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..a78511567fab4 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/SpatialUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,58 @@ +/* + * 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.File; + +import org.neo4j.gis.spatial.index.curves.StandardConfiguration; +import org.neo4j.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.configuration.Config; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettings; +import org.neo4j.kernel.impl.index.schema.config.SpaceFillingCurveSettingsFactory; +import org.neo4j.values.storable.CoordinateReferenceSystem; + +public class SpatialUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + private static final CoordinateReferenceSystem crs = CoordinateReferenceSystem.WGS84; + private static final SpaceFillingCurveSettings settings = new SpaceFillingCurveSettingsFactory( Config.defaults() ).settingsFor( crs ); + + private SpatialIndexFiles.SpatialFileLayout fileLayout; + + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + fileLayout = new SpatialIndexFiles.SpatialFileLayout( CoordinateReferenceSystem.WGS84, settings, super.getIndexFile() ); + return new SpatialIndexPopulator.PartPopulator( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig, + new StandardConfiguration() ); + } + + @Override + public File getIndexFile() + { + return fileLayout.indexFile; + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( new SpatialLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ), settings, crs ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringLayoutTestUtil.java index c6064e7d6af38..6e553813afdb4 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringLayoutTestUtil.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringLayoutTestUtil.java @@ -47,7 +47,7 @@ abstract class StringLayoutTestUtil extends LayoutTestUtil { @Override - NativeSchemaIndexPopulator createPopulator( PageCache pageCache, FileSystemAbstraction fs, - File indexFile, Layout layout, IndexSamplingConfig samplingConfig ) + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) { - return new StringSchemaIndexPopulator( pageCache, fs, indexFile, layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + return new StringSchemaIndexPopulator( pageCache, fs, getIndexFile(), layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } @Override diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringSchemaIndexAccessorTest.java index 48ec490f7cede..d02290a8f8592 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringSchemaIndexAccessorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringSchemaIndexAccessorTest.java @@ -29,7 +29,7 @@ public abstract class StringSchemaIndexAccessorTest extends NativeSchemaIndexAcc @Override StringSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException { - return new StringSchemaIndexAccessor( pageCache, fs, indexFile, layout, IMMEDIATE, monitor, + return new StringSchemaIndexAccessor( pageCache, fs, getIndexFile(), layout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringUniqueSchemaIndexPopulatorTest.java index 677447d166584..a2f46350439d3 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringUniqueSchemaIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/StringUniqueSchemaIndexPopulatorTest.java @@ -19,20 +19,14 @@ */ package org.neo4j.kernel.impl.index.schema; -import java.io.File; -import org.neo4j.index.internal.gbptree.Layout; -import org.neo4j.io.fs.FileSystemAbstraction; -import org.neo4j.io.pagecache.PageCache; import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; public class StringUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest { @Override - NativeSchemaIndexPopulator createPopulator( - PageCache pageCache, FileSystemAbstraction fs, File indexFile, - Layout layout, IndexSamplingConfig samplingConfig ) + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) { - return new StringSchemaIndexPopulator( pageCache, fs, indexFile, layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + return new StringSchemaIndexPopulator( pageCache, fs, getIndexFile(), layout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); } @Override diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeLayoutTestUtil.java new file mode 100644 index 0000000000000..09436eba0dc8b --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeLayoutTestUtil.java @@ -0,0 +1,107 @@ +/* + * 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.apache.commons.lang3.ArrayUtils; + +import java.time.OffsetTime; +import java.time.ZoneOffset; +import java.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.TimeValue; +import org.neo4j.values.storable.Value; +import org.neo4j.values.storable.Values; + +import static java.time.ZoneOffset.UTC; + +public class TimeLayoutTestUtil extends LayoutTestUtil +{ + static long MAX_NANOS_PER_DAY = 86399999999999L; + + private static final OffsetTime[] ALL_EXTREME_VALUES = new OffsetTime[] + { + OffsetTime.of( 0,0,0,0, ZoneOffset.ofHours( -18 ) ), + OffsetTime.of( 0,0,0,0, ZoneOffset.ofHours( 18 ) ), + OffsetTime.of( 12,0,0,0, ZoneOffset.ofHours( -18 ) ), + OffsetTime.of( 12,0,0,0, ZoneOffset.ofHours( 18 ) ), + OffsetTime.of( 23,59,59,999_999_999, ZoneOffset.ofHours( 18 ) ), + OffsetTime.of( 23,59,59,999_999_999, ZoneOffset.ofHours( -18 ) ), + }; + + TimeLayoutTestUtil( SchemaIndexDescriptor schemaIndexDescriptor ) + { + super( schemaIndexDescriptor ); + } + + @Override + Layout createLayout() + { + return new ZonedTimeLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return someUpdatesWithDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return IndexQuery.range( 0, (TimeValue) from, fromInclusive, (TimeValue) to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( ZonedTimeSchemaKey key1, ZonedTimeSchemaKey key2 ) + { + return Values.COMPARATOR.compare( key1.asValue(), key2.asValue() ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + TimeValue candidate; + do + { + candidate = TimeValue.time( random.nextLong( 0, MAX_NANOS_PER_DAY ), UTC); + } + while ( !uniqueCompareValues.add( candidate ) ); + uniqueValues.add( candidate ); + return candidate; + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return generateAddUpdatesFor( ALL_EXTREME_VALUES ); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return generateAddUpdatesFor( ArrayUtils.addAll( ALL_EXTREME_VALUES, ALL_EXTREME_VALUES ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..9d72a7e2aadaf --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,45 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class TimeNonUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new TimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..658515daa740c --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeNonUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,41 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class TimeNonUniqueSchemaIndexPopulatorTest extends NativeNonUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new TimeLayoutTestUtil( SchemaIndexDescriptorFactory.forLabel( 42, 666 ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexAccessorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexAccessorTest.java new file mode 100644 index 0000000000000..3b4e9df26f845 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexAccessorTest.java @@ -0,0 +1,46 @@ +/* + * 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.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +import static org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector.IMMEDIATE; + +public class TimeUniqueSchemaIndexAccessorTest extends NativeSchemaIndexAccessorTest +{ + @Override + NativeSchemaIndexAccessor makeAccessorWithSamplingConfig( IndexSamplingConfig samplingConfig ) throws IOException + { + TemporalIndexFiles.FileLayout fileLayout = new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_TIME ); + return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, IMMEDIATE, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new TimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } + +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexPopulatorTest.java new file mode 100644 index 0000000000000..e1c5e19d85dcd --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/TimeUniqueSchemaIndexPopulatorTest.java @@ -0,0 +1,42 @@ +/* + * 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.kernel.api.schema.index.SchemaIndexDescriptorFactory; +import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig; +import org.neo4j.values.storable.ValueGroup; + +public class TimeUniqueSchemaIndexPopulatorTest extends NativeUniqueSchemaIndexPopulatorTest +{ + @Override + NativeSchemaIndexPopulator createPopulator( IndexSamplingConfig samplingConfig ) + { + TemporalIndexFiles.FileLayout fileLayout = + new TemporalIndexFiles.FileLayout<>( getIndexFile(), layout, ValueGroup.ZONED_TIME ); + return new TemporalIndexPopulator.PartPopulator<>( pageCache, fs, fileLayout, monitor, schemaIndexDescriptor, indexId, samplingConfig ); + } + + @Override + protected LayoutTestUtil createLayoutTestUtil() + { + return new UniqueLayoutTestUtil<>( + new TimeLayoutTestUtil( SchemaIndexDescriptorFactory.uniqueForLabel( 42, 666 ) ) ); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/UniqueLayoutTestUtil.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/UniqueLayoutTestUtil.java new file mode 100644 index 0000000000000..e030dcccdc01d --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/UniqueLayoutTestUtil.java @@ -0,0 +1,90 @@ +/* + * 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.util.List; +import java.util.Set; + +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.SchemaIndexDescriptor; +import org.neo4j.test.rule.RandomRule; +import org.neo4j.values.storable.Value; + +class UniqueLayoutTestUtil, VALUE extends NativeSchemaValue> extends LayoutTestUtil +{ + + private final LayoutTestUtil delegate; + + UniqueLayoutTestUtil( LayoutTestUtil delegate ) + { + super( delegate.schemaIndexDescriptor ); + this.delegate = delegate; + } + + @Override + Layout createLayout() + { + return delegate.createLayout(); + } + + @Override + IndexEntryUpdate[] someUpdates() + { + return delegate.someUpdatesNoDuplicateValues(); + } + + @Override + IndexQuery rangeQuery( Object from, boolean fromInclusive, Object to, boolean toInclusive ) + { + return delegate.rangeQuery( from, fromInclusive, to, toInclusive ); + } + + @Override + int compareIndexedPropertyValue( KEY key1, KEY key2 ) + { + return delegate.compareIndexedPropertyValue( key1, key2 ); + } + + @Override + Value newUniqueValue( RandomRule random, Set uniqueCompareValues, List uniqueValues ) + { + return delegate.newUniqueValue( random, uniqueCompareValues, uniqueValues ); + } + + @Override + IndexEntryUpdate[] someUpdatesNoDuplicateValues() + { + return delegate.someUpdatesNoDuplicateValues(); + } + + @Override + IndexEntryUpdate[] someUpdatesWithDuplicateValues() + { + return delegate.someUpdatesWithDuplicateValues(); + } + + @Override + protected double fractionDuplicates() + { + return 0; + } +}