use of org.neo4j.server.http.cypher.format.api.ConnectionException in project neo4j by neo4j.
the class InvocationTest method shouldKeepTransactionOpenIfConnectionErrorWhenWritingOutputInImplicitTransaction.
@Test
void shouldKeepTransactionOpenIfConnectionErrorWhenWritingOutputInImplicitTransaction() {
// given
when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
TransactionHandle handle = getTransactionHandle(executionEngine, registry, false);
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);
doThrow(new ConnectionException("Connection error", new IOException("Broken pipe"))).when(outputEventStream).writeStatementEnd(any(), any(), any(), any());
// when
var e = assertThrows(ConnectionException.class, () -> invocation.execute(outputEventStream));
assertEquals("Connection error", e.getMessage());
// then
verify(internalTransaction, never()).rollback();
verify(registry, never()).forget(1337L);
InOrder outputOrder = inOrder(outputEventStream);
outputOrder.verify(outputEventStream).writeStatementStart(statement, List.of("c1", "c2", "c3"));
verifyDefaultResultRows(outputOrder);
outputOrder.verify(outputEventStream).writeStatementEnd(queryExecutionType, queryStatistics, executionPlanDescription, notifications);
verifyNoMoreInteractions(outputEventStream);
}
Aggregations