Search in sources :

Example 1 with TransactionStateMachineSPI

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

Example 2 with TransactionStateMachineSPI

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

Example 3 with TransactionStateMachineSPI

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

Example 4 with TransactionStateMachineSPI

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

Example 5 with TransactionStateMachineSPI

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();
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) 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