Search in sources :

Example 1 with RecordingByteChannel

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

the class MessageConditions method serialize.

public static byte[] serialize(Neo4jPack neo4jPack, RequestMessage... messages) throws IOException {
    RecordingByteChannel rawData = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(rawData));
    BoltRequestMessageWriter writer = new BoltRequestMessageWriterV4(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) BoltRequestMessageWriterV4(org.neo4j.bolt.v4.BoltRequestMessageWriterV4) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Example 2 with RecordingByteChannel

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

the class BoltProtocolV43ComponentFactory 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 3 with RecordingByteChannel

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

the class BoltProtocolV41ComponentFactory 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 4 with RecordingByteChannel

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

the class BoltRequestMessageV3Test method unpack.

private <T extends RequestMessage> T unpack(RecordingByteChannel channel) throws Exception {
    List<RequestMessage> messages = new ArrayList<>();
    BoltStateMachine stateMachine = mock(BoltStateMachine.class);
    doAnswer((Answer<Void>) invocationOnMock -> {
        RequestMessage msg = invocationOnMock.getArgument(0);
        messages.add(msg);
        return null;
    }).when(stateMachine).process(any(), any());
    BoltRequestMessageReader reader = new BoltRequestMessageReaderV3(new SynchronousBoltConnection(stateMachine), mock(BoltResponseMessageWriter.class), mock(ChannelProtector.class), NullLogService.getInstance());
    byte[] bytes = channel.getBytes();
    String serialized = HexPrinter.hex(bytes);
    Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(new PackedInputArray(bytes));
    try {
        reader.read(unpacker);
    } catch (Throwable e) {
        throw new AssertionError("Failed to unpack message, wire data was:\n" + serialized + "[" + bytes.length + "b]", e);
    }
    return (T) messages.get(0);
}
Also used : PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) ResetMessage(org.neo4j.bolt.v3.messaging.request.ResetMessage) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnyValue(org.neo4j.values.AnyValue) MapUtil.map(org.neo4j.internal.helpers.collection.MapUtil.map) System.lineSeparator(java.lang.System.lineSeparator) NullLogService(org.neo4j.logging.internal.NullLogService) HexPrinter(org.neo4j.common.HexPrinter) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NodeValue(org.neo4j.values.virtual.NodeValue) GOODBYE_MESSAGE(org.neo4j.bolt.v3.messaging.request.GoodbyeMessage.GOODBYE_MESSAGE) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) ArrayList(java.util.ArrayList) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) Answer(org.mockito.stubbing.Answer) DiscardAllMessage(org.neo4j.bolt.v3.messaging.request.DiscardAllMessage) VirtualValues.map(org.neo4j.values.virtual.VirtualValues.map) RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) Mockito.doAnswer(org.mockito.Mockito.doAnswer) MapValue(org.neo4j.values.virtual.MapValue) PullAllMessage(org.neo4j.bolt.v3.messaging.request.PullAllMessage) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) VirtualValues(org.neo4j.values.virtual.VirtualValues) MessageConditions.serialize(org.neo4j.bolt.testing.MessageConditions.serialize) BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) ValueUtils(org.neo4j.kernel.impl.util.ValueUtils) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) VirtualValues.relationshipValue(org.neo4j.values.virtual.VirtualValues.relationshipValue) Values.stringArray(org.neo4j.values.storable.Values.stringArray) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput) HelloMessage(org.neo4j.bolt.v3.messaging.request.HelloMessage) IOException(java.io.IOException) BeginMessage(org.neo4j.bolt.v3.messaging.request.BeginMessage) Values.stringValue(org.neo4j.values.storable.Values.stringValue) RunMessage(org.neo4j.bolt.v3.messaging.request.RunMessage) Test(org.junit.jupiter.api.Test) VirtualValues.nodeValue(org.neo4j.values.virtual.VirtualValues.nodeValue) List(java.util.List) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) COMMIT_MESSAGE(org.neo4j.bolt.v3.messaging.request.CommitMessage.COMMIT_MESSAGE) Values.intValue(org.neo4j.values.storable.Values.intValue) ROLLBACK_MESSAGE(org.neo4j.bolt.v3.messaging.request.RollbackMessage.ROLLBACK_MESSAGE) RecordMessage(org.neo4j.bolt.v3.messaging.response.RecordMessage) Mockito.mock(org.mockito.Mockito.mock) BoltResponseMessageWriter(org.neo4j.bolt.messaging.BoltResponseMessageWriter) BoltRequestMessageReader(org.neo4j.bolt.messaging.BoltRequestMessageReader) SynchronousBoltConnection(org.neo4j.bolt.runtime.SynchronousBoltConnection) ArrayList(java.util.ArrayList) ChannelProtector(org.neo4j.bolt.transport.pipeline.ChannelProtector) BoltStateMachine(org.neo4j.bolt.runtime.statemachine.BoltStateMachine) RequestMessage(org.neo4j.bolt.messaging.RequestMessage) PackedInputArray(org.neo4j.bolt.packstream.PackedInputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)

Example 5 with RecordingByteChannel

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

the class BoltRequestMessageV3Test method serializeAndDeserialize.

private <T extends RequestMessage> T serializeAndDeserialize(T msg) throws Exception {
    RecordingByteChannel channel = new RecordingByteChannel();
    Neo4jPack.Packer packer = neo4jPack.newPacker(new BufferedChannelOutput(channel));
    BoltRequestMessageWriter writer = new BoltRequestMessageWriterV3(packer);
    writer.write(msg).flush();
    channel.eof();
    return unpack(channel);
}
Also used : RecordingByteChannel(org.neo4j.bolt.messaging.RecordingByteChannel) BoltRequestMessageWriter(org.neo4j.bolt.messaging.BoltRequestMessageWriter) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) BoltProtocolV3ComponentFactory.newNeo4jPack(org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack) BufferedChannelOutput(org.neo4j.bolt.packstream.BufferedChannelOutput)

Aggregations

RecordingByteChannel (org.neo4j.bolt.messaging.RecordingByteChannel)12 BufferedChannelOutput (org.neo4j.bolt.packstream.BufferedChannelOutput)11 BoltRequestMessageWriter (org.neo4j.bolt.messaging.BoltRequestMessageWriter)8 Neo4jPack (org.neo4j.bolt.packstream.Neo4jPack)7 RequestMessage (org.neo4j.bolt.messaging.RequestMessage)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 PackStream (org.neo4j.bolt.packstream.PackStream)3 BoltResponseMessageWriter (org.neo4j.bolt.messaging.BoltResponseMessageWriter)2 BoltProtocolV3ComponentFactory.newNeo4jPack (org.neo4j.bolt.v3.BoltProtocolV3ComponentFactory.newNeo4jPack)2 BoltRequestMessageWriterV4 (org.neo4j.bolt.v4.BoltRequestMessageWriterV4)2 IOException (java.io.IOException)1 System.lineSeparator (java.lang.System.lineSeparator)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Test (org.junit.jupiter.api.Test)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 Mockito.mock (org.mockito.Mockito.mock)1