Search in sources :

Example 1 with BoltTransaction

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

Example 2 with BoltTransaction

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

Example 3 with BoltTransaction

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

Example 4 with BoltTransaction

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

Example 5 with BoltTransaction

use of org.neo4j.bolt.dbapi.BoltTransaction 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)

Aggregations

BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)16 Test (org.junit.jupiter.api.Test)13 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)13 BoltResultHandle (org.neo4j.bolt.runtime.BoltResultHandle)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)2 InOrder (org.mockito.InOrder)1 BoltQueryExecutor (org.neo4j.bolt.dbapi.BoltQueryExecutor)1 TransactionFailureException (org.neo4j.internal.kernel.api.exceptions.TransactionFailureException)1 LoginContext (org.neo4j.internal.kernel.api.security.LoginContext)1 Status (org.neo4j.kernel.api.exceptions.Status)1