use of org.neo4j.server.http.cypher.format.api.Statement in project neo4j by neo4j.
the class InvocationTest method shouldHandleAuthorizationErrorWhenStartingTransaction.
@Test
void shouldHandleAuthorizationErrorWhenStartingTransaction() {
// given
when(databaseFacade.beginTransaction(any(), any(), any())).thenThrow(new AuthorizationViolationException("Forbidden"));
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
verifyNoMoreInteractions(log);
InOrder outputOrder = inOrder(outputEventStream);
outputOrder.verify(outputEventStream).writeFailure(Status.Security.Forbidden, "Forbidden");
outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.NO_TRANSACTION, 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 shouldCommitSinglePeriodicCommitStatement.
@Test
void shouldCommitSinglePeriodicCommitStatement() {
// given
String queryText = "USING PERIODIC COMMIT CREATE()";
var transaction = mock(InternalTransaction.class);
when(databaseFacade.beginTransaction(eq(IMPLICIT), any(LoginContext.class), any(ClientConnectionInfo.class), anyLong(), any(TimeUnit.class))).thenReturn(transaction);
when(transaction.execute(eq(queryText), any())).thenReturn(executionResult);
when(executionEngine.isPeriodicCommit(queryText)).thenReturn(true);
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);
mockDefaultResult();
Invocation invocation = new Invocation(log, handle, uriScheme.txCommitUri(1337L), mock(MemoryPool.class, RETURNS_MOCKS), inputEventStream, true);
// when
invocation.execute(outputEventStream);
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 shouldHandleErrorWhenStartingTransaction.
@Test
void shouldHandleErrorWhenStartingTransaction() {
// given
when(databaseFacade.beginTransaction(any(), any(), any())).thenThrow(new IllegalStateException("Something went wrong"));
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(log).error(eq("Failed to start transaction"), any(IllegalStateException.class));
InOrder outputOrder = inOrder(outputEventStream);
outputOrder.verify(outputEventStream).writeFailure(Status.Transaction.TransactionStartFailed, "Something went wrong");
outputOrder.verify(outputEventStream).writeTransactionInfo(TransactionNotificationState.NO_TRANSACTION, 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 shouldCommitTransactionAndTellRegistryToForgetItsHandle.
@Test
void shouldCommitTransactionAndTellRegistryToForgetItsHandle() {
// 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
InOrder transactionOrder = inOrder(internalTransaction, registry);
transactionOrder.verify(internalTransaction).commit();
transactionOrder.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).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 shouldFreeMemoryOnException.
@Test
void shouldFreeMemoryOnException() {
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();
doThrow(new ConnectionException("Something broke", new IOException("Oh no"))).when(outputEventStream).writeStatementEnd(any(), any(), any(), any());
var invocation = new Invocation(mock(Log.class), handle, uriScheme.txCommitUri(1337L), memoryPool, inputEventStream, true);
assertThrows(ConnectionException.class, () -> invocation.execute(outputEventStream));
verify(memoryPool).reserveHeap(Statement.SHALLOW_SIZE);
verify(memoryPool).releaseHeap(Statement.SHALLOW_SIZE);
verifyNoMoreInteractions(memoryPool);
}
Aggregations