use of org.neo4j.server.http.cypher.format.api.InputEventStream in project neo4j by neo4j.
the class InvocationTest method shouldHandleCypherSyntaxError.
@Test
void shouldHandleCypherSyntaxError() {
// given
String queryText = "matsch (n) return n";
when(internalTransaction.execute(queryText, emptyMap())).thenThrow(new RuntimeException(new SyntaxException("did you mean MATCH?")));
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
TransactionHandle handle = getTransactionHandle(executionEngine, registry);
InputEventStream inputEventStream = mock(InputEventStream.class);
Statement statement = new Statement(queryText, 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.Statement.SyntaxError, "did you mean MATCH?");
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 shouldHandleExecutionEngineThrowingUndeclaredCheckedExceptions.
@Test
void shouldHandleExecutionEngineThrowingUndeclaredCheckedExceptions() {
// given
when(internalTransaction.execute("query", emptyMap())).thenThrow(new RuntimeException("BOO"));
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.Statement.ExecutionFailed, "BOO");
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 shouldHandleCommitError.
@Test
void shouldHandleCommitError() {
// given
when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
doThrow(new IllegalStateException("Something went wrong")).when(internalTransaction).commit();
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());
verify(log).error(eq("Failed to commit transaction."), any(IllegalStateException.class));
verify(registry).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);
outputOrder.verify(outputEventStream).writeFailure(Status.Transaction.TransactionCommitFailed, "Something went wrong");
outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.UNKNOWN, 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 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);
}
use of org.neo4j.server.http.cypher.format.api.InputEventStream in project neo4j by neo4j.
the class InvocationTest method shouldHandleInputParsingErrorWhenReadingStatements.
@Test
void shouldHandleInputParsingErrorWhenReadingStatements() {
// given
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
TransactionHandle handle = getTransactionHandle(executionEngine, registry);
InputEventStream inputEventStream = mock(InputEventStream.class);
when(inputEventStream.read()).thenThrow(new InputFormatException("Cannot parse input", new IOException("JSON ERROR")));
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.Request.InvalidFormat, "Cannot parse input");
outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.ROLLED_BACK, uriScheme.txCommitUri(1337L), -1);
verifyNoMoreInteractions(outputEventStream);
}
Aggregations