Search in sources :

Example 1 with BoltResponseMessageWriter

use of org.neo4j.bolt.messaging.BoltResponseMessageWriter in project neo4j by neo4j.

the class MessageProcessingHandlerTest method shouldCallHaltOnUnexpectedFailures.

@Test
void shouldCallHaltOnUnexpectedFailures() throws Exception {
    // Given
    BoltResponseMessageWriter msgWriter = newResponseHandlerMock();
    doThrow(new RuntimeException("Something went horribly wrong")).when(msgWriter).write(any(SuccessMessage.class));
    BoltConnection connection = mock(BoltConnection.class);
    MessageProcessingHandler handler = new MessageProcessingHandler(msgWriter, connection, mock(Log.class));
    // When
    handler.onFinish();
    // Then
    verify(connection).stop();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) SuccessMessage(org.neo4j.bolt.v3.messaging.response.SuccessMessage) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) Log(org.neo4j.logging.Log) Test(org.junit.jupiter.api.Test)

Example 2 with BoltResponseMessageWriter

use of org.neo4j.bolt.messaging.BoltResponseMessageWriter in project neo4j by neo4j.

the class MessageProcessingHandlerTest method emulateFailureWritingError.

private static AssertableLogProvider emulateFailureWritingError(Neo4jError error, Throwable errorDuringWrite) throws Exception {
    AssertableLogProvider logProvider = new AssertableLogProvider();
    BoltResponseMessageWriter responseHandler = newResponseHandlerMock(errorDuringWrite);
    MessageProcessingHandler handler = new MessageProcessingHandler(responseHandler, mock(BoltConnection.class), logProvider.getLog(MessageProcessingHandlerTest.class));
    handler.markFailed(error);
    handler.onFinish();
    return logProvider;
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 3 with BoltResponseMessageWriter

use of org.neo4j.bolt.messaging.BoltResponseMessageWriter in project neo4j by neo4j.

the class MessageDecoderTest method shouldLogContentOfTheMessageOnIOError.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnIOError(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    BoltConnection connection = mock(BoltConnection.class);
    BoltResponseMessageWriter responseMessageHandler = mock(BoltResponseMessageWriter.class);
    BoltRequestMessageReader requestMessageReader = new BoltRequestMessageReaderV3(connection, responseMessageHandler, mock(ChannelProtector.class), NullLogService.getInstance());
    LogService logService = mock(LogService.class);
    Log log = mock(Log.class);
    when(logService.getInternalLog(MessageDecoder.class)).thenReturn(log);
    channel = new EmbeddedChannel(new MessageDecoder(packerUnderTest::newUnpacker, requestMessageReader, logService));
    byte invalidMessageSignature = Byte.MAX_VALUE;
    byte[] messageBytes = packMessageWithSignature(invalidMessageSignature);
    assertThrows(BoltIOException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
    assertMessageHexDumpLogged(log, messageBytes);
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) BoltConnection(org.neo4j.bolt.runtime.BoltConnection) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) Log(org.neo4j.logging.Log) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) BoltRequestMessageReaderV3(org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3) NullLogService(org.neo4j.logging.internal.NullLogService) LogService(org.neo4j.logging.internal.LogService) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with BoltResponseMessageWriter

use of org.neo4j.bolt.messaging.BoltResponseMessageWriter in project neo4j by neo4j.

the class MessageConditions method serialize.

public static byte[] serialize(Neo4jPack neo4jPack, ResponseMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    BufferedChannelOutput output = new BufferedChannelOutput(rawData);
    BoltResponseMessageWriter writer = new BoltResponseMessageWriterV3(neo4jPack::newPacker, output, NullLogService.getInstance());
    for (ResponseMessage message : messages) {
        writer.write(message);
    }
    writer.flush();
    return rawData.getBytes();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) BoltResponseMessageWriterV3(org.neo4j.bolt.v3.messaging.BoltResponseMessageWriterV3) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) ResponseMessage(org.neo4j.bolt.messaging.ResponseMessage) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 5 with BoltResponseMessageWriter

use of org.neo4j.bolt.messaging.BoltResponseMessageWriter in project neo4j by neo4j.

the class MessageProcessingHandlerTest method newResponseHandlerMock.

private static BoltResponseMessageWriter newResponseHandlerMock(Throwable error) throws Exception {
    BoltResponseMessageWriter handler = newResponseHandlerMock();
    doThrow(error).when(handler).write(any(FailureMessage.class));
    return handler;
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) FailureMessage(org.neo4j.bolt.v3.messaging.response.FailureMessage)

Aggregations

BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)5 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)3 Log (org.neo4j.logging.Log)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)1 RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)1 ResponseMessage (org.neo4j.bolt.messaging.ResponseMessage)1 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)1 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)1 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)1 MessageDecoder (org.neo4j.bolt.transport.pipeline.MessageDecoder)1 BoltRequestMessageReaderV3 (org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3)1 BoltResponseMessageWriterV3 (org.neo4j.bolt.v3.messaging.BoltResponseMessageWriterV3)1 FailureMessage (org.neo4j.bolt.v3.messaging.response.FailureMessage)1 SuccessMessage (org.neo4j.bolt.v3.messaging.response.SuccessMessage)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 LogService (org.neo4j.logging.internal.LogService)1