use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldNotMarkForTerminationWhenNoTransaction.
@Test
void shouldNotMarkForTerminationWhenNoTransaction() throws Exception {
BoltTransaction transaction = newTransaction();
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
stateMachine.markCurrentTransactionForTermination();
verify(transaction, never()).markForTermination(any());
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldResetInExplicitTransactionWhileStatementIsRunningWhenValidated.
@Test
void shouldResetInExplicitTransactionWhileStatementIsRunningWhenValidated() throws Exception {
BoltTransaction transaction = newTimedOutTransaction();
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
// start an explicit transaction
beginTx(stateMachine);
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.EXPLICIT_TRANSACTION);
assertNotNull(stateMachine.ctx.currentTransaction);
stateMachine.run("RETURN 1", null);
// verify transaction, which is timed out
stateMachine.validateTransaction();
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.AUTO_COMMIT);
assertNull(stateMachine.ctx.currentTransaction);
assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
verify(transaction).getReasonIfTerminated();
verify(transaction).rollback();
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldStartWithAutoCommitState.
@Test
void shouldStartWithAutoCommitState() {
TransactionStateMachineSPI stateMachineSPI = mock(TransactionStateMachineSPI.class);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.AUTO_COMMIT);
assertNull(stateMachine.ctx.currentTransaction);
assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldDoNothingInAutoCommitTransactionUponInitialisationWhenValidated.
@Test
void shouldDoNothingInAutoCommitTransactionUponInitialisationWhenValidated() throws Exception {
BoltTransaction transaction = newTimedOutTransaction();
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
// We're in auto-commit state
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.AUTO_COMMIT);
assertNull(stateMachine.ctx.currentTransaction);
// call validate transaction
stateMachine.validateTransaction();
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.AUTO_COMMIT);
assertNull(stateMachine.ctx.currentTransaction);
verify(transaction, never()).getReasonIfTerminated();
verify(transaction, never()).rollback();
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI 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");
}
Aggregations