Skip to content

Commit

Permalink
Gather all implementations of NativeIndexPopulatorTest in one paramet…
Browse files Browse the repository at this point in the history
…erized test

Except for Spatial for now. Expecting it to need some special care when moving
to randomized values.
  • Loading branch information
burqen committed Oct 3, 2018
1 parent 8e67d61 commit 46ea5b6
Show file tree
Hide file tree
Showing 16 changed files with 311 additions and 414 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -19,17 +19,8 @@
*/
package org.neo4j.kernel.impl.index.schema;

public class NumberUniqueIndexPopulatorTest extends NativeUniqueIndexPopulatorTest<NumberIndexKey,NativeIndexValue>
@FunctionalInterface
interface LayoutTestUtilFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
@Override
NativeIndexPopulator<NumberIndexKey,NativeIndexValue> createPopulator()
{
return new NumberIndexPopulator( pageCache, fs, getIndexFile(), layout, monitor, indexDescriptor );
}

@Override
protected LayoutTestUtil<NumberIndexKey,NativeIndexValue> createLayoutTestUtil()
{
return new NumberUniqueLayoutTestUtil();
}
LayoutTestUtil<KEY,VALUE> create();
}

This file was deleted.

This file was deleted.

Expand Up @@ -44,37 +44,63 @@
@RunWith( Parameterized.class )
public class NativeIndexAccessorTest<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue> extends NativeIndexAccessorTests<KEY,VALUE>
{
@Parameterized.Parameters(name = "{index}: {0}")
@Parameterized.Parameters( name = "{index}: {0}" )
public static Collection<Object[]> data()
{
IndexDescriptor descriptor = TestIndexDescriptorFactory.forLabel( 42, 666 );
return Arrays.asList( new Object[][]{
{"Number", numberAccessorFactory(), (LayoutUtilFactory) NumberNonUniqueLayoutTestUtil::new},
{"String", stringAccessorFactory(), (LayoutUtilFactory) StringNonUniqueLayoutTestUtil::new},
{"Date", temporalAccessorFactory( ValueGroup.DATE ), (LayoutUtilFactory) () -> new DateLayoutTestUtil( descriptor )},
{"DateTime", temporalAccessorFactory( ValueGroup.ZONED_DATE_TIME ), (LayoutUtilFactory) () -> new DateTimeLayoutTestUtil( descriptor )},
{"Duration", temporalAccessorFactory( ValueGroup.DURATION ), (LayoutUtilFactory) () -> new DurationLayoutTestUtil( descriptor )},
{"LocalDateTime", temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutUtilFactory) () -> new LocalDateTimeLayoutTestUtil( descriptor )},
{"LocalTime", temporalAccessorFactory( ValueGroup.LOCAL_TIME ),
(LayoutUtilFactory) () -> new LocalTimeLayoutTestUtil( descriptor )},
{"LocalDateTime", temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutUtilFactory) () -> new LocalDateTimeLayoutTestUtil( descriptor )},
{"Time", temporalAccessorFactory( ValueGroup.ZONED_TIME ),
(LayoutUtilFactory) () -> new TimeLayoutTestUtil( descriptor )},
{"Generic", genericAccessorFactory(), (LayoutUtilFactory) () -> new GenericLayoutTestUtil( descriptor )},
{"Number",
numberAccessorFactory(),
(LayoutTestUtilFactory) NumberNonUniqueLayoutTestUtil::new
},
{"String",
stringAccessorFactory(),
(LayoutTestUtilFactory) StringNonUniqueLayoutTestUtil::new
},
{"Date",
temporalAccessorFactory( ValueGroup.DATE ),
(LayoutTestUtilFactory) () -> new DateLayoutTestUtil( descriptor )
},
{"DateTime",
temporalAccessorFactory( ValueGroup.ZONED_DATE_TIME ),
(LayoutTestUtilFactory) () -> new DateTimeLayoutTestUtil( descriptor )
},
{"Duration",
temporalAccessorFactory( ValueGroup.DURATION ),
(LayoutTestUtilFactory) () -> new DurationLayoutTestUtil( descriptor )
},
{"LocalDateTime",
temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutTestUtilFactory) () -> new LocalDateTimeLayoutTestUtil( descriptor )
},
{"LocalTime",
temporalAccessorFactory( ValueGroup.LOCAL_TIME ),
(LayoutTestUtilFactory) () -> new LocalTimeLayoutTestUtil( descriptor )
},
{"LocalDateTime",
temporalAccessorFactory( ValueGroup.LOCAL_DATE_TIME ),
(LayoutTestUtilFactory) () -> new LocalDateTimeLayoutTestUtil( descriptor )
},
{"Time",
temporalAccessorFactory( ValueGroup.ZONED_TIME ),
(LayoutTestUtilFactory) () -> new TimeLayoutTestUtil( descriptor )
},
{"Generic",
genericAccessorFactory(),
(LayoutTestUtilFactory) () -> new GenericLayoutTestUtil( descriptor )
},
//{ Spatial has it's own subclass because it need to override some of the test methods }
} );
}

private final AccessorFactory<KEY,VALUE> accessorFactory;
private final LayoutUtilFactory<KEY,VALUE> layoutUtilFactory;
private final LayoutTestUtilFactory<KEY,VALUE> layoutTestUtilFactory;

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

@Override
Expand All @@ -86,7 +112,7 @@ NativeIndexAccessor<KEY,VALUE> makeAccessor() throws IOException
@Override
LayoutTestUtil<KEY,VALUE> createLayoutTestUtil()
{
return layoutUtilFactory.create();
return layoutTestUtilFactory.create();
}

/* Helpers */
Expand All @@ -100,11 +126,11 @@ private static AccessorFactory<StringIndexKey,NativeIndexValue> stringAccessorFa
return StringIndexAccessor::new;
}

private static AccessorFactory<DateIndexKey,NativeIndexValue> temporalAccessorFactory( ValueGroup temporalValueGroup )
private static <TK extends NativeIndexSingleValueKey<TK>> AccessorFactory<TK,NativeIndexValue> temporalAccessorFactory( ValueGroup temporalValueGroup )
{
return ( pageCache, fs, storeFile, layout, cleanup, monitor, descriptor ) ->
{
TemporalIndexFiles.FileLayout<DateIndexKey> fileLayout = new TemporalIndexFiles.FileLayout<>( storeFile, layout, temporalValueGroup );
TemporalIndexFiles.FileLayout<TK> fileLayout = new TemporalIndexFiles.FileLayout<>( storeFile, layout, temporalValueGroup );
return new TemporalIndexAccessor.PartAccessor<>( pageCache, fs, fileLayout, cleanup, monitor, descriptor );
};
}
Expand All @@ -122,13 +148,7 @@ private static AccessorFactory<CompositeGenericKey,NativeIndexValue> genericAcce
private interface AccessorFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
NativeIndexAccessor<KEY,VALUE> create( PageCache pageCache, FileSystemAbstraction fs,
File storeFile, IndexLayout<KEY,VALUE> layout, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector, IndexProvider.Monitor monitor,
StoreIndexDescriptor descriptor ) throws IOException;
}

@FunctionalInterface
private interface LayoutUtilFactory<KEY extends NativeIndexKey<KEY>, VALUE extends NativeIndexValue>
{
LayoutTestUtil<KEY,VALUE> create();
File storeFile, IndexLayout<KEY,VALUE> layout, RecoveryCleanupWorkCollector recoveryCleanupWorkCollector,
IndexProvider.Monitor monitor, StoreIndexDescriptor descriptor ) throws IOException;
}
}
Expand Up @@ -1023,7 +1023,7 @@ IndexEntryUpdate<IndexDescriptor>[] someUpdates()

private IndexEntryUpdate<IndexDescriptor>[] someUpdatesOfTypes( boolean allowDuplicates, RandomValues.Type... types )
{
if ( types.length < 1)
if ( types.length < 1 )
{
throw new IllegalArgumentException( "Need at least one type, was " + Arrays.toString( types ) );
}
Expand Down

0 comments on commit 46ea5b6

Please sign in to comment.