Search in sources :

Example 16 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 17 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)

Example 18 with GraphDatabaseQueryService

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

the class TransactionStateMachineSPIProviderV4Test method managementService.

private DatabaseManagementService managementService(String databaseName) {
    DatabaseManagementService managementService = mock(DatabaseManagementService.class);
    GraphDatabaseFacade databaseFacade = mock(GraphDatabaseFacade.class);
    final DependencyResolver dependencyResolver = mock(DependencyResolver.class);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(databaseFacade.isAvailable(anyLong())).thenReturn(true);
    when(managementService.database(databaseName)).thenReturn(databaseFacade);
    when(databaseFacade.getDependencyResolver()).thenReturn(dependencyResolver);
    when(dependencyResolver.resolveDependency(GraphDatabaseQueryService.class)).thenReturn(queryService);
    when(dependencyResolver.resolveDependency(Database.class)).thenReturn(mock(Database.class));
    when(queryService.getDependencyResolver()).thenReturn(dependencyResolver);
    return managementService;
}
Also used : GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Database(org.neo4j.kernel.database.Database) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) DependencyResolver(org.neo4j.common.DependencyResolver)

Aggregations

GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)18 Test (org.junit.Test)10 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.common.DependencyResolver)3 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)3 DependencyResolver (org.neo4j.graphdb.DependencyResolver)3 Notification (org.neo4j.graphdb.Notification)3 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)3 Test (org.junit.jupiter.api.Test)2 SyntaxException (org.neo4j.cypher.SyntaxException)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)2 SecurityContext (org.neo4j.kernel.api.security.SecurityContext)2 Database (org.neo4j.kernel.database.Database)2 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)2