Search in sources :

Example 6 with BufferedChannelOutput

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

the class BoltRequestMessageTest method serializeAndDeserialize.

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

Example 7 with BufferedChannelOutput

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

the class TransportErrorIT method shouldHandleUnknownMessages.

@Test
public void shouldHandleUnknownMessages() throws Throwable {
    // Given I send a message with an invalid type
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final PackStream.Packer packer = new PackStream.Packer(new BufferedChannelOutput(rawData));
    // Invalid message type
    packer.packStructHeader(1, (byte) 0x66);
    packer.pack(1234);
    packer.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 8 with BufferedChannelOutput

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

the class TransportErrorIT method shouldHandleMessagesWithIncorrectFields.

@Test
public void shouldHandleMessagesWithIncorrectFields() throws Throwable {
    // 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, RUN.signature());
    packer.pack("RETURN 1");
    // Should've been a map
    packer.pack(1234);
    packer.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)

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