use of org.neo4j.server.http.cypher.format.api.Statement 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.Statement 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.Statement in project neo4j by neo4j.
the class InvocationTest method shouldAllocateAndFreeMemory.
@Test
void shouldAllocateAndFreeMemory() {
var handle = getTransactionHandle(executionEngine, registry, false);
var memoryPool = mock(MemoryPool.class);
var inputEventStream = mock(InputEventStream.class);
when(internalTransaction.execute("query", emptyMap())).thenReturn(executionResult);
when(registry.begin(any(TransactionHandle.class))).thenReturn(1337L);
when(inputEventStream.read()).thenReturn(new Statement("query", map()), NULL_STATEMENT);
mockDefaultResult();
var invocation = new Invocation(mock(Log.class), handle, uriScheme.txCommitUri(1337L), memoryPool, inputEventStream, true);
invocation.execute(outputEventStream);
verify(memoryPool, times(2)).reserveHeap(Statement.SHALLOW_SIZE);
verify(memoryPool, times(2)).releaseHeap(Statement.SHALLOW_SIZE);
verifyNoMoreInteractions(memoryPool);
}
use of org.neo4j.server.http.cypher.format.api.Statement 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);
}
use of org.neo4j.server.http.cypher.format.api.Statement in project neo4j by neo4j.
the class InvocationTest method shouldInterruptTransaction.
@Test
void shouldInterruptTransaction() throws Exception {
// given
TransactionalContext transactionalContext = prepareKernelWithQuerySession();
when(executionEngine.executeQuery("query", NO_PARAMS, transactionalContext, false)).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);
invocation.execute(outputEventStream);
// when
handle.terminate();
// then
verify(internalTransaction).terminate();
}
Aggregations