Search in sources :

Example 21 with Statement

use of org.neo4j.server.http.cypher.format.api.Statement in project neo4j by neo4j.

the class InvocationTest method shouldSuspendTransactionAndReleaseForOtherRequestsAfterExecutingStatements.

@Test
void shouldSuspendTransactionAndReleaseForOtherRequestsAfterExecutingStatements() {
    // given
    when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(executionEngine, registry);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    Statement statement = new Statement("query", map());
    when(inputEventStream.read()).thenReturn(statement, NULL_STATEMENT);
    mockDefaultResult();
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, false);
    // when
    invocation.execute(outputEventStream);
    // then
    InOrder transactionOrder = inOrder(transactionContext, registry);
    transactionOrder.verify(registry).release(1337L, handle);
    verify(internalTransaction).execute("query", emptyMap());
    InOrder outputOrder = inOrder(outputEventStream);
    outputOrder.verify(outputEventStream).writeStatementStart(statement, List.of("c1", "c2", "c3"));
    verifyDefaultResultRows(outputOrder);
    outputOrder.verify(outputEventStream).writeStatementEnd(queryExecutionType, queryStatistics, executionPlanDescription, notifications);
    outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.OPEN, uriScheme.txCommitUri(1337L), 0);
    verifyNoMoreInteractions(outputEventStream);
}
Also used : InOrder(org.mockito.InOrder) InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) Statement(org.neo4j.server.http.cypher.format.api.Statement) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Aggregations

Statement (org.neo4j.server.http.cypher.format.api.Statement)21 Test (org.junit.jupiter.api.Test)19 InputEventStream (org.neo4j.server.http.cypher.format.api.InputEventStream)18 MemoryPool (org.neo4j.memory.MemoryPool)17 InOrder (org.mockito.InOrder)16 ConnectionException (org.neo4j.server.http.cypher.format.api.ConnectionException)4 IOException (java.io.IOException)3 AuthorizationViolationException (org.neo4j.graphdb.security.AuthorizationViolationException)2 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)2 DeadlockDetectedException (org.neo4j.kernel.DeadlockDetectedException)2 Log (org.neo4j.logging.Log)2 HashMap (java.util.HashMap)1 TimeUnit (java.util.concurrent.TimeUnit)1 InvalidSemanticsException (org.neo4j.exceptions.InvalidSemanticsException)1 KernelException (org.neo4j.exceptions.KernelException)1 Neo4jException (org.neo4j.exceptions.Neo4jException)1 SyntaxException (org.neo4j.exceptions.SyntaxException)1 QueryExecutionType (org.neo4j.graphdb.QueryExecutionType)1 WriteOperationsNotAllowedException (org.neo4j.graphdb.WriteOperationsNotAllowedException)1 ClientConnectionInfo (org.neo4j.internal.kernel.api.connectioninfo.ClientConnectionInfo)1