Search in sources :

Example 6 with GraphDatabaseQueryService

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

the class ConcurrentTransactionAccessTest method shouldThrowSpecificExceptionOnConcurrentTransactionAccess.

@Test
public void shouldThrowSpecificExceptionOnConcurrentTransactionAccess() throws Exception {
    // given
    TransactionRegistry registry = new TransactionHandleRegistry(mock(Clock.class), 0, NullLogProvider.getInstance());
    TransitionalPeriodTransactionMessContainer kernel = mock(TransitionalPeriodTransactionMessContainer.class);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    when(kernel.newTransaction(any(KernelTransaction.Type.class), any(SecurityContext.class), anyLong())).thenReturn(mock(TransitionalTxManagementKernelTransaction.class));
    TransactionFacade actions = new TransactionFacade(kernel, null, queryService, registry, NullLogProvider.getInstance());
    final TransactionHandle transactionHandle = actions.newTransactionHandle(new DisgustingUriScheme(), true, SecurityContext.AUTH_DISABLED, -1);
    final DoubleLatch latch = new DoubleLatch();
    final StatementDeserializer statements = mock(StatementDeserializer.class);
    when(statements.hasNext()).thenAnswer(invocation -> {
        latch.startAndWaitForAllToStartAndFinish();
        return false;
    });
    new Thread(() -> {
        // start and block until finish
        transactionHandle.execute(statements, mock(ExecutionResultSerializer.class), mock(HttpServletRequest.class));
    }).start();
    latch.waitForAllToStart();
    try {
        // when
        actions.findTransactionHandle(DisgustingUriScheme.parseTxId(transactionHandle.uri()));
        fail("should have thrown exception");
    } catch (InvalidConcurrentTransactionAccess neo4jError) {
    // then we get here
    } finally {
        latch.finish();
    }
}
Also used : InvalidConcurrentTransactionAccess(org.neo4j.server.rest.transactional.error.InvalidConcurrentTransactionAccess) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Clock(java.time.Clock) SecurityContext(org.neo4j.kernel.api.security.SecurityContext) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 7 with GraphDatabaseQueryService

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

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

Example 9 with GraphDatabaseQueryService

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

the class TransactionHandleTest method startTransactionWithRequestedTimeout.

@Test
public void startTransactionWithRequestedTimeout() {
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    TransitionalPeriodTransactionMessContainer txManagerFacade = mockKernel();
    TransactionHandle handle = new TransactionHandle(txManagerFacade, executionEngine, queryService, mock(TransactionRegistry.class), uriScheme, true, AUTH_DISABLED, 100, NullLogProvider.getInstance());
    handle.commit(statements(new Statement("query", map(), false, (ResultDataContent[]) null)), output, mock(HttpServletRequest.class));
    verify(txManagerFacade).newTransaction(Type.implicit, AUTH_DISABLED, 100);
}
Also used : QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) HttpServletRequest(javax.servlet.http.HttpServletRequest) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Test(org.junit.Test)

Example 10 with GraphDatabaseQueryService

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

the class TransactionHandleTest method shouldHandleExecutionEngineThrowingUndeclaredCheckedExceptions.

@Test
public void shouldHandleExecutionEngineThrowingUndeclaredCheckedExceptions() throws Exception {
    // given
    QueryExecutionEngine executionEngine = mock(QueryExecutionEngine.class);
    when(executionEngine.executeQuery(eq("match (n) return n"), eq(map()), any(TransactionalContext.class))).thenAnswer(invocationOnMock -> {
        throw new Exception("BOO");
    });
    TransactionRegistry registry = mock(TransactionRegistry.class);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    GraphDatabaseQueryService queryService = mock(GraphDatabaseQueryService.class);
    TransactionHandle handle = new TransactionHandle(mockKernel(), executionEngine, queryService, registry, uriScheme, false, AUTH_DISABLED, anyLong(), NullLogProvider.getInstance());
    ExecutionResultSerializer output = mock(ExecutionResultSerializer.class);
    // when
    Statement statement = new Statement("match (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.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) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) TransactionalContext(org.neo4j.kernel.impl.query.TransactionalContext) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) SyntaxException(org.neo4j.cypher.SyntaxException) 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