Skip to content

Commit

Permalink
Move inner test classes from NativeIndexPopulatorTest out
Browse files Browse the repository at this point in the history
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
  • Loading branch information
burqen committed Feb 18, 2019
1 parent fe3858e commit 6e0a076
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 123 deletions.
Expand Up @@ -19,9 +19,6 @@
*/ */
package org.neo4j.kernel.impl.index.schema; package org.neo4j.kernel.impl.index.schema;


import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
Expand All @@ -32,7 +29,6 @@
import org.neo4j.io.fs.FileSystemAbstraction; import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.pagecache.PageCache; import org.neo4j.io.pagecache.PageCache;
import org.neo4j.kernel.api.index.IndexProvider; 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.configuration.Config;
import org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache; import org.neo4j.kernel.impl.index.schema.config.ConfiguredSpaceFillingCurveSettingsCache;
import org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettingsCache; import org.neo4j.kernel.impl.index.schema.config.IndexSpecificSpaceFillingCurveSettingsCache;
Expand All @@ -41,63 +37,75 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.ValueType; import org.neo4j.values.storable.ValueType;


public class NativeIndexPopulatorTest class NativeIndexPopulatorTestCases
{ {
private static Collection<Object[]> allPopulators() static class TestCase<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
final String name;
final PopulatorFactory<KEY,VALUE> populatorFactory;
final ValueType[] typesOfGroup;
final IndexLayoutFactory<KEY,VALUE> indexLayoutFactory;

TestCase( String name, PopulatorFactory<KEY,VALUE> populatorFactory, ValueType[] typesOfGroup, IndexLayoutFactory<KEY,VALUE> indexLayoutFactory )
{
this.name = name;
this.populatorFactory = populatorFactory;
this.typesOfGroup = typesOfGroup;
this.indexLayoutFactory = indexLayoutFactory;
}

@Override
public String toString()
{
return name;
}
}

static Collection<Object[]> allCases()
{ {
return Arrays.asList( new Object[][]{ return Arrays.asList( new Object[][]{
{"Number", {new TestCase<>( "Number",
numberPopulatorFactory(), numberPopulatorFactory(),
RandomValues.typesOfGroup( ValueGroup.NUMBER ), RandomValues.typesOfGroup( ValueGroup.NUMBER ),
(IndexLayoutFactory) NumberLayoutNonUnique::new NumberLayoutNonUnique::new )},
}, {new TestCase<>( "String",
{"String", StringIndexPopulator::new,
(PopulatorFactory) StringIndexPopulator::new,
RandomValues.typesOfGroup( ValueGroup.TEXT ), RandomValues.typesOfGroup( ValueGroup.TEXT ),
(IndexLayoutFactory) StringLayout::new StringLayout::new )},
}, {new TestCase<>( "Date",
{"Date",
temporalPopulatorFactory( ValueGroup.DATE ), temporalPopulatorFactory( ValueGroup.DATE ),
RandomValues.typesOfGroup( ValueGroup.DATE ), RandomValues.typesOfGroup( ValueGroup.DATE ),
(IndexLayoutFactory) DateLayout::new DateLayout::new )},
}, {new TestCase<>( "DateTime",
{"DateTime",
temporalPopulatorFactory( ValueGroup.ZONED_DATE_TIME ), temporalPopulatorFactory( ValueGroup.ZONED_DATE_TIME ),
RandomValues.typesOfGroup( ValueGroup.ZONED_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.ZONED_DATE_TIME ),
(IndexLayoutFactory) ZonedDateTimeLayout::new ZonedDateTimeLayout::new )},
}, {new TestCase<>( "Duration",
{"Duration",
temporalPopulatorFactory( ValueGroup.DURATION ), temporalPopulatorFactory( ValueGroup.DURATION ),
RandomValues.typesOfGroup( ValueGroup.DURATION ), RandomValues.typesOfGroup( ValueGroup.DURATION ),
(IndexLayoutFactory) DurationLayout::new DurationLayout::new )},
}, {new TestCase<>( "LocalDateTime",
{"LocalDateTime",
temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ), temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ),
RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ),
(IndexLayoutFactory) LocalDateTimeLayout::new LocalDateTimeLayout::new )},
}, {new TestCase<>( "LocalTime",
{"LocalTime",
temporalPopulatorFactory( ValueGroup.LOCAL_TIME ), temporalPopulatorFactory( ValueGroup.LOCAL_TIME ),
RandomValues.typesOfGroup( ValueGroup.LOCAL_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_TIME ),
(IndexLayoutFactory) LocalTimeLayout::new LocalTimeLayout::new )},
}, {new TestCase<>( "LocalDateTime",
{"LocalDateTime",
temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ), temporalPopulatorFactory( ValueGroup.LOCAL_DATE_TIME ),
RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ), RandomValues.typesOfGroup( ValueGroup.LOCAL_DATE_TIME ),
(IndexLayoutFactory) LocalDateTimeLayout::new LocalDateTimeLayout::new )},
}, {new TestCase<>( "Time",
{"Time",
temporalPopulatorFactory( ValueGroup.ZONED_TIME ), temporalPopulatorFactory( ValueGroup.ZONED_TIME ),
RandomValues.typesOfGroup( ValueGroup.ZONED_TIME ), RandomValues.typesOfGroup( ValueGroup.ZONED_TIME ),
(IndexLayoutFactory) ZonedTimeLayout::new ZonedTimeLayout::new )},
}, {new TestCase<>( "Generic",
{"Generic",
genericPopulatorFactory(), genericPopulatorFactory(),
ValueType.values(), ValueType.values(),
(IndexLayoutFactory) () -> new GenericLayout( 1, spaceFillingCurveSettings ) () -> new GenericLayout( 1, spaceFillingCurveSettings ) )}
},
// todo { Spatial has it's own subclass because it need to override some of the test methods }
} ); } );
// { Spatial has it's own subclass because it need to override some of the test methods }
} }


private static final IndexSpecificSpaceFillingCurveSettingsCache spaceFillingCurveSettings = private static final IndexSpecificSpaceFillingCurveSettingsCache spaceFillingCurveSettings =
Expand Down Expand Up @@ -126,93 +134,9 @@ private static PopulatorFactory<GenericKey,NativeIndexValue> genericPopulatorFac
} }


@FunctionalInterface @FunctionalInterface
private interface PopulatorFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> public interface PopulatorFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{ {
NativeIndexPopulator<KEY,VALUE> create( PageCache pageCache, FileSystemAbstraction fs, File storeFile, IndexLayout<KEY,VALUE> layout, NativeIndexPopulator<KEY,VALUE> create( PageCache pageCache, FileSystemAbstraction fs, File storeFile, IndexLayout<KEY,VALUE> layout,
IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor ) throws IOException; IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor ) throws IOException;
} }

@RunWith( Parameterized.class )
public static class UniqueTest<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.Unique<KEY,VALUE>
{
@Parameterized.Parameters( name = "{index} {0}" )
public static Collection<Object[]> data()
{
return allPopulators();
}

@Parameterized.Parameter()
public String name;

@Parameterized.Parameter( 1 )
public PopulatorFactory<KEY,VALUE> populatorFactory;

@Parameterized.Parameter( 2 )
public ValueType[] supportedTypes;

@Parameterized.Parameter( 3 )
public IndexLayoutFactory<KEY,VALUE> indexLayoutFactory;

private static final StoreIndexDescriptor uniqueDescriptor = TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 );

@Override
NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
{
return populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor );
}

@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return new ValueCreatorUtil<>( uniqueDescriptor, supportedTypes, ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE );
}

@Override
IndexLayout<KEY,VALUE> createLayout()
{
return indexLayoutFactory.create();
}
}

@RunWith( Parameterized.class )
public static class NonUniqueTest<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.NonUnique<KEY,VALUE>
{
@Parameterized.Parameters( name = "{index} {0}" )
public static Collection<Object[]> data()
{
return allPopulators();
}

@Parameterized.Parameter()
public String name;

@Parameterized.Parameter( 1 )
public PopulatorFactory<KEY,VALUE> populatorFactory;

@Parameterized.Parameter( 2 )
public ValueType[] supportedTypes;

@Parameterized.Parameter( 3 )
public IndexLayoutFactory<KEY,VALUE> indexLayoutFactory;

private static final StoreIndexDescriptor nonUniqueDescriptor = TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 );

@Override
NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
{
return populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor );
}

@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return new ValueCreatorUtil<>( nonUniqueDescriptor, supportedTypes, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
IndexLayout<KEY,VALUE> createLayout()
{
return indexLayoutFactory.create();
}
}
} }
@@ -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 <http://www.gnu.org/licenses/>.
*/
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<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
extends NativeIndexPopulatorTests.NonUnique<KEY,VALUE>
{
@Parameterized.Parameters( name = "{index} {0}" )
public static Collection<Object[]> data()
{
return NativeIndexPopulatorTestCases.allCases();
}

@Parameterized.Parameter()
public NativeIndexPopulatorTestCases.TestCase<KEY,VALUE> testCase;

private static final StoreIndexDescriptor nonUniqueDescriptor = TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 );

@Override
NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
{
return testCase.populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor );
}

@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return new ValueCreatorUtil<>( nonUniqueDescriptor, testCase.typesOfGroup, ValueCreatorUtil.FRACTION_DUPLICATE_NON_UNIQUE );
}

@Override
IndexLayout<KEY,VALUE> createLayout()
{
return testCase.indexLayoutFactory.create();
}
}
@@ -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 <http://www.gnu.org/licenses/>.
*/
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<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> extends NativeIndexPopulatorTests.Unique<KEY,VALUE>
{
@Parameterized.Parameters( name = "{index} {0}" )
public static Collection<Object[]> data()
{
return NativeIndexPopulatorTestCases.allCases();
}

@Parameterized.Parameter()
public NativeIndexPopulatorTestCases.TestCase<KEY,VALUE> testCase;

private static final StoreIndexDescriptor uniqueDescriptor = TestIndexDescriptorFactory.uniqueForLabel( 42, 666 ).withId( 0 );

@Override
NativeIndexPopulator<KEY,VALUE> createPopulator() throws IOException
{
return testCase.populatorFactory.create( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor );
}

@Override
ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return new ValueCreatorUtil<>( uniqueDescriptor, testCase.typesOfGroup, ValueCreatorUtil.FRACTION_DUPLICATE_UNIQUE );
}

@Override
IndexLayout<KEY,VALUE> createLayout()
{
return testCase.indexLayoutFactory.create();
}
}

0 comments on commit 6e0a076

Please sign in to comment.