Skip to content

Commit

Permalink
Break out IndexLayout creation from LayoutTestUtil, now renamed to Va…
Browse files Browse the repository at this point in the history
…lueCreatorUtil

As well as fixing some compilation issues
  • Loading branch information
burqen committed Oct 3, 2018
1 parent 081de57 commit 093dff9
Show file tree
Hide file tree
Showing 24 changed files with 191 additions and 172 deletions.
Expand Up @@ -33,7 +33,7 @@


import static java.time.ZoneOffset.UTC; import static java.time.ZoneOffset.UTC;


public class DateTimeLayoutTestUtil extends LayoutTestUtil<ZonedDateTimeIndexKey,NativeIndexValue> public class DateTimeValueCreatorUtil extends ValueCreatorUtil<ZonedDateTimeIndexKey,NativeIndexValue>
{ {
private static final ZonedDateTime[] ALL_EXTREME_VALUES = new ZonedDateTime[] private static final ZonedDateTime[] ALL_EXTREME_VALUES = new ZonedDateTime[]
{ {
Expand All @@ -45,17 +45,11 @@ public class DateTimeLayoutTestUtil extends LayoutTestUtil<ZonedDateTimeIndexKey
ZonedDateTime.of( -1, 12, 31, 23,59,59,999_999_999, UTC ) ZonedDateTime.of( -1, 12, 31, 23,59,59,999_999_999, UTC )
}; };


DateTimeLayoutTestUtil( StoreIndexDescriptor schemaIndexDescriptor ) DateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
{ {
super( schemaIndexDescriptor ); super( schemaIndexDescriptor );
} }


@Override
IndexLayout<ZonedDateTimeIndexKey,NativeIndexValue> createLayout()
{
return new ZonedDateTimeLayout();
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


public class DateLayoutTestUtil extends LayoutTestUtil<DateIndexKey,NativeIndexValue> public class DateValueCreatorUtil extends ValueCreatorUtil<DateIndexKey,NativeIndexValue>
{ {
private static final LocalDate[] ALL_EXTREME_VALUES = new LocalDate[] private static final LocalDate[] ALL_EXTREME_VALUES = new LocalDate[]
{ {
Expand All @@ -42,17 +42,11 @@ public class DateLayoutTestUtil extends LayoutTestUtil<DateIndexKey,NativeIndexV
LocalDate.of( -1, 12, 31) LocalDate.of( -1, 12, 31)
}; };


DateLayoutTestUtil( StoreIndexDescriptor indexDescriptor ) DateValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
{ {
super( indexDescriptor ); super( indexDescriptor );
} }


@Override
IndexLayout<DateIndexKey,NativeIndexValue> createLayout()
{
return new DateLayout();
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


public class DurationLayoutTestUtil extends LayoutTestUtil<DurationIndexKey,NativeIndexValue> public class DurationValueCreatorUtil extends ValueCreatorUtil<DurationIndexKey,NativeIndexValue>
{ {
private static final DurationValue[] ALL_EXTREME_VALUES = new DurationValue[] private static final DurationValue[] ALL_EXTREME_VALUES = new DurationValue[]
{ {
Expand All @@ -43,17 +43,11 @@ public class DurationLayoutTestUtil extends LayoutTestUtil<DurationIndexKey,Nati
DurationValue.duration( 0, 0, 0, Long.MAX_VALUE), DurationValue.duration( 0, 0, 0, Long.MAX_VALUE),
}; };


DurationLayoutTestUtil( StoreIndexDescriptor schemaIndexDescriptor ) DurationValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
{ {
super( schemaIndexDescriptor ); super( schemaIndexDescriptor );
} }


@Override
IndexLayout<DurationIndexKey,NativeIndexValue> createLayout()
{
return new DurationLayout();
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.neo4j.values.storable.RandomValues; import org.neo4j.values.storable.RandomValues;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


class GenericLayoutTestUtil extends LayoutTestUtil<CompositeGenericKey,NativeIndexValue> class GenericValueCreatorUtil extends ValueCreatorUtil<CompositeGenericKey,NativeIndexValue>
{ {
// todo This is only here to have SOME values to start with. It will be replaced by random value generation later on. // todo This is only here to have SOME values to start with. It will be replaced by random value generation later on.
private static final Number[] SOME_VALUE = new Number[] private static final Number[] SOME_VALUE = new Number[]
Expand Down Expand Up @@ -62,17 +62,11 @@ class GenericLayoutTestUtil extends LayoutTestUtil<CompositeGenericKey,NativeInd
new IndexSpecificSpaceFillingCurveSettingsCache( new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ), new HashMap<>() ); new IndexSpecificSpaceFillingCurveSettingsCache( new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ), new HashMap<>() );
StandardConfiguration configuration = new StandardConfiguration(); StandardConfiguration configuration = new StandardConfiguration();


GenericLayoutTestUtil( StoreIndexDescriptor indexDescriptor ) GenericValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
{ {
super( indexDescriptor ); super( indexDescriptor );
} }


@Override
IndexLayout<CompositeGenericKey,NativeIndexValue> createLayout()
{
return new GenericLayout( 1, spaceFillingCurveSettings );
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2002-2018 "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;

@FunctionalInterface
interface IndexLayoutFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
IndexLayout<KEY,VALUE> create();
}
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


public class LocalDateTimeLayoutTestUtil extends LayoutTestUtil<LocalDateTimeIndexKey,NativeIndexValue> public class LocalDateTimeValueCreatorUtil extends ValueCreatorUtil<LocalDateTimeIndexKey,NativeIndexValue>
{ {
private static final LocalDateTime[] ALL_EXTREME_VALUES = new LocalDateTime[] private static final LocalDateTime[] ALL_EXTREME_VALUES = new LocalDateTime[]
{ {
Expand All @@ -42,17 +42,11 @@ public class LocalDateTimeLayoutTestUtil extends LayoutTestUtil<LocalDateTimeInd
LocalDateTime.of( -1, 12, 31, 23,59,59,999_999_999 ) LocalDateTime.of( -1, 12, 31, 23,59,59,999_999_999 )
}; };


LocalDateTimeLayoutTestUtil( StoreIndexDescriptor schemaIndexDescriptor ) LocalDateTimeValueCreatorUtil( StoreIndexDescriptor schemaIndexDescriptor )
{ {
super( schemaIndexDescriptor ); super( schemaIndexDescriptor );
} }


@Override
IndexLayout<LocalDateTimeIndexKey,NativeIndexValue> createLayout()
{
return new LocalDateTimeLayout();
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
Expand Up @@ -30,7 +30,7 @@
import org.neo4j.values.storable.ValueGroup; import org.neo4j.values.storable.ValueGroup;
import org.neo4j.values.storable.Values; import org.neo4j.values.storable.Values;


public class LocalTimeLayoutTestUtil extends LayoutTestUtil<LocalTimeIndexKey,NativeIndexValue> public class LocalTimeValueCreatorUtil extends ValueCreatorUtil<LocalTimeIndexKey,NativeIndexValue>
{ {
private static final LocalTime[] ALL_EXTREME_VALUES = new LocalTime[] private static final LocalTime[] ALL_EXTREME_VALUES = new LocalTime[]
{ {
Expand All @@ -42,17 +42,11 @@ public class LocalTimeLayoutTestUtil extends LayoutTestUtil<LocalTimeIndexKey,Na
LocalTime.of(23,59,59,999_999_999 ) LocalTime.of(23,59,59,999_999_999 )
}; };


LocalTimeLayoutTestUtil( StoreIndexDescriptor indexDescriptor ) LocalTimeValueCreatorUtil( StoreIndexDescriptor indexDescriptor )
{ {
super( indexDescriptor ); super( indexDescriptor );
} }


@Override
IndexLayout<LocalTimeIndexKey,NativeIndexValue> createLayout()
{
return new LocalTimeLayout();
}

@Override @Override
IndexEntryUpdate<IndexDescriptor>[] someUpdates() IndexEntryUpdate<IndexDescriptor>[] someUpdates()
{ {
Expand Down
Expand Up @@ -26,7 +26,7 @@
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.Collections;


import org.neo4j.gis.spatial.index.curves.StandardConfiguration; import org.neo4j.gis.spatial.index.curves.StandardConfiguration;
import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector; import org.neo4j.index.internal.gbptree.RecoveryCleanupWorkCollector;
Expand All @@ -49,56 +49,75 @@ public static Collection<Object[]> data()
return Arrays.asList( new Object[][]{ return Arrays.asList( new Object[][]{
{"Number", {"Number",
numberAccessorFactory(), numberAccessorFactory(),
(LayoutTestUtilFactory) NumberLayoutTestUtil::new (ValueCreatorUtilFactory) NumberValueCreatorUtil::new,
(IndexLayoutFactory) NumberLayoutNonUnique::new
}, },
{"String", {"String",
stringAccessorFactory(), stringAccessorFactory(),
(LayoutTestUtilFactory) StringLayoutTestUtil::new (ValueCreatorUtilFactory) StringValueCreatorUtil::new,
(IndexLayoutFactory) StringLayout::new
}, },
{"Date", {"Date",
temporalAccessorFactory( ValueGroup.DATE ), temporalAccessorFactory( ValueGroup.DATE ),
(LayoutTestUtilFactory) DateLayoutTestUtil::new (ValueCreatorUtilFactory) DateValueCreatorUtil::new,
(IndexLayoutFactory) DateLayout::new
}, },
{"DateTime", {"DateTime",
temporalAccessorFactory( ValueGroup.ZONED_DATE_TIME ), temporalAccessorFactory( ValueGroup.ZONED_DATE_TIME ),
(LayoutTestUtilFactory) DateTimeLayoutTestUtil::new (ValueCreatorUtilFactory) DateTimeValueCreatorUtil::new,
(IndexLayoutFactory) ZonedDateTimeLayout::new
}, },
{"Duration", {"Duration",
temporalAccessorFactory( ValueGroup.DURATION ), temporalAccessorFactory( ValueGroup.DURATION ),
(LayoutTestUtilFactory) DurationLayoutTestUtil::new (ValueCreatorUtilFactory) DurationValueCreatorUtil::new,
(IndexLayoutFactory) DurationLayout::new
}, },
{"LocalDateTime", {"LocalDateTime",
temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ), temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutTestUtilFactory) LocalDateTimeLayoutTestUtil::new (ValueCreatorUtilFactory) LocalDateTimeValueCreatorUtil::new,
(IndexLayoutFactory) LocalDateTimeLayout::new
}, },
{"LocalTime", {"LocalTime",
temporalAccessorFactory( ValueGroup.LOCAL_TIME ), temporalAccessorFactory( ValueGroup.LOCAL_TIME ),
(LayoutTestUtilFactory) LocalTimeLayoutTestUtil::new (ValueCreatorUtilFactory) LocalTimeValueCreatorUtil::new,
(IndexLayoutFactory) LocalTimeLayout::new
}, },
{"LocalDateTime", {"LocalDateTime",
temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ), temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutTestUtilFactory) LocalDateTimeLayoutTestUtil::new (ValueCreatorUtilFactory) LocalDateTimeValueCreatorUtil::new,
(IndexLayoutFactory) LocalDateTimeLayout::new
}, },
{"Time", {"Time",
temporalAccessorFactory( ValueGroup.ZONED_TIME ), temporalAccessorFactory( ValueGroup.ZONED_TIME ),
(LayoutTestUtilFactory) TimeLayoutTestUtil::new (ValueCreatorUtilFactory) TimeValueCreatorUtil::new,
(IndexLayoutFactory) ZonedTimeLayout::new
}, },
{"Generic", {"Generic",
genericAccessorFactory(), genericAccessorFactory(),
(LayoutTestUtilFactory) GenericLayoutTestUtil::new (ValueCreatorUtilFactory) GenericValueCreatorUtil::new,
(IndexLayoutFactory) () -> new GenericLayout( 1, spaceFillingCurveSettings )
}, },
//{ 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 =
new IndexSpecificSpaceFillingCurveSettingsCache( new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ), Collections.emptyMap() );
private static final StandardConfiguration configuration = new StandardConfiguration();

private final AccessorFactory<KEY,VALUE> accessorFactory; private final AccessorFactory<KEY,VALUE> accessorFactory;
private final LayoutTestUtilFactory<KEY,VALUE> layoutTestUtilFactory; private final ValueCreatorUtilFactory<KEY,VALUE> valueCreatorUtilFactory;
private final IndexLayoutFactory<KEY,VALUE> indexLayoutFactory;


@SuppressWarnings( "unused" ) @SuppressWarnings( "unused" )
public NativeIndexAccessorTest( String name, AccessorFactory<KEY,VALUE> accessorFactory, LayoutTestUtilFactory<KEY,VALUE> layoutTestUtilFactory ) public NativeIndexAccessorTest( String name,
AccessorFactory<KEY,VALUE> accessorFactory,
ValueCreatorUtilFactory<KEY,VALUE> valueCreatorUtilFactory,
IndexLayoutFactory<KEY,VALUE> indexLayoutFactory )
{ {
this.accessorFactory = accessorFactory; this.accessorFactory = accessorFactory;
this.layoutTestUtilFactory = layoutTestUtilFactory; this.valueCreatorUtilFactory = valueCreatorUtilFactory;
this.indexLayoutFactory = indexLayoutFactory;
} }


@Override @Override
Expand All @@ -108,9 +127,15 @@ NativeIndexAccessor<KEY,VALUE> makeAccessor() throws IOException
} }


@Override @Override
LayoutTestUtil<KEY,VALUE> createLayoutTestUtil() ValueCreatorUtil<KEY,VALUE> createValueCreatorUtil()
{
return valueCreatorUtilFactory.create( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) );
}

@Override
IndexLayout<KEY,VALUE> createLayout()
{ {
return layoutTestUtilFactory.create( TestIndexDescriptorFactory.forLabel( 42, 666 ).withId( 0 ) ); return indexLayoutFactory.create();
} }


/* Helpers */ /* Helpers */
Expand All @@ -135,9 +160,6 @@ private static <TK extends NativeIndexSingleValueKey<TK>> AccessorFactory<TK,Nat


private static AccessorFactory<CompositeGenericKey,NativeIndexValue> genericAccessorFactory() private static AccessorFactory<CompositeGenericKey,NativeIndexValue> genericAccessorFactory()
{ {
IndexSpecificSpaceFillingCurveSettingsCache spaceFillingCurveSettings =
new IndexSpecificSpaceFillingCurveSettingsCache( new ConfiguredSpaceFillingCurveSettingsCache( Config.defaults() ), new HashMap<>() );
StandardConfiguration configuration = new StandardConfiguration();
return ( pageCache, fs, storeFile, layout, cleanup, monitor, descriptor ) -> return ( pageCache, fs, storeFile, layout, cleanup, monitor, descriptor ) ->
new GenericNativeIndexAccessor( pageCache, fs, storeFile, layout, cleanup, monitor, descriptor, spaceFillingCurveSettings, configuration ); new GenericNativeIndexAccessor( pageCache, fs, storeFile, layout, cleanup, monitor, descriptor, spaceFillingCurveSettings, configuration );
} }
Expand Down
Expand Up @@ -72,7 +72,7 @@
import static org.neo4j.kernel.api.index.IndexEntryUpdate.change; import static org.neo4j.kernel.api.index.IndexEntryUpdate.change;
import static org.neo4j.kernel.api.index.IndexEntryUpdate.remove; import static org.neo4j.kernel.api.index.IndexEntryUpdate.remove;
import static org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE; import static org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE;
import static org.neo4j.kernel.impl.index.schema.LayoutTestUtil.countUniqueValues; import static org.neo4j.kernel.impl.index.schema.ValueCreatorUtil.countUniqueValues;
import static org.neo4j.values.storable.Values.of; import static org.neo4j.values.storable.Values.of;


/** /**
Expand Down

0 comments on commit 093dff9

Please sign in to comment.