Search in sources :

Example 1 with MessageDecoder

use of org.neo4j.bolt.transport.pipeline.MessageDecoder in project neo4j by neo4j.

the class AbstractBoltProtocol method install.

/**
 * Install chunker, packstream, message reader, message handler, message encoder for protocol v1
 */
@Override
public void install() {
    BoltStateMachine stateMachine = stateMachineFactory.newStateMachine(version(), channel, connectionHints, memoryTracker);
    var neo4jPack = createPack(memoryTracker);
    var messageWriter = createMessageWriter(neo4jPack, logging, memoryTracker);
    var connection = connectionFactory.newConnection(channel, stateMachine, messageWriter);
    var messageReader = createMessageReader(connection, messageWriter, bookmarksParser, logging, channelProtector, memoryTracker);
    memoryTracker.allocateHeap(ChunkDecoder.SHALLOW_SIZE + MessageAccumulator.SHALLOW_SIZE + MessageDecoder.SHALLOW_SIZE + HouseKeeper.SHALLOW_SIZE);
    channel.installBoltProtocol(new ChunkDecoder(), new MessageAccumulator(config), new MessageDecoder(neo4jPack, messageReader, logging), new HouseKeeper(connection, logging.getInternalLog(HouseKeeper.class)));
}
Also used : MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) ChunkDecoder(org.neo4j.bolt.transport.pipeline.ChunkDecoder) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) MessageAccumulator(org.neo4j.bolt.transport.pipeline.MessageAccumulator) HouseKeeper(org.neo4j.bolt.transport.pipeline.HouseKeeper)

Example 2 with MessageDecoder

use of org.neo4j.bolt.transport.pipeline.MessageDecoder in project neo4j by neo4j.

the class MessageDecoderTest method shouldLogContentOfTheMessageOnError.

@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnError(Neo4jPack packerUnderTest) throws Exception {
    this.packerUnderTest = packerUnderTest;
    BoltRequestMessageReader requestMessageReader = mock(BoltRequestMessageReader.class);
    RuntimeException error = new RuntimeException("Hello!");
    doThrow(error).when(requestMessageReader).read(any());
    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[] messageBytes = packMessageWithSignature(RunMessage.SIGNATURE);
    var e = assertThrows(RuntimeException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
    assertEquals(error, e);
    assertMessageHexDumpLogged(log, messageBytes);
}
Also used : MessageDecoder(org.neo4j.bolt.transport.pipeline.MessageDecoder) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) Log(org.neo4j.logging.Log) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) 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 3 with MessageDecoder

use of org.neo4j.bolt.transport.pipeline.MessageDecoder 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)

Aggregations

MessageDecoder (org.neo4j.bolt.transport.pipeline.MessageDecoder)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 BoltRequestMessageReader (org.neo4j.bolt.messaging.BoltRequestMessageReader)2 Log (org.neo4j.logging.Log)2 LogService (org.neo4j.logging.internal.LogService)2 NullLogService (org.neo4j.logging.internal.NullLogService)2 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1 BoltConnection (org.neo4j.bolt.runtime.BoltConnection)1 SynchronousBoltConnection (org.neo4j.bolt.runtime.SynchronousBoltConnection)1 BoltStateMachine (org.neo4j.bolt.runtime.statemachine.BoltStateMachine)1 ChannelProtector (org.neo4j.bolt.transport.pipeline.ChannelProtector)1 ChunkDecoder (org.neo4j.bolt.transport.pipeline.ChunkDecoder)1 HouseKeeper (org.neo4j.bolt.transport.pipeline.HouseKeeper)1 MessageAccumulator (org.neo4j.bolt.transport.pipeline.MessageAccumulator)1 BoltRequestMessageReaderV3 (org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3)1