Skip to content

Commit

Permalink
Uses abstractions instead of accessing SchemaStore directly in test
Browse files Browse the repository at this point in the history
  • Loading branch information
tinwelint committed Jun 19, 2018
1 parent 7355d3f commit 0927a24
Showing 1 changed file with 27 additions and 40 deletions.
Expand Up @@ -27,7 +27,6 @@
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.junit.runners.Parameterized; import org.junit.runners.Parameterized;


import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
Expand All @@ -41,21 +40,19 @@
import org.neo4j.graphdb.Transaction; import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction; import org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction;
import org.neo4j.internal.kernel.api.InternalIndexState; import org.neo4j.internal.kernel.api.InternalIndexState;
import org.neo4j.internal.kernel.api.Kernel;
import org.neo4j.io.pagecache.IOLimiter; import org.neo4j.io.pagecache.IOLimiter;
import org.neo4j.kernel.api.KernelTransaction; import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.impl.schema.LuceneIndexProviderFactory; import org.neo4j.kernel.api.impl.schema.LuceneIndexProviderFactory;
import org.neo4j.kernel.api.impl.schema.NativeLuceneFusionIndexProviderFactory10; import org.neo4j.kernel.api.impl.schema.NativeLuceneFusionIndexProviderFactory10;
import org.neo4j.kernel.api.impl.schema.NativeLuceneFusionIndexProviderFactory20; import org.neo4j.kernel.api.impl.schema.NativeLuceneFusionIndexProviderFactory20;
import org.neo4j.kernel.api.index.IndexProvider; import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.api.schema.index.StoreIndexDescriptor; import org.neo4j.kernel.api.schema.RelationTypeSchemaDescriptor;
import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory; import org.neo4j.kernel.api.schema.index.TestIndexDescriptorFactory;
import org.neo4j.kernel.extension.KernelExtensionFactory; import org.neo4j.kernel.extension.KernelExtensionFactory;
import org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProviderFactory; import org.neo4j.kernel.impl.api.index.inmemory.InMemoryIndexProviderFactory;
import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge; import org.neo4j.kernel.impl.core.ThreadToStatementContextBridge;
import org.neo4j.kernel.impl.storageengine.impl.recordstorage.RecordStorageEngine;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.SchemaStore;
import org.neo4j.kernel.impl.store.UnderlyingStorageException; import org.neo4j.kernel.impl.store.UnderlyingStorageException;
import org.neo4j.kernel.internal.GraphDatabaseAPI; import org.neo4j.kernel.internal.GraphDatabaseAPI;
import org.neo4j.storageengine.api.schema.PopulationProgress; import org.neo4j.storageengine.api.schema.PopulationProgress;
Expand All @@ -64,9 +61,10 @@


import static java.util.Arrays.asList; import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.neo4j.internal.kernel.api.Transaction.Type.explicit;
import static org.neo4j.internal.kernel.api.security.LoginContext.AUTH_DISABLED;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel; import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forLabel;
import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forRelType; import static org.neo4j.kernel.api.schema.SchemaDescriptorFactory.forRelType;
import static org.neo4j.kernel.api.schema.index.IndexDescriptorFactory.forSchema;


@RunWith( Parameterized.class ) @RunWith( Parameterized.class )
public class IndexingServiceIntegrationTest public class IndexingServiceIntegrationTest
Expand Down Expand Up @@ -123,17 +121,19 @@ public void tearDown()
} }


@Test @Test
public void testManualIndexPopulation() throws IOException, IndexNotFoundKernelException, InterruptedException public void testManualIndexPopulation() throws InterruptedException, IndexNotFoundKernelException
{ {
IndexingService indexingService = getIndexingService( database ); try ( Transaction tx = database.beginTx() )
SchemaStore schemaStore = getSchemaStore( database ); {
database.schema().indexFor( Label.label( FOOD_LABEL ) ).on( PROPERTY_NAME ).create();
tx.success();
}


int foodId = getLabelId( FOOD_LABEL ); int labelId = getLabelId( FOOD_LABEL );
int propertyId = getPropertyKeyId( PROPERTY_NAME ); int propertyKeyId = getPropertyKeyId( PROPERTY_NAME );


StoreIndexDescriptor rule = forSchema( forLabel( foodId, propertyId ), indexDescriptor ).withId( schemaStore.nextId() ); IndexingService indexingService = getIndexingService( database );
indexingService.createIndexes( rule ); IndexProxy indexProxy = indexingService.getIndexProxy( forLabel( labelId, propertyKeyId ) );
IndexProxy indexProxy = indexingService.getIndexProxy( rule.getId() );


waitIndexOnline( indexProxy ); waitIndexOnline( indexProxy );
assertEquals( InternalIndexState.ONLINE, indexProxy.getState() ); assertEquals( InternalIndexState.ONLINE, indexProxy.getState() );
Expand All @@ -142,17 +142,21 @@ public void testManualIndexPopulation() throws IOException, IndexNotFoundKernelE
} }


@Test @Test
public void testManualRelationshipIndexPopulation() throws IOException, IndexNotFoundKernelException, InterruptedException public void testManualRelationshipIndexPopulation() throws Exception
{ {
IndexingService indexingService = getIndexingService( database ); RelationTypeSchemaDescriptor descriptor;
SchemaStore schemaStore = getSchemaStore( database ); try ( org.neo4j.internal.kernel.api.Transaction tx =

((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency( Kernel.class ).beginTransaction( explicit, AUTH_DISABLED ) )
int foodId = getRelationshipTypeId( FOOD_LABEL ); {
int propertyId = getPropertyKeyId( PROPERTY_NAME ); int foodId = tx.tokenWrite().relationshipTypeGetOrCreateForName( FOOD_LABEL );
int propertyId = tx.tokenWrite().propertyKeyGetOrCreateForName( PROPERTY_NAME );
descriptor = forRelType( foodId, propertyId );
tx.schemaWrite().indexCreate( descriptor );
tx.success();
}


StoreIndexDescriptor rule = forSchema( forRelType( foodId, propertyId ), indexDescriptor ).withId( schemaStore.nextId() ); IndexingService indexingService = getIndexingService( database );
indexingService.createIndexes( rule ); IndexProxy indexProxy = indexingService.getIndexProxy( descriptor );
IndexProxy indexProxy = indexingService.getIndexProxy( rule.getId() );


waitIndexOnline( indexProxy ); waitIndexOnline( indexProxy );
assertEquals( InternalIndexState.ONLINE, indexProxy.getState() ); assertEquals( InternalIndexState.ONLINE, indexProxy.getState() );
Expand Down Expand Up @@ -232,13 +236,6 @@ private void waitIndexOnline( IndexProxy indexProxy ) throws InterruptedExceptio
} }
} }


private SchemaStore getSchemaStore( GraphDatabaseService database )
{
NeoStores neoStores = getDependencyResolver( database )
.resolveDependency( RecordStorageEngine.class ).testAccessNeoStores();
return neoStores.getSchemaStore();
}

private IndexingService getIndexingService( GraphDatabaseService database ) private IndexingService getIndexingService( GraphDatabaseService database )
{ {
return getDependencyResolver(database).resolveDependency( IndexingService.class ); return getDependencyResolver(database).resolveDependency( IndexingService.class );
Expand Down Expand Up @@ -286,14 +283,4 @@ private int getLabelId( String name )
return transaction.tokenRead().nodeLabel( name ); return transaction.tokenRead().nodeLabel( name );
} }
} }

private int getRelationshipTypeId( String name )
{
try ( Transaction tx = database.beginTx() )
{
KernelTransaction transaction = ((GraphDatabaseAPI) database).getDependencyResolver().resolveDependency(
ThreadToStatementContextBridge.class ).getKernelTransactionBoundToThisThread( true );
return transaction.tokenRead().relationshipType( name );
}
}
} }

0 comments on commit 0927a24

Please sign in to comment.