Search in sources :

Example 6 with BufferedChannelOutput

use of org.neo4j.bolt.packstream.BufferedChannelOutput in project neo4j by neo4j.

the class BoltProtocolV4ComponentFactory method encode.

public static byte[] encode(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = requestMessageWriter(packer);
    for (RequestMessage message : messages) {
        writer.write(message);
    }
    writer.flush();
    return rawData.getBytes();
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 7 with BufferedChannelOutput

use of org.neo4j.bolt.packstream.BufferedChannelOutput in project neo4j by neo4j.

the class BoltProtocolV3ComponentFactory method encode.

public static byte[] encode(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = requestMessageWriter(packer);
    for (RequestMessage message : messages) {
        writer.write(message);
    }
    writer.flush();
    return rawData.getBytes();
}
Also used : RequestMessage(org.neo4j.bolt.messaging.RequestMessage) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 8 with BufferedChannelOutput

use of org.neo4j.bolt.packstream.BufferedChannelOutput 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 9 with BufferedChannelOutput

use of org.neo4j.bolt.packstream.BufferedChannelOutput in project neo4j by neo4j.

the class TransportErrorIT method shouldHandleUnknownMarkerBytes.

@ParameterizedTest(name = "{displayName} {2}")
@MethodSource("argumentsProvider")
public void shouldHandleUnknownMarkerBytes(Class<? extends TransportConnection> connectionClass, Neo4jPack neo4jPack, String name) throws Exception {
    initParameters(connectionClass, neo4jPack, name);
    // Given I send a message with an invalid type
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final BufferedChannelOutput out = new BufferedChannelOutput(rawData);
    final PackStream.Packer packer = new PackStream.Packer(out);
    packer.packStructHeader(2, RunMessage.SIGNATURE);
    // Invalid marker byte
    out.writeByte(PackStream.RESERVED_C7);
    out.flush();
    byte[] invalidMessage = rawData.getBytes();
    // When
    connection.connect(address).send(util.defaultAcceptedVersions()).send(util.chunk(32, invalidMessage));
    // Then
    assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
    assertThat(connection).satisfies(eventuallyDisconnects());
}
Also used : PackStream(org.neo4j.bolt.packstream.PackStream) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 10 with BufferedChannelOutput

use of org.neo4j.bolt.packstream.BufferedChannelOutput in project neo4j by neo4j.

the class TransportErrorIT method shouldHandleMessagesWithIncorrectFields.

@ParameterizedTest(name = "{displayName} {2}")
@MethodSource("argumentsProvider")
public void shouldHandleMessagesWithIncorrectFields(Class<? extends TransportConnection> connectionClass, Neo4jPack neo4jPack, String name) throws Exception {
    initParameters(connectionClass, neo4jPack, name);
    // Given I send a message with the wrong types in its fields
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final PackStream.Packer packer = new PackStream.Packer(new BufferedChannelOutput(rawData));
    packer.packStructHeader(2, RunMessage.SIGNATURE);
    packer.pack("RETURN 1");
    // Should've been a map
    packer.pack(1234);
    packer.flush();
    byte[] invalidMessage = rawData.getBytes();
    // When
    connection.connect(address).send(util.defaultAcceptedVersions()).send(util.chunk(32, invalidMessage));
    // Then
    assertThat(connection).satisfies(util.eventuallyReceivesSelectedProtocolVersion());
    assertThat(connection).satisfies(eventuallyDisconnects());
}
Also used : PackStream(org.neo4j.bolt.packstream.PackStream) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)11 RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)10 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)6 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)6 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 PackStream (org.neo4j.bolt.packstream.PackStream)3 BoltResponseMessageWriterV3 (org.neo4j.bolt.v3.messaging.BoltResponseMessageWriterV3)2 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)1 ResponseMessage (org.neo4j.bolt.messaging.ResponseMessage)1 BufferedChannelInput (org.neo4j.bolt.packstream.BufferedChannelInput)1 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)1 BoltRequestMessageWriterV4 (org.neo4j.bolt.v4.BoltRequestMessageWriterV4)1