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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations