use of org.neo4j.bolt.v1.messaging.BoltRequestMessageRecorder in project neo4j by neo4j.
the class MessageMatchers method messages.
public static List<RequestMessage> messages(byte[] bytes) throws IOException {
BoltRequestMessageReader unpacker = requestReader(bytes);
BoltRequestMessageRecorder consumer = new BoltRequestMessageRecorder();
try {
while (unpacker.hasNext()) {
unpacker.read(consumer);
}
return consumer.asList();
} catch (Throwable e) {
throw new IOException("Failed to deserialize response, '" + e.getMessage() + "'. Messages read so " + "far: \n" + consumer.asList() + "\n" + "Raw data: \n" + HexPrinter.hex(bytes));
}
}
use of org.neo4j.bolt.v1.messaging.BoltRequestMessageRecorder in project neo4j by neo4j.
the class BoltV1DechunkerTest method shouldReadMessageWhenTheHeaderIsSplitAcrossChunks.
@Test
public void shouldReadMessageWhenTheHeaderIsSplitAcrossChunks() throws Exception {
Random random = ThreadLocalRandom.current();
for (int len = 1; len <= 0x8000; len = len << 1) {
// given
StringBuilder content = new StringBuilder(len);
for (int i = 0; i < len; i++) {
content.appendCodePoint('a' + random.nextInt('z' - 'a'));
}
RunMessage run = run(content.toString());
byte[] message = MessageMatchers.serialize(run);
byte head1 = (byte) (message.length >> 8), head2 = (byte) (message.length & 0xFF);
byte[] chunk2 = new byte[message.length + 3];
chunk2[0] = head2;
System.arraycopy(message, 0, chunk2, 1, message.length);
BoltRequestMessageRecorder messages = new BoltRequestMessageRecorder();
BoltV1Dechunker dechunker = new BoltV1Dechunker(messages, () -> {
});
// when
dechunker.handle(wrappedBuffer(new byte[] { head1 }));
assertTrue("content length " + len + ": should be waiting for second chunk", messages.asList().isEmpty());
dechunker.handle(wrappedBuffer(chunk2));
// then
assertEquals("content length " + len + ": should have received message", 1, messages.asList().size());
assertEquals(run, messages.asList().get(0));
}
}
Aggregations