use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.
the class TransactionStateMachineTest method newResultHandle.
private static BoltResultHandle newResultHandle() throws KernelException {
BoltResultHandle resultHandle = mock(BoltResultHandle.class);
when(resultHandle.start()).thenReturn(BoltResult.EMPTY);
return resultHandle;
}
use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.
the class TransactionStateMachineTest method newResultHandle.
private static BoltResultHandle newResultHandle(Throwable t) throws KernelException {
BoltResultHandle resultHandle = mock(BoltResultHandle.class);
when(resultHandle.start()).thenThrow(t);
return resultHandle;
}
use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldTryToTerminateAllActiveStatements.
@Test
void shouldTryToTerminateAllActiveStatements() throws Exception {
BoltTransaction transaction = newTimedOutTransaction();
BoltResultHandle resultHandle = newResultHandle();
doThrow(new RuntimeException("You shall not pass")).doThrow(new RuntimeException("Not pass twice")).when(resultHandle).terminate();
TransactionStateMachineSPI stateMachineSPI = mock(TransactionStateMachineSPI.class);
when(stateMachineSPI.beginTransaction(any(), any(), any(), any(), any(), any())).thenReturn(transaction);
when(stateMachineSPI.executeQuery(any(), anyString(), any())).thenReturn(resultHandle);
// V4
when(stateMachineSPI.supportsNestedStatementsInTransaction()).thenReturn(true);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
// We're in explicit-commit state
beginTx(stateMachine, List.of());
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.EXPLICIT_TRANSACTION);
assertNotNull(stateMachine.ctx.currentTransaction);
// We run two statements
stateMachine.run("RETURN 1", null);
stateMachine.run("RETURN 2", null);
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.EXPLICIT_TRANSACTION);
assertNotNull(stateMachine.ctx.currentTransaction);
assertThat(stateMachine.ctx.statementCounter).isEqualTo(2);
RuntimeException error = assertThrows(RuntimeException.class, () -> stateMachine.reset());
assertThat(error.getCause().getMessage()).isEqualTo("You shall not pass");
assertThat(error.getSuppressed().length).isEqualTo(1);
assertThat(error.getSuppressed()[0].getMessage()).isEqualTo("Not pass twice");
}
use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldCloseResultHandlesWhenExecutionFailsInExplicitTransaction.
@Test
void shouldCloseResultHandlesWhenExecutionFailsInExplicitTransaction() throws Exception {
BoltTransaction transaction = newTransaction();
BoltResultHandle resultHandle = newResultHandle(new RuntimeException("some error"));
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction, resultHandle);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
RuntimeException e = assertThrows(RuntimeException.class, () -> {
beginTx(stateMachine);
stateMachine.run("SOME STATEMENT", null);
});
assertEquals("some error", e.getMessage());
assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
assertNotNull(stateMachine.ctx.currentTransaction);
}
use of org.neo4j.bolt.runtime.BoltResultHandle in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldCloseResultAndTransactionHandlesWhenExecutionFails.
@Test
void shouldCloseResultAndTransactionHandlesWhenExecutionFails() throws Exception {
BoltTransaction transaction = newTransaction();
BoltResultHandle resultHandle = newResultHandle(new RuntimeException("some error"));
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction, resultHandle);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
RuntimeException e = assertThrows(RuntimeException.class, () -> stateMachine.run("SOME STATEMENT", null));
assertEquals("some error", e.getMessage());
assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
assertNull(stateMachine.ctx.currentTransaction);
}
Aggregations