use of org.neo4j.bolt.runtime.SynchronousBoltConnection 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.runtime.SynchronousBoltConnection 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.runtime.SynchronousBoltConnection in project neo4j by neo4j.
the class MessageDecoderTest method unpack.
private void unpack(byte[] input) {
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
channel = new EmbeddedChannel(newDecoder(connection));
channel.writeInbound(Unpooled.wrappedBuffer(input));
channel.finishAndReleaseAll();
}
use of org.neo4j.bolt.runtime.SynchronousBoltConnection in project neo4j by neo4j.
the class MessageDecoderTest method shouldDispatchRequestMessage.
@ParameterizedTest
@MethodSource("argumentsProvider")
public void shouldDispatchRequestMessage(Neo4jPack packerUnderTest) throws Exception {
this.packerUnderTest = packerUnderTest;
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
channel = new EmbeddedChannel(newDecoder(connection));
channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerUnderTest, ResetMessage.INSTANCE)));
channel.finishAndReleaseAll();
verify(stateMachine).process(eq(ResetMessage.INSTANCE), any());
}
use of org.neo4j.bolt.runtime.SynchronousBoltConnection in project neo4j by neo4j.
the class MessageDecoderTest method testUnpackableStructParametersWithKnownType.
private void testUnpackableStructParametersWithKnownType(Neo4jPack packerForSerialization, AnyValue parameterValue, String expectedMessage) throws Exception {
String statement = "RETURN $x";
MapValue parameters = VirtualValues.map(new String[] { "x" }, new AnyValue[] { parameterValue });
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
SynchronousBoltConnection connection = new SynchronousBoltConnection(stateMachine);
channel = new EmbeddedChannel(newDecoder(connection));
channel.writeInbound(Unpooled.wrappedBuffer(serialize(packerForSerialization, new RunMessage(statement, parameters))));
channel.finishAndReleaseAll();
verify(stateMachine).handleExternalFailure(eq(Neo4jError.from(Status.Statement.TypeError, expectedMessage)), any());
}
Aggregations