Search in sources :

Example 16 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler 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)

Example 17 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class BoltConnectionIT method shouldHandleFailureDuringResultPublishing.

@Test
void shouldHandleFailureDuringResultPublishing() throws Throwable {
    // Given
    var machine = newStateMachineAfterAuth();
    var pullAllCallbackCalled = new CountDownLatch(1);
    var error = new AtomicReference<Neo4jError>();
    // When something fails while publishing the result stream
    machine.process(run(), nullResponseHandler());
    machine.process(pullAll(), new BoltResponseHandler() {

        @Override
        public boolean onPullRecords(BoltResult result, long size) throws Throwable {
            throw new RuntimeException("Ooopsies!");
        }

        @Override
        public boolean onDiscardRecords(BoltResult result, long size) throws Throwable {
            throw new RuntimeException("Not this one!");
        }

        @Override
        public void onMetadata(String key, AnyValue value) {
        }

        @Override
        public void markFailed(Neo4jError err) {
            error.set(err);
            pullAllCallbackCalled.countDown();
        }

        @Override
        public void markIgnored() {
        }

        @Override
        public void onFinish() {
        }
    });
    // Then
    assertTrue(pullAllCallbackCalled.await(30, TimeUnit.SECONDS));
    var err = error.get();
    assertThat(err.status()).isEqualTo(Status.General.UnknownError);
    assertThat(err.message()).contains("Ooopsies!");
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) AnyValue(org.neo4j.values.AnyValue) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BoltResult(org.neo4j.bolt.runtime.BoltResult) Test(org.junit.jupiter.api.Test)

Example 18 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class InTransactionStateIT method shouldMoveFromInTxStateToFailedStateOnfail.

@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromInTxStateToFailedStateOnfail(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV4 machine = getBoltStateMachineInTxState();
    // When
    BoltResponseHandler handler = mock(BoltResponseHandler.class);
    doThrow(new RuntimeException("Fail")).when(handler).onPullRecords(any(), anyLong());
    doThrow(new RuntimeException("Fail")).when(handler).onDiscardRecords(any(), anyLong());
    machine.process(message, handler);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV4(org.neo4j.bolt.v4.BoltStateMachineV4) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 19 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class TransactionReadyStateIT method shouldMoveToFailedOnRun_fail.

@Test
void shouldMoveToFailedOnRun_fail() throws Throwable {
    BoltStateMachineV3 machine = getBoltStateMachineInTxReadyState();
    // When
    BoltResponseHandler handler = mock(BoltResponseHandler.class);
    doThrow(new RuntimeException("Error!")).when(handler).onPullRecords(any(), anyLong());
    doThrow(new RuntimeException("Error!")).when(handler).onDiscardRecords(any(), anyLong());
    machine.process(new RunMessage("A cypher query"), handler);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 20 with BoltResponseHandler

use of org.neo4j.bolt.runtime.BoltResponseHandler in project neo4j by neo4j.

the class TransactionStreamingStateIT method shouldMoveFromTxStreamingStateToFailedStateOnPullAllOrDiscardAll_fail.

@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromTxStreamingStateToFailedStateOnPullAllOrDiscardAll_fail(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV3 machine = getBoltStateMachineInTxStreamingState();
    // When
    BoltResponseHandler handler = mock(BoltResponseHandler.class);
    doThrow(new RuntimeException("Fail")).when(handler).onPullRecords(any(), anyLong());
    doThrow(new RuntimeException("Fail")).when(handler).onDiscardRecords(any(), anyLong());
    machine.process(message, handler);
    // Then
    assertThat(machine.state()).isInstanceOf(FailedState.class);
}
Also used : BoltStateMachineV3(org.neo4j.bolt.v3.BoltStateMachineV3) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

BoltResponseHandler (org.neo4j.bolt.runtime.BoltResponseHandler)20 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)10 Test (org.junit.jupiter.api.Test)8 Neo4jError (org.neo4j.bolt.runtime.Neo4jError)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CommitMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.CommitMessageDecoder)4 GoodbyeMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.GoodbyeMessageDecoder)4 ResetMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.ResetMessageDecoder)4 RollbackMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.RollbackMessageDecoder)4 FailedState (org.neo4j.bolt.v4.runtime.FailedState)4 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 StatementOutcome (org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.StatementOutcome)3 BoltStateMachineV3 (org.neo4j.bolt.v3.BoltStateMachineV3)3 ResultHandler (org.neo4j.bolt.v3.messaging.ResultHandler)3 Unpacker (org.neo4j.bolt.packstream.Neo4jPack.Unpacker)2 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)2 BoltConnectionAuthFatality (org.neo4j.bolt.runtime.BoltConnectionAuthFatality)2 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)2 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)2 HelloMessageDecoder (org.neo4j.bolt.v3.messaging.decoder.HelloMessageDecoder)2