Skip to content

Commit

Permalink
DefaultSchemaIndexConfigTest tests all index providers
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Sep 11, 2018
1 parent 955555f commit d745018
Showing 1 changed file with 31 additions and 48 deletions.
Expand Up @@ -20,7 +20,12 @@
package org.neo4j.kernel.api.impl.schema; package org.neo4j.kernel.api.impl.schema;


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


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;


import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.GraphDatabaseService;
Expand All @@ -38,69 +43,47 @@
import org.neo4j.test.TestLabels; import org.neo4j.test.TestLabels;


import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.neo4j.graphdb.factory.GraphDatabaseSettings.default_schema_provider;


@RunWith( Parameterized.class )
public class DefaultSchemaIndexConfigTest public class DefaultSchemaIndexConfigTest
{ {
private static final String KEY = "key"; private static final String KEY = "key";
private static final TestLabels LABEL = TestLabels.LABEL_ONE; private static final TestLabels LABEL = TestLabels.LABEL_ONE;
private static final GraphDatabaseBuilder dbBuilder = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder(); private static final GraphDatabaseBuilder dbBuilder = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder();


@Test @Parameterized.Parameters( name = "{0}" )
public void shouldUseConfiguredIndexProviderNull() throws IndexNotFoundKernelException public static List<GraphDatabaseSettings.SchemaIndex> providers()
{ {
// given List<GraphDatabaseSettings.SchemaIndex> providers = new ArrayList<>();
GraphDatabaseService db = dbBuilder.setConfig( GraphDatabaseSettings.default_schema_provider, null ).newGraphDatabase(); providers.addAll( Arrays.asList( GraphDatabaseSettings.SchemaIndex.values() ) );

providers.add( null ); // <-- to exercise the default option
// when return providers;
createIndex( db );

// then
assertIndexProvider( db, NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR );
}

@Test
public void shouldUseConfiguredIndexProviderLucene() throws IndexNotFoundKernelException
{
// given
GraphDatabaseService db = dbBuilder.setConfig( GraphDatabaseSettings.default_schema_provider,
GraphDatabaseSettings.SchemaIndex.LUCENE10.providerIdentifier() ).newGraphDatabase();

// when
createIndex( db );

// then
assertIndexProvider( db, LuceneIndexProviderFactory.PROVIDER_DESCRIPTOR );
} }


@Test @Parameterized.Parameter
public void shouldUseConfiguredIndexProviderNative10() throws IndexNotFoundKernelException public GraphDatabaseSettings.SchemaIndex provider;
{
// given
GraphDatabaseService db = dbBuilder.setConfig( GraphDatabaseSettings.default_schema_provider,
GraphDatabaseSettings.SchemaIndex.NATIVE10.providerIdentifier() ).newGraphDatabase();

// when
createIndex( db );

// then
assertIndexProvider( db, NativeLuceneFusionIndexProviderFactory10.DESCRIPTOR );
}


@Test @Test
public void shouldUseConfiguredIndexProviderNative20() throws IndexNotFoundKernelException public void shouldUseConfiguredIndexProvider() throws IndexNotFoundKernelException
{ {
// given // given
GraphDatabaseService db = dbBuilder.setConfig( GraphDatabaseSettings.default_schema_provider, GraphDatabaseService db = dbBuilder.setConfig( default_schema_provider, provider == null ? null : provider.providerIdentifier() ).newGraphDatabase();
GraphDatabaseSettings.SchemaIndex.NATIVE20.providerIdentifier() ).newGraphDatabase(); try

{
// when // when
createIndex( db ); createIndex( db );


// then // then
assertIndexProvider( db, NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR ); assertIndexProvider( db, provider == null ? NativeLuceneFusionIndexProviderFactory20.DESCRIPTOR.name() : provider.providerIdentifier() );
}
finally
{
db.shutdown();
}
} }


private void assertIndexProvider( GraphDatabaseService db, IndexProviderDescriptor expected ) throws IndexNotFoundKernelException private void assertIndexProvider( GraphDatabaseService db, String expectedProviderIdentifier ) throws IndexNotFoundKernelException
{ {
GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) db; GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) db;
try ( Transaction tx = graphDatabaseAPI.beginTx() ) try ( Transaction tx = graphDatabaseAPI.beginTx() )
Expand All @@ -113,8 +96,8 @@ private void assertIndexProvider( GraphDatabaseService db, IndexProviderDescript
int propertyId = tokenRead.propertyKey( KEY ); int propertyId = tokenRead.propertyKey( KEY );
IndexReference index = ktx.schemaRead().index( labelId, propertyId ); IndexReference index = ktx.schemaRead().index( labelId, propertyId );


assertEquals( "expected IndexProvider.Descriptor", expected, assertEquals( "expected IndexProvider.Descriptor", expectedProviderIdentifier,
new IndexProviderDescriptor( index.providerKey(), index.providerVersion() ) ); new IndexProviderDescriptor( index.providerKey(), index.providerVersion() ).name() );
tx.success(); tx.success();
} }
} }
Expand Down

0 comments on commit d745018

Please sign in to comment.