Search in sources :

Example 16 with TransactionalContext

use of org.neo4j.kernel.impl.query.TransactionalContext 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 17 with TransactionalContext

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

the class TransactionHandleTest method prepareKernelWithQuerySession.

private TransactionalContext prepareKernelWithQuerySession(TransitionalPeriodTransactionMessContainer kernel) {
    TransactionalContext tc = mock(TransactionalContext.class);
    when(kernel.create(any(HttpServletRequest.class), any(GraphDatabaseQueryService.class), any(Type.class), any(SecurityContext.class), any(String.class), any(Map.class))).thenReturn(tc);
    return tc;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Type(org.neo4j.kernel.api.KernelTransaction.Type) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap)

Example 18 with TransactionalContext

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);
}
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 19 with TransactionalContext

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

Example 20 with TransactionalContext

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);
}
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) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Aggregations

TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)20 Result (org.neo4j.graphdb.Result)16 Test (org.junit.Test)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)10 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)10 InOrder (org.mockito.InOrder)9 Notification (org.neo4j.graphdb.Notification)7 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)5 QueryStatistics (org.neo4j.graphdb.QueryStatistics)4 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)3 Map (java.util.Map)2 Matchers.anyString (org.mockito.Matchers.anyString)2 CypherException (org.neo4j.cypher.CypherException)2 SyntaxException (org.neo4j.cypher.SyntaxException)2 Type (org.neo4j.kernel.api.KernelTransaction.Type)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2