Search in sources :

Example 1 with StatementOutcome

use of org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldNotFailWhenMarkedForTerminationAndPullAll.

@Test
void shouldNotFailWhenMarkedForTerminationAndPullAll() throws Exception {
    BoltStateMachineSPIImpl spi = mock(BoltStateMachineSPIImpl.class, RETURNS_MOCKS);
    BoltStateMachine machine = init(newMachine(spi));
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    machine.markForTermination();
    machine.process(BoltV4Messages.pullAll(), responseHandler);
    verify(spi, never()).reportError(any());
    assertThat(machine).isNotEqualTo(inState(FailedState.class));
}
Also used : BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) FailedState(org.neo4j.bolt.v4.runtime.FailedState) Test(org.junit.jupiter.api.Test)

Example 2 with StatementOutcome

use of org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction.

@Test
void shouldCloseResultHandlesWhenConsumeFailsInExplicitTransaction() throws Throwable {
    BoltTransaction transaction = newTransaction();
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    beginTx(stateMachine);
    stateMachine.run("SOME STATEMENT", null);
    StatementOutcome outcome = stateMachine.ctx.statementOutcomes.get(StatementMetadata.ABSENT_QUERY_ID);
    assertNotNull(outcome);
    assertNotNull(outcome.resultHandle);
    assertNotNull(outcome.result);
    RuntimeException e = assertThrows(RuntimeException.class, () -> {
        stateMachine.streamResult(StatementMetadata.ABSENT_QUERY_ID, ERROR);
    });
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNotNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 3 with StatementOutcome

use of org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome in project neo4j by neo4j.

the class TransactionStateMachineTest method shouldCloseResultAndTransactionHandlesWhenConsumeFails.

@Test
void shouldCloseResultAndTransactionHandlesWhenConsumeFails() throws Exception {
    BoltTransaction transaction = newTransaction();
    TransactionStateMachineSPI stateMachineSPI = newTransactionStateMachineSPI(transaction);
    TransactionStateMachine stateMachine = newTransactionStateMachine(stateMachineSPI);
    stateMachine.run("SOME STATEMENT", null);
    StatementOutcome outcome = stateMachine.ctx.statementOutcomes.get(StatementMetadata.ABSENT_QUERY_ID);
    assertNotNull(outcome);
    assertNotNull(outcome.resultHandle);
    assertNotNull(outcome.result);
    RuntimeException e = assertThrows(RuntimeException.class, () -> {
        stateMachine.streamResult(StatementMetadata.ABSENT_QUERY_ID, ERROR);
    });
    assertEquals("some error", e.getMessage());
    assertThat(stateMachine.ctx.statementOutcomes.entrySet()).hasSize(0);
    assertNull(stateMachine.ctx.currentTransaction);
}
Also used : BoltTransaction(org.neo4j.bolt.dbapi.BoltTransaction) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) TransactionStateMachineSPI(org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI) Test(org.junit.jupiter.api.Test)

Example 4 with StatementOutcome

use of org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGDiscardAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onDiscardRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.discardAll(), responseHandler);
        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) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Example 5 with StatementOutcome

use of org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome in project neo4j by neo4j.

the class BoltStateMachineV4Test method shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll.

@Test
void shouldTerminateOnAuthExpiryDuringSTREAMINGPullAll() throws Throwable {
    // Given
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    doThrow(new AuthorizationExpiredException("Auth expired!")).when(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
    BoltStateMachine machine = init(newMachine());
    // move to streaming state
    machine.process(BoltV4Messages.run(), nullResponseHandler());
    // We assume the only implementation of statement processor is TransactionStateMachine
    txStateMachine(machine).ctx.statementOutcomes.put(StatementMetadata.ABSENT_QUERY_ID, new StatementOutcome(BoltResult.EMPTY));
    // When & Then
    try {
        machine.process(BoltV4Messages.pullAll(), responseHandler);
        fail("Exception expected");
    } catch (BoltConnectionAuthFatality e) {
        assertEquals("Auth expired!", e.getCause().getMessage());
    }
    verify(responseHandler).onPullRecords(any(), eq(STREAM_LIMIT_UNLIMITED));
}
Also used : AuthorizationExpiredException(org.neo4j.graphdb.security.AuthorizationExpiredException) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) StatementOutcome(org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) BoltConnectionAuthFatality(org.neo4j.bolt.runtime.BoltConnectionAuthFatality) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)5 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)5 BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)3 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)3 BoltTransaction (org.neo4j.bolt.dbapi.BoltTransaction)2 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)2 TransactionStateMachineSPI (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPI)2 AuthorizationExpiredException (org.neo4j.graphdb.security.AuthorizationExpiredException)2 FailedState (org.neo4j.bolt.v4.runtime.FailedState)1