Search in sources :

Example 11 with GraphDatabaseQueryService

use of org.neo4j.kernel.GraphDatabaseQueryService in project neo4j by neo4j.

the class TransactionHandleTest method deadlockExceptionHasCorrectStatus.

@Test
@SuppressWarnings("unchecked")
public void deadlockExceptionHasCorrectStatus() throws Exception {
    // given
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    when(executionEngine.executeQuery(anyString(), anyMap(), any(TransactionalContext.class))).thenThrow(new DeadlockDetectedException("deadlock"));
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(mockKernel(), executionEngine, queryService, mock(TransactionRegistry.class), uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    handle.execute(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    // then
    verify(output).errors(argThat(hasErrors(Status.Transaction.DeadlockDetected)));
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) Test(org.junit.Test)

Example 12 with GraphDatabaseQueryService

use of org.neo4j.kernel.GraphDatabaseQueryService in project neo4j by neo4j.

the class TransactionStateMachineSPITest method createTxSpi.

private static TransactionStateMachineSPI createTxSpi(TransactionIdStore txIdStore, Duration txAwaitDuration, AvailabilityGuard availabilityGuard, Clock clock) {
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(queryService.getDependencyResolver()).thenReturn(mock(DependencyResolver.class));
    return new TransactionStateMachineSPI(mock(GraphDatabaseAPI.class), new ThreadToStatementContextBridge(), mock(QueryExecutionEngine.class), txIdStore, availabilityGuard, queryService, txAwaitDuration, clock);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) ThreadToStatementContextBridge(org.neo4j.kernel.impl.core.ThreadToStatementContextBridge) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Example 13 with GraphDatabaseQueryService

use of org.neo4j.kernel.GraphDatabaseQueryService 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 14 with GraphDatabaseQueryService

use of org.neo4j.kernel.GraphDatabaseQueryService in project neo4j by neo4j.

the class TransactionHandleTest method shouldRollbackTransactionAndTellRegistryToForgetItsHandle.

@Test
public void shouldRollbackTransactionAndTellRegistryToForgetItsHandle() throws Exception {
    // given
    TransitionalPeriodTransactionMessContainer kernel = mockKernel();
    TransitionalTxManagementKernelTransaction transactionContext = kernel.newTransaction(explicit, AUTH_DISABLED, -1);
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(kernel, mock(QueryExecutionEngine.class), queryService, registry, uriScheme, true, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    handle.rollback(output);
    // then
    InOrder transactionOrder = inOrder(transactionContext, registry);
    transactionOrder.verify(transactionContext).rollback();
    transactionOrder.verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(output);
    outputOrder.verify(output).errors(argThat(hasNoErrors()));
    outputOrder.verify(output).finish();
    verifyNoMoreInteractions(output);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) InOrder(org.mockito.InOrder) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Test(org.junit.Test)

Example 15 with GraphDatabaseQueryService

use of org.neo4j.kernel.GraphDatabaseQueryService 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

GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)15 Test (org.junit.Test)12 QueryExecutionEngine (org.neo4j.kernel.impl.query.QueryExecutionEngine)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 InOrder (org.mockito.InOrder)7 TransactionalContext (org.neo4j.kernel.impl.query.TransactionalContext)7 Result (org.neo4j.graphdb.Result)5 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)4 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 Notification (org.neo4j.graphdb.Notification)3 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)3 SyntaxException (org.neo4j.cypher.SyntaxException)2 GraphDatabaseCypherService (org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)2 PropertyContainerLocker (org.neo4j.kernel.impl.coreapi.PropertyContainerLocker)2 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2