use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class BoltRequestMessageReaderV43Test method verifyBoltV3MessageIsReadAsBoltV4Message.
private static void verifyBoltV3MessageIsReadAsBoltV4Message(TransactionInitiatingMessage messageV3, TransactionInitiatingMessage messageV4) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltRequestMessageReader reader = requestMessageReader(stateMachine);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, messageV3));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
reader.read(unpacker);
verify(stateMachine).process(eq(messageV4), any());
assertThat(messageV3.meta()).isEqualTo(messageV4.meta());
}
use of org.neo4j.bolt.packstream.PackedInputArray 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);
}
use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class DiscardMessageDecoderTest method assertOriginalMessageEqualsToDecoded.
private 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);
}
use of org.neo4j.bolt.packstream.PackedInputArray 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);
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.packstream.PackedInputArray in project neo4j by neo4j.
the class BoltRequestMessageReaderV4Test method testMessageDecoding.
private static void testMessageDecoding(RequestMessage message) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltRequestMessageReader reader = requestMessageReader(stateMachine);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, message));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
reader.read(unpacker);
verify(stateMachine).process(eq(message), any());
}
Aggregations