Search in sources :

Example 1 with BufferedChannelOutput

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

the class FragmentedMessageDeliveryTest method serialize.

private byte[] serialize(int chunkSize, RequestMessage... msgs) throws IOException {
    byte[][] serialized = new byte[msgs.length][];
    for (int i = 0; i < msgs.length; i++) {
        RecordingByteChannel channel = new RecordingByteChannel();
        BoltRequestMessageWriter writer = new BoltRequestMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(channel)), NO_BOUNDARY_HOOK);
        writer.write(msgs[i]).flush();
        serialized[i] = channel.getBytes();
    }
    return Chunker.chunk(chunkSize, serialized);
}
Also used : RecordingByteChannel(org.neo4j.bolt.v1.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.v1.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.v1.messaging.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Example 2 with BufferedChannelOutput

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

the class TransportErrorIT method shouldHandleUnknownMarkerBytes.

@Test
public void shouldHandleUnknownMarkerBytes() throws Throwable {
    // 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, RUN.signature());
    // Invalid marker byte
    out.writeByte(PackStream.RESERVED_C4);
    out.flush();
    byte[] invalidMessage = rawData.getBytes();
    // When
    client.connect(address).send(acceptedVersions(1, 0, 0, 0)).send(chunk(32, invalidMessage));
    // Then
    assertThat(client, eventuallyReceives(new byte[] { 0, 0, 0, 1 }));
    assertThat(client, eventuallyDisconnects());
}
Also used : PackStream(org.neo4j.bolt.v1.packstream.PackStream) RecordingByteChannel(org.neo4j.bolt.v1.messaging.RecordingByteChannel) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput) Test(org.junit.Test)

Example 3 with BufferedChannelOutput

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

the class MessageMatchers method serialize.

public static byte[] serialize(ResponseMessage... messages) throws IOException {
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final BoltResponseMessageWriter packer = new BoltResponseMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(rawData)), NO_BOUNDARY_HOOK);
    for (ResponseMessage message : messages) {
        message.dispatch(packer);
    }
    packer.flush();
    return rawData.getBytes();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter) RecordingByteChannel(org.neo4j.bolt.v1.messaging.RecordingByteChannel) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) Neo4jPack(org.neo4j.bolt.v1.messaging.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Example 4 with BufferedChannelOutput

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

the class MessageMatchers method serialize.

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

Example 5 with BufferedChannelOutput

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

the class BoltResponseMessageTest method serializeAndDeserialize.

private <T extends ResponseMessage> T serializeAndDeserialize(T msg) throws IOException {
    RecordingByteChannel channel = new RecordingByteChannel();
    BoltResponseMessageReader reader = new BoltResponseMessageReader(new Neo4jPack.Unpacker(new BufferedChannelInput(16).reset(channel)));
    BoltResponseMessageWriter writer = new BoltResponseMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(channel)), NO_BOUNDARY_HOOK);
    msg.dispatch(writer);
    writer.flush();
    channel.eof();
    return unpack(reader, channel);
}
Also used : BufferedChannelInput(org.neo4j.bolt.v1.packstream.BufferedChannelInput) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Aggregations

BufferedChannelOutput (org.neo4j.bolt.v1.packstream.BufferedChannelOutput)8 RecordingByteChannel (org.neo4j.bolt.v1.messaging.RecordingByteChannel)6 Test (org.junit.Test)3 Neo4jPack (org.neo4j.bolt.v1.messaging.Neo4jPack)3 PackStream (org.neo4j.bolt.v1.packstream.PackStream)3 BoltRequestMessageWriter (org.neo4j.bolt.v1.messaging.BoltRequestMessageWriter)2 BufferedChannelInput (org.neo4j.bolt.v1.packstream.BufferedChannelInput)2 BoltResponseMessageWriter (org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter)1 RequestMessage (org.neo4j.bolt.v1.messaging.message.RequestMessage)1 ResponseMessage (org.neo4j.bolt.v1.messaging.message.ResponseMessage)1