use of org.neo4j.bolt.v3.messaging.BoltRequestMessageReaderV3 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.v3.messaging.BoltRequestMessageReaderV3 in project neo4j by neo4j.
the class MessageDecoderTest method shouldLogContentOfTheMessageOnIOError.
@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldLogContentOfTheMessageOnIOError(Neo4jPack packerUnderTest) throws Exception {
this.packerUnderTest = packerUnderTest;
BoltConnection connection = mock(BoltConnection.class);
BoltResponseMessageWriter responseMessageHandler = mock(BoltResponseMessageWriter.class);
BoltRequestMessageReader requestMessageReader = new BoltRequestMessageReaderV3(connection, responseMessageHandler, mock(ChannelProtector.class), NullLogService.getInstance());
LogService logService = mock(LogService.class);
Log log = mock(Log.class);
when(logService.getInternalLog(MessageDecoder.class)).thenReturn(log);
channel = new EmbeddedChannel(new MessageDecoder(packerUnderTest::newUnpacker, requestMessageReader, logService));
byte invalidMessageSignature = Byte.MAX_VALUE;
byte[] messageBytes = packMessageWithSignature(invalidMessageSignature);
assertThrows(BoltIOException.class, () -> channel.writeInbound(Unpooled.wrappedBuffer(messageBytes)));
assertMessageHexDumpLogged(log, messageBytes);
}
Aggregations