Search in sources :

Example 16 with QueryExecutionEngine

use of org.neo4j.kernel.impl.query.QueryExecutionEngine in project neo4j by neo4j.

the class ServerExecutionEngineTest method shouldDetectPeriodicCommitQueries.

@Test
public void shouldDetectPeriodicCommitQueries() throws Exception {
    // GIVEN
    QueryExecutionEngine engine = rule.getGraphDatabaseAPI().getDependencyResolver().resolveDependency(QueryExecutionEngine.class);
    // WHEN
    boolean result = engine.isPeriodicCommit("USING PERIODIC COMMIT LOAD CSV FROM 'file:///tmp/foo.csv' AS line CREATE ()");
    // THEN
    assertTrue("Did not detect periodic commit query", result);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) Test(org.junit.Test)

Example 17 with QueryExecutionEngine

use of org.neo4j.kernel.impl.query.QueryExecutionEngine in project neo4j by neo4j.

the class GraphDatabaseFacadeFactory method initFacade.

/**
     * Instantiate a graph database given configuration, dependencies, and a custom implementation of {@link org
     * .neo4j.kernel.impl.factory.GraphDatabaseFacade}.
     *
     * @param storeDir the directory where the Neo4j data store is located
     * @param config configuration
     * @param dependencies the dependencies required to construct the {@link GraphDatabaseFacade}
     * @param graphDatabaseFacade the already created facade which needs initialisation
     * @return the initialised {@link GraphDatabaseFacade}
     */
public GraphDatabaseFacade initFacade(File storeDir, Config config, final Dependencies dependencies, final GraphDatabaseFacade graphDatabaseFacade) {
    PlatformModule platform = createPlatform(storeDir, config, dependencies, graphDatabaseFacade);
    EditionModule edition = editionFactory.apply(platform);
    AtomicReference<QueryExecutionEngine> queryEngine = new AtomicReference<>(noEngine());
    final DataSourceModule dataSource = createDataSource(platform, edition, queryEngine::get);
    Logger msgLog = platform.logging.getInternalLog(getClass()).infoLogger();
    CoreAPIAvailabilityGuard coreAPIAvailabilityGuard = edition.coreAPIAvailabilityGuard;
    ClassicCoreSPI spi = new ClassicCoreSPI(platform, dataSource, msgLog, coreAPIAvailabilityGuard);
    graphDatabaseFacade.init(spi, dataSource.guard, dataSource.threadToTransactionBridge, platform.config);
    // Start it
    platform.dataSourceManager.addListener(new DataSourceManager.Listener() {

        private QueryExecutionEngine engine;

        @Override
        public void registered(NeoStoreDataSource dataSource) {
            if (engine == null) {
                engine = QueryEngineProvider.initialize(platform.dependencies, platform.graphDatabaseFacade, dependencies.executionEngines());
            }
            queryEngine.set(engine);
        }

        @Override
        public void unregistered(NeoStoreDataSource dataSource) {
            queryEngine.set(noEngine());
        }
    });
    Throwable error = null;
    try {
        // Done after create to avoid a redundant
        // "database is now unavailable"
        enableAvailabilityLogging(platform.availabilityGuard, msgLog);
        platform.life.start();
    } catch (final Throwable throwable) {
        error = new RuntimeException("Error starting " + getClass().getName() + ", " + platform.storeDir, throwable);
    } finally {
        if (error != null) {
            try {
                graphDatabaseFacade.shutdown();
            } catch (Throwable shutdownError) {
                error = Exceptions.withSuppressed(shutdownError, error);
            }
        }
    }
    if (error != null) {
        msgLog.log("Failed to start database", error);
        throw Exceptions.launderedException(error);
    }
    return graphDatabaseFacade;
}
Also used : NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) Logger(org.neo4j.logging.Logger) DataSourceManager(org.neo4j.kernel.impl.transaction.state.DataSourceManager) CoreAPIAvailabilityGuard(org.neo4j.kernel.impl.coreapi.CoreAPIAvailabilityGuard) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine)

Example 18 with QueryExecutionEngine

use of org.neo4j.kernel.impl.query.QueryExecutionEngine in project neo4j by neo4j.

the class TransactionHandleTest method shouldCreateTransactionContextOnlyWhenFirstNeeded.

@Test
public void shouldCreateTransactionContextOnlyWhenFirstNeeded() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    // when
    QueryExecutionEngine engine = mock(QueryExecutionEngine.class);
    Result executionResult = mock(Result.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(engine.executeQuery("query", map(), transactionalContext)).thenReturn(executionResult);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(kernel, engine, queryService, registry, uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    // then
    verifyZeroInteractions(kernel);
    // when
    handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    // then
    verify(kernel).newTransaction(any(Type.class), any(SecurityContext.class), anyLong());
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).transactionCommitUri(uriScheme.txCommitUri(1337));
    outputOrder.verify(output).statementResult(executionResult, false, (ResultDataContent[]) null);
    outputOrder.verify(output).notifications(anyCollectionOf(Notification.class));
    outputOrder.verify(output).transactionStatus(anyLong());
    outputOrder.verify(output).errors(argThat(hasNoErrors()));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : InOrder(org.mockito.InOrder) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Notification(org.neo4j.graphdb.Notification) Result(org.neo4j.graphdb.Result) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) Type(org.neo4j.kernel.api.KernelTransaction.Type) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 19 with QueryExecutionEngine

use of org.neo4j.kernel.impl.query.QueryExecutionEngine in project neo4j by neo4j.

the class TransactionHandleTest method shouldCommitSinglePeriodicCommitStatement.

@Test
public void shouldCommitSinglePeriodicCommitStatement() throws Exception {
    // given
    String queryText = "USING PERIODIC COMMIT CREATE()";
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    Result executionResult = mock(Result.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(executionEngine.isPeriodicCommit(queryText)).thenReturn(true);
    when(executionEngine.executeQuery(eq(queryText), eq(map()), eq(transactionalContext))).thenReturn(executionResult);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(kernel, executionEngine, registry);
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    Statement statement = new Statement(queryText, map(), false, (ResultDataContent[]) null);
    // when
    handle.commit(statements(statement), output, mock(HttpServletRequest.class));
    // then
    verify(executionEngine).executeQuery(queryText, map(), transactionalContext);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).statementResult(executionResult, false, (ResultDataContent[]) null);
    outputOrder.verify(output).notifications(anyCollectionOf(Notification.class));
    outputOrder.verify(output).errors(argThat(hasNoErrors()));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : InOrder(org.mockito.InOrder) Matchers.anyString(org.mockito.Matchers.anyString) Notification(org.neo4j.graphdb.Notification) Result(org.neo4j.graphdb.Result) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 20 with QueryExecutionEngine

use of org.neo4j.kernel.impl.query.QueryExecutionEngine in project neo4j by neo4j.

the class TransactionHandleTest method shouldExecuteStatements.

@Test
public void shouldExecuteStatements() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    Result executionResult = mock(Result.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(executionEngine.executeQuery("query", map(), transactionalContext)).thenReturn(executionResult);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(kernel, executionEngine, registry);
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    // then
    verify(executionEngine).executeQuery("query", map(), transactionalContext);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).transactionCommitUri(uriScheme.txCommitUri(1337));
    outputOrder.verify(output).statementResult(executionResult, false, (ResultDataContent[]) null);
    outputOrder.verify(output).notifications(anyCollectionOf(Notification.class));
    outputOrder.verify(output).transactionStatus(anyLong());
    outputOrder.verify(output).errors(argThat(hasNoErrors()));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) InOrder(org.mockito.InOrder) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Notification(org.neo4j.graphdb.Notification) Result(org.neo4j.graphdb.Result) Test(org.junit.Test)

Aggregations

QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)21 Test (org.junit.Test)16 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)12 InOrder (org.mockito.InOrder)10 Result (org.neo4j.graphdb.Result)8 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)8 Notification (org.neo4j.graphdb.Notification)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 LogProvider (org.neo4j.logging.LogProvider)3 SyntaxException (org.neo4j.cypher.SyntaxException)2 CommunityCompatibilityFactory (org.neo4j.cypher.internal.CommunityCompatibilityFactory)2 GraphDatabaseCypherService (org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 KernelAPI (org.neo4j.kernel.api.KernelAPI)2 Type (org.neo4j.kernel.api.KernelTransaction.Type)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 LogService (org.neo4j.kernel.impl.logging.LogService)2 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)2 Monitors (org.neo4j.kernel.monitoring.Monitors)2