Search in sources :

Example 51 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class ExtensionInitializer method initializePackages.

public Collection<Injectable<?>> initializePackages(Iterable<String> packageNames) {
    GraphDatabaseAPI graphDatabaseService = neoServer.getDatabase().getGraph();
    Config configuration = neoServer.getConfig();
    Collection<Injectable<?>> injectables = new HashSet<>();
    for (PluginLifecycle lifecycle : lifecycles) {
        if (hasPackage(lifecycle, packageNames)) {
            if (lifecycle instanceof SPIPluginLifecycle) {
                SPIPluginLifecycle lifeCycleSpi = (SPIPluginLifecycle) lifecycle;
                injectables.addAll(lifeCycleSpi.start(neoServer));
            } else {
                injectables.addAll(lifecycle.start(graphDatabaseService, new ConfigAdapter(configuration)));
            }
        }
    }
    return injectables;
}
Also used : Injectable(org.neo4j.server.plugins.Injectable) SPIPluginLifecycle(org.neo4j.server.plugins.SPIPluginLifecycle) PluginLifecycle(org.neo4j.server.plugins.PluginLifecycle) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) ConfigAdapter(org.neo4j.server.plugins.ConfigAdapter) Config(org.neo4j.kernel.configuration.Config) SPIPluginLifecycle(org.neo4j.server.plugins.SPIPluginLifecycle) HashSet(java.util.HashSet)

Example 52 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class ProcedureIT method shouldNotBeAbleToCallSchemaProcedureThroughWriteProcedureInWriteTransaction.

@Test
public void shouldNotBeAbleToCallSchemaProcedureThroughWriteProcedureInWriteTransaction() throws Throwable {
    // Expect
    exception.expect(QueryExecutionException.class);
    exception.expectMessage("Schema operations are not allowed");
    GraphDatabaseAPI gdapi = (GraphDatabaseAPI) db;
    // When
    try (Transaction tx = gdapi.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.write())) {
        db.execute("CALL org.neo4j.procedure.writeProcedureCallingSchemaProcedure").next();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 53 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class ProcedureIT method shouldNotAllowSchemaWriteProcedureInWriteTransaction.

@Test
public void shouldNotAllowSchemaWriteProcedureInWriteTransaction() throws Throwable {
    // Expect
    exception.expect(AuthorizationViolationException.class);
    exception.expectMessage("Schema operations are not allowed");
    GraphDatabaseAPI gdapi = (GraphDatabaseAPI) db;
    // When
    try (Transaction tx = gdapi.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.write())) {
        db.execute("CALL org.neo4j.procedure.schemaProcedure()");
        tx.success();
    }
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Test(org.junit.Test)

Example 54 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BoltFactoryImplTest method txIdStoreRefreshedAfterRestart.

@Test
public void txIdStoreRefreshedAfterRestart() throws Throwable {
    GraphDatabaseAPI db = newDbMock();
    DependencyResolver dependencyResolver = db.getDependencyResolver();
    TransactionIdStore txIdStoreBeforeRestart = mock(TransactionIdStore.class);
    when(txIdStoreBeforeRestart.getLastClosedTransactionId()).thenReturn(42L);
    TransactionIdStore txIdStoreAfterRestart = mock(TransactionIdStore.class);
    when(txIdStoreAfterRestart.getLastClosedTransactionId()).thenReturn(4242L);
    when(dependencyResolver.resolveDependency(TransactionIdStore.class)).thenReturn(txIdStoreBeforeRestart).thenReturn(txIdStoreAfterRestart);
    BoltFactoryImpl boltFactory = newBoltFactory(db);
    boltFactory.start();
    BoltStateMachine stateMachine1 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
    assertEquals(42, stateMachine1.spi.transactionSpi().newestEncounteredTxId());
    boltFactory.stop();
    boltFactory.start();
    BoltStateMachine stateMachine2 = boltFactory.newMachine(CONNECTION_DESCRIPTOR, mock(Runnable.class), CLOCK);
    assertEquals(4242, stateMachine2.spi.transactionSpi().newestEncounteredTxId());
}
Also used : TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) DependencyResolver(org.neo4j.graphdb.DependencyResolver) Test(org.junit.Test)

Example 55 with GraphDatabaseAPI

use of org.neo4j.kernel.internal.GraphDatabaseAPI in project neo4j by neo4j.

the class BoltFactoryImplTest method newDbMock.

private static GraphDatabaseAPI newDbMock() {
    GraphDatabaseAPI db = mock(GraphDatabaseAPI.class);
    DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    when(db.getDependencyResolver()).thenReturn(dependencyResolver);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(queryService.getDependencyResolver()).thenReturn(dependencyResolver);
    when(dependencyResolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    return db;
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Aggregations

GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)262 Test (org.junit.Test)91 Test (org.junit.jupiter.api.Test)88 Transaction (org.neo4j.graphdb.Transaction)87 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)61 Node (org.neo4j.graphdb.Node)38 Path (java.nio.file.Path)30 TestDatabaseManagementServiceBuilder (org.neo4j.test.TestDatabaseManagementServiceBuilder)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)26 File (java.io.File)25 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)24 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)18 DependencyResolver (org.neo4j.graphdb.DependencyResolver)17 Label (org.neo4j.graphdb.Label)15 PageCache (org.neo4j.io.pagecache.PageCache)15 Config (org.neo4j.kernel.configuration.Config)15 DatabaseStateService (org.neo4j.dbms.DatabaseStateService)14 IOException (java.io.IOException)11