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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations