use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringREADYRun.
@SuppressWarnings("unchecked")
@Test
void shouldTerminateOnAuthExpiryDuringREADYRun() throws Throwable {
// Given
TransactionStateMachineSPI transactionSPI = mock(TransactionStateMachineSPI.class);
doThrow(new AuthorizationExpiredException("Auth expired!")).when(transactionSPI).beginTransaction(any(), any(), any(), any(), any(), any());
BoltStateMachine machine = newMachineWithTransactionSPI(transactionSPI);
// When & Then
try {
machine.process(BoltV4Messages.run("THIS WILL BE IGNORED"), nullResponseHandler());
fail("Exception expected");
} catch (BoltConnectionAuthFatality e) {
assertEquals("Auth expired!", e.getCause().getMessage());
}
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldResetInExplicitTransactionUponTxBeginWhenValidated.
@Test
void shouldResetInExplicitTransactionUponTxBeginWhenValidated() 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);
// 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 shouldUnbindTxAfterStreamResult.
@Test
void shouldUnbindTxAfterStreamResult() throws Throwable {
BoltTransaction transaction = newTimedOutTransaction();
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
stateMachine.run("SOME STATEMENT", null);
stateMachine.streamResult(StatementMetadata.ABSENT_QUERY_ID, EMPTY);
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldUnbindTxAfterRun.
@Test
void shouldUnbindTxAfterRun() throws Exception {
BoltTransaction transaction = newTimedOutTransaction();
TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
stateMachine.run("SOME STATEMENT", null);
}
use of org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI in project neo4j by neo4j.
the class TransactionStateMachineTest method shouldResetInAutoCommitTransactionWhileStatementIsRunningWhenValidated.
@Test
void shouldResetInAutoCommitTransactionWhileStatementIsRunningWhenValidated() 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);
stateMachine.run("RETURN 1", null);
// We're in auto-commit state
assertThat(stateMachine.state).isEqualTo(TransactionStateMachine.State.AUTO_COMMIT);
assertNotNull(stateMachine.ctx.currentTransaction);
// call validate transaction
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();
}
Aggregations