Search in sources :

Example 1 with InputEventStream

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

the class InvocationTest method deadlockExceptionHasCorrectStatus.

@Test
void deadlockExceptionHasCorrectStatus() {
    // given
    when(internalTransaction.execute("query", emptyMap())).thenThrow(new DeadlockDetectedException("deadlock"));
    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);
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // when
    invocation.execute(outputEventStream);
    // then
    verify(internalTransaction).rollback();
    verify(registry).forget(1337L);
    InOrder outputOrder = inOrder(outputEventStream);
    outputOrder.verify(outputEventStream).writeFailure(Status.Transaction.DeadlockDetected, "deadlock");
    outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.ROLLED_BACK, uriScheme.txCommitUri(1337L), -1);
    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) DeadlockDetectedException(org.neo4j.kernel.DeadlockDetectedException) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Example 2 with InputEventStream

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

the class InvocationTest method shouldExecuteStatements.

@Test
void shouldExecuteStatements() {
    // 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, true);
    // when
    invocation.execute(outputEventStream);
    // then
    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.COMMITTED, uriScheme.txCommitUri(1337L), -1);
    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)

Example 3 with InputEventStream

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

the class InvocationTest method shouldKeepTransactionOpenIfConnectionErrorWhenReadingStatementsInExplicitTransaction.

@Test
void shouldKeepTransactionOpenIfConnectionErrorWhenReadingStatementsInExplicitTransaction() {
    // given
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    TransactionHandle handle = getTransactionHandle(executionEngine, registry, false);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    when(inputEventStream.read()).thenThrow(new ConnectionException("Connection error", new IOException("Broken pipe")));
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // when
    var e = assertThrows(ConnectionException.class, () -> invocation.execute(outputEventStream));
    assertEquals("Connection error", e.getMessage());
    // then
    verify(transactionContext, never()).rollback();
    verify(transactionContext, never()).commit();
    verify(registry, never()).forget(1337L);
    verifyNoInteractions(outputEventStream);
}
Also used : InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) IOException(java.io.IOException) ConnectionException(org.neo4j.server.http.cypher.format.api.ConnectionException) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Example 4 with InputEventStream

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

the class InvocationTest method startTransactionWithRequestedTimeout.

@Test
void startTransactionWithRequestedTimeout() {
    // given
    TransactionHandle handle = new TransactionHandle(databaseFacade, executionEngine, mock(TransactionRegistry.class), uriScheme, true, AUTH_DISABLED, EMBEDDED_CONNECTION, 100);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    when(inputEventStream.read()).thenReturn(null);
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // when
    invocation.execute(outputEventStream);
    // then
    verify(databaseFacade).beginTransaction(IMPLICIT, AUTH_DISABLED, EMBEDDED_CONNECTION, 100, TimeUnit.MILLISECONDS);
}
Also used : InputEventStream(org.neo4j.server.http.cypher.format.api.InputEventStream) MemoryPool(org.neo4j.memory.MemoryPool) Test(org.junit.jupiter.api.Test)

Example 5 with InputEventStream

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

the class InvocationTest method shouldCreateTransactionContextOnlyWhenFirstNeeded.

@Test
void shouldCreateTransactionContextOnlyWhenFirstNeeded() {
    // given
    when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
    when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
    InputEventStream inputEventStream = mock(InputEventStream.class);
    Statement statement = new Statement("query", map());
    when(inputEventStream.read()).thenReturn(statement, NULL_STATEMENT);
    mockDefaultResult();
    // when
    TransactionHandle handle = getTransactionHandle(executionEngine, registry);
    Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
    // then
    verifyNoInteractions(databaseFacade);
    // when
    invocation.execute(outputEventStream);
    // then
    verify(databaseFacade).beginTransaction(any(KernelTransaction.Type.class), any(LoginContext.class), eq(EMBEDDED_CONNECTION));
    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.COMMITTED, uriScheme.txCommitUri(1337L), -1);
    verifyNoMoreInteractions(outputEventStream);
}
Also used : QueryExecutionType(org.neo4j.graphdb.QueryExecutionType) LoginContext(org.neo4j.internal.kernel.api.security.LoginContext) 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

InputEventStream (org.neo4j.server.http.cypher.format.api.InputEventStream)25 MemoryPool (org.neo4j.memory.MemoryPool)24 Test (org.junit.jupiter.api.Test)21 Statement (org.neo4j.server.http.cypher.format.api.Statement)18 InOrder (org.mockito.InOrder)17 IOException (java.io.IOException)5 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)5 ConnectionException (org.neo4j.server.http.cypher.format.api.ConnectionException)4 URI (java.net.URI)3 Collections.emptyMap (java.util.Collections.emptyMap)3 Map (java.util.Map)3 Objects.requireNonNullElse (java.util.Objects.requireNonNullElse)3 Optional (java.util.Optional)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 DELETE (javax.ws.rs.DELETE)3 POST (javax.ws.rs.POST)3 Path (javax.ws.rs.Path)3 PathParam (javax.ws.rs.PathParam)3 Context (javax.ws.rs.core.Context)3 HttpHeaders (javax.ws.rs.core.HttpHeaders)3