From 6e0a0765c2a08df9a0f2ddcb6490130d04e734b4 Mon Sep 17 00:00:00 2001 From: Anton Persson Date: Thu, 14 Feb 2019 16:38:23 +0100 Subject: [PATCH] Move inner test classes from NativeIndexPopulatorTest out Because inner test classes are ignored by maven. This should make those tests run on CI. Change name: NativeIndexPopulatorTest -> NativeIndexPopulatorTestCases NativeIndexPopulatorTest.UniqueTest -> NativeUniqueIndexPopulatorTest NativeIndexPopulatorTest.NonUniqueTest -> NativeNonUniqueIndexPopulatorTest --- ...ava => NativeIndexPopulatorTestCases.java} | 170 +++++------------- .../NativeNonUniqueIndexPopulatorTest.java | 63 +++++++ .../NativeUniqueIndexPopulatorTest.java | 62 +++++++ 3 files changed, 172 insertions(+), 123 deletions(-) rename community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/{NativeIndexPopulatorTest.java => NativeIndexPopulatorTestCases.java} (51%) create mode 100644 community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeNonUniqueIndexPopulatorTest.java create mode 100644 community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeUniqueIndexPopulatorTest.java diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTestCases.java similarity index 51% rename from community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTest.java rename to community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTestCases.java index 5831a4695ec99..032dff5322f06 100644 --- a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTest.java +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeIndexPopulatorTestCases.java @@ -19,9 +19,6 @@ */ package org.neo4j.kernel.impl.index.schema; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; - import java.io.File; import java.io.IOException; import java.util.Arrays; @@ -32,7 +29,6 @@ import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.pagecache.PageCache; import org.neo4j.kernel.api.index.IndexProvider; -import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; import org.neo4j.kernel.configuration.Config; import org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache; import org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettingsCache; @@ -41,63 +37,75 @@ import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueType; -public class NativeIndexPopulatorTest +class NativeIndexPopulatorTestCases { - private static Collection allPopulators() + static class TestCase, VALUE extends NativeIndexValue> + { + final String name; + final PopulatorFactory populatorFactory; + final ValueType[] typesOfGroup; + final IndexLayoutFactory indexLayoutFactory; + + TestCase( String name, PopulatorFactory populatorFactory, ValueType[] typesOfGroup, IndexLayoutFactory indexLayoutFactory ) + { + this.name = name; + this.populatorFactory = populatorFactory; + this.typesOfGroup = typesOfGroup; + this.indexLayoutFactory = indexLayoutFactory; + } + + @Override + public String toString() + { + return name; + } + } + + static Collection allCases() { return Arrays.asList( new Object[][]{ - {"Number", + {new TestCase<>( "Number", numberPopulatorFactory(), RandomValues.typesOfGroup( ValueGroup.NUMBER ), - (IndexLayoutFactory) NumberLayoutNonUnique::new - }, - {"String", - (PopulatorFactory) StringIndexPopulator::new, + NumberLayoutNonUnique::new )}, + {new TestCase<>( "String", + StringIndexPopulator::new, RandomValues.typesOfGroup( ValueGroup.TEXT ), - (IndexLayoutFactory) StringLayout::new - }, - {"Date", + StringLayout::new )}, + {new TestCase<>( "Date", temporalPopulatorFactory( ValueGroup.DATE ), RandomValues.typesOfGroup( ValueGroup.DATE ), - (IndexLayoutFactory) DateLayout::new - }, - {"DateTime", + DateLayout::new )}, + {new TestCase<>( "DateTime", temporalPopulatorFactory( ValueGroup.ZONED_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.ZONED_DATE_TIME ), - (IndexLayoutFactory) ZonedDateTimeLayout::new - }, - {"Duration", + ZonedDateTimeLayout::new )}, + {new TestCase<>( "Duration", temporalPopulatorFactory( ValueGroup.DURATION ), RandomValues.typesOfGroup( ValueGroup.DURATION ), - (IndexLayoutFactory) DurationLayout::new - }, - {"LocalDateTime", + DurationLayout::new )}, + {new TestCase<>( "LocalDateTime", temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ), - (IndexLayoutFactory) LocalDateTimeLayout::new - }, - {"LocalTime", + LocalDateTimeLayout::new )}, + {new TestCase<>( "LocalTime", temporalPopulatorFactory( ValueGroup.LOCAL_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_TIME ), - (IndexLayoutFactory) LocalTimeLayout::new - }, - {"LocalDateTime", + LocalTimeLayout::new )}, + {new TestCase<>( "LocalDateTime", temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ), - (IndexLayoutFactory) LocalDateTimeLayout::new - }, - {"Time", + LocalDateTimeLayout::new )}, + {new TestCase<>( "Time", temporalPopulatorFactory( ValueGroup.ZONED_TIME ), RandomValues.typesOfGroup( ValueGroup.ZONED_TIME ), - (IndexLayoutFactory) ZonedTimeLayout::new - }, - {"Generic", + ZonedTimeLayout::new )}, + {new TestCase<>( "Generic", genericPopulatorFactory(), ValueType.values(), - (IndexLayoutFactory) () -> new GenericLayout( 1, spaceFillingCurveSettings ) - }, - // todo { Spatial has it's own subclass because it need to override some of the test methods } + () -> new GenericLayout( 1, spaceFillingCurveSettings ) )} } ); + // { Spatial has it's own subclass because it need to override some of the test methods } } private static final IndexSpecificSpaceFillingCurveSettingsCache spaceFillingCurveSettings = @@ -126,93 +134,9 @@ private static PopulatorFactory genericPopulatorFac } @FunctionalInterface - private interface PopulatorFactory, VALUE extends NativeIndexValue> + public interface PopulatorFactory, VALUE extends NativeIndexValue> { NativeIndexPopulator create( PageCache pageCache, FileSystemAbstraction fs, File storeFile, IndexLayout layout, IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor ) throws IOException; } - - @RunWith( Parameterized.class ) - public static class UniqueTest, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.Unique - { - @Parameterized.Parameters( name = "{index} {0}" ) - public static Collection data() - { - return allPopulators(); - } - - @Parameterized.Parameter() - public String name; - - @Parameterized.Parameter( 1 ) - public PopulatorFactory populatorFactory; - - @Parameterized.Parameter( 2 ) - public ValueType[] supportedTypes; - - @Parameterized.Parameter( 3 ) - public IndexLayoutFactory indexLayoutFactory; - - private static final StoreIndexDescriptor uniqueDescriptor = TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 ); - - @Override - NativeIndexPopulator createPopulator() throws IOException - { - return populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor ); - } - - @Override - ValueCreatorUtil createValueCreatorUtil() - { - return new ValueCreatorUtil<>( uniqueDescriptor, supportedTypes, ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE ); - } - - @Override - IndexLayout createLayout() - { - return indexLayoutFactory.create(); - } - } - - @RunWith( Parameterized.class ) - public static class NonUniqueTest, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.NonUnique - { - @Parameterized.Parameters( name = "{index} {0}" ) - public static Collection data() - { - return allPopulators(); - } - - @Parameterized.Parameter() - public String name; - - @Parameterized.Parameter( 1 ) - public PopulatorFactory populatorFactory; - - @Parameterized.Parameter( 2 ) - public ValueType[] supportedTypes; - - @Parameterized.Parameter( 3 ) - public IndexLayoutFactory indexLayoutFactory; - - private static final StoreIndexDescriptor nonUniqueDescriptor = TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ); - - @Override - NativeIndexPopulator createPopulator() throws IOException - { - return populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor ); - } - - @Override - ValueCreatorUtil createValueCreatorUtil() - { - return new ValueCreatorUtil<>( nonUniqueDescriptor, supportedTypes, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE ); - } - - @Override - IndexLayout createLayout() - { - return indexLayoutFactory.create(); - } - } } diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeNonUniqueIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeNonUniqueIndexPopulatorTest.java new file mode 100644 index 0000000000000..d877b81c6bb0a --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeNonUniqueIndexPopulatorTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2002-2019 "Neo4j," + * Neo4j Sweden AB [http://neo4j.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.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.util.Collection; + +import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; +import org.neo4j.storageengine.api.schema.StoreIndexDescriptor; + +@RunWith( Parameterized.class ) +public class NativeNonUniqueIndexPopulatorTest, VALUE extends NativeIndexValue> + extends NativeIndexPopulatorTests.NonUnique +{ + @Parameterized.Parameters( name = "{index} {0}" ) + public static Collection data() + { + return NativeIndexPopulatorTestCases.allCases(); + } + + @Parameterized.Parameter() + public NativeIndexPopulatorTestCases.TestCase testCase; + + private static final StoreIndexDescriptor nonUniqueDescriptor = TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ); + + @Override + NativeIndexPopulator createPopulator() throws IOException + { + return testCase.populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor ); + } + + @Override + ValueCreatorUtil createValueCreatorUtil() + { + return new ValueCreatorUtil<>( nonUniqueDescriptor, testCase.typesOfGroup, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE ); + } + + @Override + IndexLayout createLayout() + { + return testCase.indexLayoutFactory.create(); + } +} diff --git a/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeUniqueIndexPopulatorTest.java b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeUniqueIndexPopulatorTest.java new file mode 100644 index 0000000000000..071a6b2087605 --- /dev/null +++ b/community/kernel/src/test/java/org/neo4j/kernel/impl/index/schema/NativeUniqueIndexPopulatorTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2002-2019 "Neo4j," + * Neo4j Sweden AB [http://neo4j.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.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.IOException; +import java.util.Collection; + +import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; +import org.neo4j.storageengine.api.schema.StoreIndexDescriptor; + +@RunWith( Parameterized.class ) +public class NativeUniqueIndexPopulatorTest, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.Unique +{ + @Parameterized.Parameters( name = "{index} {0}" ) + public static Collection data() + { + return NativeIndexPopulatorTestCases.allCases(); + } + + @Parameterized.Parameter() + public NativeIndexPopulatorTestCases.TestCase testCase; + + private static final StoreIndexDescriptor uniqueDescriptor = TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 ); + + @Override + NativeIndexPopulator createPopulator() throws IOException + { + return testCase.populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor ); + } + + @Override + ValueCreatorUtil createValueCreatorUtil() + { + return new ValueCreatorUtil<>( uniqueDescriptor, testCase.typesOfGroup, ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE ); + } + + @Override + IndexLayout createLayout() + { + return testCase.indexLayoutFactory.create(); + } +}