use of org.neo4j.kernel.impl.query.TransactionalContext 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.TransactionalContext 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);
}
use of org.neo4j.kernel.impl.query.TransactionalContext in project neo4j by neo4j.
the class TransactionHandleTest method shouldCommitTransactionAndTellRegistryToForgetItsHandle.
@Test
public void shouldCommitTransactionAndTellRegistryToForgetItsHandle() throws Exception {
// given
TransitionalPeriodTransactionMessContainer kernel = mockKernel();
TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
TransactionRegistry registry = mock(TransactionRegistry.class);
QueryExecutionEngine engine = mock(QueryExecutionEngine.class);
TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
Result result = mock(Result.class);
when(engine.executeQuery("query", map(), transactionalContext)).thenReturn(result);
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
TransactionHandle handle = new TransactionHandle(kernel, engine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
// when
Statement statement = new Statement("query", map(), false, (ResultDataContent[]) null);
handle.commit(statements(statement), output, mock(HttpServletRequest.class));
// then
InOrder transactionOrder = inOrder(transactionContext, registry);
transactionOrder.verify(transactionContext).commit();
transactionOrder.verify(registry).forget(1337L);
InOrder outputOrder = inOrder(output);
outputOrder.verify(output).statementResult(result, 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.TransactionalContext in project neo4j by neo4j.
the class ServerExecutionEngineTest method shouldCloseResourcesInCancel.
@Test
void shouldCloseResourcesInCancel() throws Exception {
// GIVEN
TransactionalContextFactory contextFactory = Neo4jTransactionalContextFactory.create(() -> queryService, transactionFactory);
// We need two node vars to have one non-pooled cursor
String query = "MATCH (n), (m) WHERE true RETURN n, m, n.name, m.name";
try (InternalTransaction tx = db.beginTransaction(KernelTransaction.Type.EXPLICIT, AUTH_DISABLED)) {
tx.createNode();
tx.createNode();
TransactionalContext context = contextFactory.newContext(tx, query, MapValue.EMPTY);
QueryExecution execution = executionEngine.executeQuery(query, MapValue.EMPTY, context, false, DO_NOTHING_SUBSCRIBER);
execution.request(1);
// This should close all cursors
execution.cancel();
tx.commit();
}
}
use of org.neo4j.kernel.impl.query.TransactionalContext in project neo4j by neo4j.
the class BoltQueryExecutorImpl method executeQuery.
@Override
public BoltQueryExecution executeQuery(String query, MapValue parameters, boolean prePopulate, QuerySubscriber subscriber) throws QueryExecutionKernelException {
TransactionalContext transactionalContext = transactionalContextFactory.newContext(internalTransaction, query, parameters);
QueryExecution queryExecution = queryExecutionEngine.executeQuery(query, parameters, transactionalContext, prePopulate, subscriber);
return new BoltQueryExecutionImpl(queryExecution, transactionalContext);
}
Aggregations