Search in sources :

Example 1 with TransactionalContext

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

the class TransactionHandleTest method shouldRollbackTransactionIfExecutionErrorOccurs.

@Test
public void shouldRollbackTransactionIfExecutionErrorOccurs() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(executionEngine.executeQuery("query", map(), transactionalContext)).thenThrow(new NullPointerException());
    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(transactionContext).rollback();
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).transactionCommitUri(uriScheme.txCommitUri(1337));
    outputOrder.verify(output).errors(argThat(hasErrors(Status.Statement.ExecutionFailed)));
    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) Test(org.junit.Test)

Example 2 with TransactionalContext

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

the class TransactionHandleTest method shouldSuspendTransactionAndReleaseForOtherRequestsAfterExecutingStatements.

@Test
public void shouldSuspendTransactionAndReleaseForOtherRequestsAfterExecutingStatements() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    Result executionResult = mock(Result.class);
    when(executionEngine.executeQuery("query", map(), transactionalContext)).thenReturn(executionResult);
    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
    InOrder transactionOrder = inOrder(transactionContext, registry);
    transactionOrder.verify(transactionContext).suspendSinceTransactionsAreStillThreadBound();
    transactionOrder.verify(registry).release(1337L, handle);
    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) 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 3 with TransactionalContext

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

the class TransactionHandleTest method shouldResumeTransactionWhenExecutingStatementsOnSecondRequest.

@Test
public void shouldResumeTransactionWhenExecutingStatementsOnSecondRequest() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(kernel, executionEngine, registry);
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    reset(transactionContext, registry, executionEngine, output);
    Result executionResult = mock(Result.class);
    when(executionEngine.executeQuery("query", map(), transactionalContext)).thenReturn(executionResult);
    // when
    handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    // then
    InOrder order = inOrder(transactionContext, registry, executionEngine);
    order.verify(transactionContext).resumeSinceTransactionsAreStillThreadBound();
    order.verify(executionEngine).executeQuery("query", map(), transactionalContext);
    order.verify(transactionContext).suspendSinceTransactionsAreStillThreadBound();
    order.verify(registry).release(1337L, handle);
    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) 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 4 with TransactionalContext

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

the class TransactionHandleTest method shouldLogMessageIfCommitErrorOccurs.

@Test
public void shouldLogMessageIfCommitErrorOccurs() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
    doThrow(new NullPointerException()).when(transactionContext).commit();
    LogProvider logProvider = mock(LogProvider.class);
    Log log = mock(Log.class);
    when(logProvider.getLog(TransactionHandle.class)).thenReturn(log);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    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, false, AUTH_DISABLED, anyLong(), logProvider);
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    Statement statement = new Statement("query", map(), false, (ResultDataContent[]) null);
    handle.commit(statements(statement), output, mock(HttpServletRequest.class));
    // then
    verify(log).error(eq("Failed to commit transaction."), any(NullPointerException.class));
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).statementResult(executionResult, false, (ResultDataContent[]) null);
    outputOrder.verify(output).notifications(anyCollectionOf(Notification.class));
    outputOrder.verify(output).errors(argThat(hasErrors(Status.Transaction.TransactionCommitFailed)));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : InOrder(org.mockito.InOrder) Log(org.neo4j.logging.Log) 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) LogProvider(org.neo4j.logging.LogProvider) NullLogProvider(org.neo4j.logging.NullLogProvider) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 5 with TransactionalContext

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

the class TransactionHandleTest method shouldLogMessageIfCypherSyntaxErrorOccurs.

@Test
public void shouldLogMessageIfCypherSyntaxErrorOccurs() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    TransactionalContext transactionalContext = prepareKernelWithQuerySession(kernel);
    when(executionEngine.executeQuery("matsch (n) return n", map(), transactionalContext)).thenThrow(new QueryExecutionKernelException(new SyntaxException("did you mean MATCH?")));
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(kernel, executionEngine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    Statement statement = new Statement("matsch (n) return n", map(), false, (ResultDataContent[]) null);
    handle.commit(statements(statement), output, mock(HttpServletRequest.class));
    // then
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).errors(argThat(hasErrors(Status.Statement.SyntaxError)));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) InOrder(org.mockito.InOrder) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) SyntaxException(org.neo4j.cypher.SyntaxException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Aggregations

TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)26 Result (org.neo4j.graphdb.Result)17 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)7 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)6 BoltResult (org.neo4j.bolt.v1.runtime.spi.BoltResult)5 QueryStatistics (org.neo4j.graphdb.QueryStatistics)5 QueryExecution (org.neo4j.kernel.impl.query.QueryExecution)4 Test (org.junit.jupiter.api.Test)3 NullLogProvider (org.neo4j.logging.NullLogProvider)3 Map (java.util.Map)2 Matchers.anyString (org.mockito.Matchers.anyString)2 Config (org.neo4j.configuration.Config)2 CypherException (org.neo4j.cypher.CypherException)2 SyntaxException (org.neo4j.cypher.SyntaxException)2 CompilerFactory (org.neo4j.cypher.internal.CompilerFactory)2