Search in sources :

Example 6 with TransactionStateMachineSPI

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());
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 7 with TransactionStateMachineSPI

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();
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 8 with TransactionStateMachineSPI

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);
}
Also used : TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 9 with TransactionStateMachineSPI

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();
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 10 with TransactionStateMachineSPI

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");
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) BoltResultHandle(org.neo4j.bolt.runtime.BoltResultHandle) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)21 Test (org.junit.jupiter.api.Test)18 BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)13 BoltResultHandle (org.neo4j.bolt.runtime.BoltResultHandle)4 StatementProcessorReleaseManager (org.neo4j.bolt.runtime.statemachine.StatementProcessorReleaseManager)3 TransactionStateMachineSPIProvider (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)3 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 InOrder (org.mockito.InOrder)1 BoltQueryExecutor (org.neo4j.bolt.dbapi.BoltQueryExecutor)1 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1