use of org.neo4j.bolt.messaging.RequestMessage 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();
}
use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.
the class FragmentedMessageDeliveryTest method testPermutation.
private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
// Given
channel = new EmbeddedChannel();
BoltChannel boltChannel = newTestBoltChannel(channel);
BoltStateMachine machine = mock(BoltStateMachine.class);
SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
NullLogService logging = NullLogService.getInstance();
var bookmarksParser = mock(BookmarksParser.class);
var memoryTracker = mock(MemoryTracker.class);
BoltProtocol boltProtocol = new BoltProtocolV4(boltChannel, (ch, s, messageWriter) -> boltConnection, (v, ch, hints, mem) -> machine, Config.defaults(), bookmarksParser, logging, mock(TransportThrottleGroup.class), mock(ChannelProtector.class), memoryTracker);
boltProtocol.install();
// When data arrives split up according to the current permutation
for (ByteBuf fragment : fragments) {
channel.writeInbound(fragment.readerIndex(0).retain());
}
// Then the session should've received the specified messages, and the protocol should be in a nice clean state
try {
RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
verify(machine).process(eq(run), any(BoltResponseHandler.class));
} catch (AssertionError e) {
throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.toString(messages) + "\n" + "Chunk size: " + chunkSize + "\n" + "Serialized data delivered in fragments: " + describeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
}
}
use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.
the class HelloMessageDecoderTest method testShouldDecodeAuthToken.
@Override
protected void testShouldDecodeAuthToken(Map<String, Object> authToken) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
authToken.put("user_agent", "My Driver");
HelloMessage originalMessage = new HelloMessage(authToken, new RoutingContext(true, Collections.emptyMap()), authToken);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertHelloMessageMatches(originalMessage, deserializedMessage);
}
use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.
the class HelloMessageDecoderTest method assertOriginalMessageEqualsToDecoded.
static void assertOriginalMessageEqualsToDecoded(RequestMessage originalMessage, RequestMessageDecoder decoder) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertEquals(originalMessage, deserializedMessage);
assertAuthTokenDoesNotContainRoutingContext(deserializedMessage);
}
use of org.neo4j.bolt.messaging.RequestMessage in project neo4j by neo4j.
the class HelloMessageDecoderTest method testShouldDecodeWhenNoRoutingContextProvided.
@Test
void testShouldDecodeWhenNoRoutingContextProvided() throws Exception {
Map<String, Object> meta = new HashMap<>();
Neo4jPack neo4jPack = newNeo4jPack();
meta.put("user_agent", "My Driver");
HelloMessage originalMessage = new HelloMessage(meta, new RoutingContext(false, Collections.emptyMap()), meta);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertHelloMessageMatches(originalMessage, deserializedMessage);
assertRoutingContextMatches(originalMessage, deserializedMessage);
}
Aggregations