Search in sources :

Example 1 with BoltResponseHandler

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

the class BoltRequestMessageReader method doRead.

private void doRead(Neo4jPack.Unpacker unpacker) throws IOException {
    try {
        unpacker.unpackStructHeader();
        int signature = unpacker.unpackStructSignature();
        RequestMessageDecoder decoder = decoders.get(signature);
        if (decoder == null) {
            throw new BoltIOException(Status.Request.InvalidFormat, String.format("Message 0x%s is not a valid message signature.", Integer.toHexString(signature)));
        }
        RequestMessage message = decoder.decode(unpacker);
        BoltResponseHandler responseHandler = decoder.responseHandler();
        connection.enqueue(stateMachine -> stateMachine.process(message, responseHandler));
        channelProtector.afterRequestReceived();
    } catch (PackStream.PackStreamException e) {
        throw new BoltIOException(Status.Request.InvalidFormat, String.format("Unable to read message type. Error was: %s.", e.getMessage()), e);
    }
}
Also used : PackStream(org.neo4j.bolt.packstream.PackStream) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler)

Example 2 with BoltResponseHandler

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

the class StreamingStateIT method shouldMoveFromStreamingStateToFailedStateOnPullAllOrDiscardAll_fail.

@ParameterizedTest
@MethodSource("pullAllDiscardAllMessages")
void shouldMoveFromStreamingStateToFailedStateOnPullAllOrDiscardAll_fail(RequestMessage message) throws Throwable {
    // Given
    BoltStateMachineV3 machine = getBoltStateMachineInStreamingState();
    // 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)

Example 3 with BoltResponseHandler

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

the class BoltRequestMessageReaderV3 method buildDecoders.

private static List<RequestMessageDecoder> buildDecoders(BoltConnection connection, BoltResponseMessageWriter responseMessageWriter, LogService logService) {
    BoltResponseHandler resultHandler = new ResultHandler(responseMessageWriter, connection, internalLog(logService));
    BoltResponseHandler defaultHandler = newSimpleResponseHandler(responseMessageWriter, connection, logService);
    return Arrays.asList(new HelloMessageDecoder(defaultHandler), new RunMessageDecoder(defaultHandler), new DiscardAllMessageDecoder(resultHandler), new PullAllMessageDecoder(resultHandler), new BeginMessageDecoder(defaultHandler), new CommitMessageDecoder(resultHandler), new RollbackMessageDecoder(resultHandler), new ResetMessageDecoder(connection, defaultHandler), new GoodbyeMessageDecoder(connection, defaultHandler));
}
Also used : DiscardAllMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.DiscardAllMessageDecoder) PullAllMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.PullAllMessageDecoder) RollbackMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.RollbackMessageDecoder) HelloMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.HelloMessageDecoder) GoodbyeMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.GoodbyeMessageDecoder) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler) ResetMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.ResetMessageDecoder) CommitMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.CommitMessageDecoder) BeginMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.BeginMessageDecoder) RunMessageDecoder(org.neo4j.bolt.v3.messaging.decoder.RunMessageDecoder)

Example 4 with BoltResponseHandler

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

the class BoltStateMachineV4Test method testMarkFailedShouldYieldSuccessIfAlreadyFailed.

private static void testMarkFailedShouldYieldSuccessIfAlreadyFailed(ThrowingBiConsumer<BoltStateMachine, BoltResponseHandler, BoltConnectionFatality> action) throws Exception {
    // Given
    BoltStateMachine machine = init(newMachine());
    machine.markFailed(Neo4jError.from(new RuntimeException()));
    BoltResponseHandler responseHandler = mock(BoltResponseHandler.class);
    Neo4jError error = Neo4jError.from(Status.Request.NoThreadsAvailable, "no threads");
    machine.markFailed(error);
    // When
    action.accept(machine, responseHandler);
    // Expect
    assertNull(pendingError(machine));
    assertFalse(pendingIgnore(machine));
    assertThat(machine).satisfies(inState(ReadyState.class));
    verify(responseHandler, never()).markIgnored();
    verify(responseHandler, never()).markFailed(any());
}
Also used : Neo4jError(org.neo4j.bolt.runtime.Neo4jError) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) ReadyState(org.neo4j.bolt.v4.runtime.ReadyState) BoltResponseHandler(org.neo4j.bolt.runtime.BoltResponseHandler)

Example 5 with BoltResponseHandler

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

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