use of org.neo4j.bolt.v1.runtime.SynchronousBoltWorker in project neo4j by neo4j.
the class BoltProtocolV1Test method shouldNotTalkToChannelDirectlyOnFatalError.
@Test
public void shouldNotTalkToChannelDirectlyOnFatalError() throws Throwable {
// Given
Channel outputChannel = newChannelMock();
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), outputChannel, NullLogService.getInstance());
verify(outputChannel).alloc();
// And given inbound data that'll explode when the protocol tries to interpret it
ByteBuf bomb = mock(ByteBuf.class);
doThrow(IOException.class).when(bomb).readableBytes();
// When
protocol.handle(mock(ChannelHandlerContext.class), bomb);
// Then the protocol should not mess with the channel (because it runs on the IO thread, and only the worker thread should produce writes)
verifyNoMoreInteractions(outputChannel);
// But instead make sure the state machine is shut down
verify(machine).close();
}
use of org.neo4j.bolt.v1.runtime.SynchronousBoltWorker in project neo4j by neo4j.
the class FragmentedMessageDeliveryTest method testPermutation.
private void testPermutation(byte[] unfragmented, ByteBuf[] fragments) throws Exception {
// Given
BoltStateMachine machine = mock(BoltStateMachine.class);
Channel ch = mock(Channel.class);
when(ch.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
when(ctx.channel()).thenReturn(ch);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), ch, NullLogService.getInstance());
// When data arrives split up according to the current permutation
for (ByteBuf fragment : fragments) {
fragment.readerIndex(0).retain();
protocol.handle(ctx, fragment);
}
// Then the session should've received the specified messages, and the protocol should be in a nice clean state
try {
verify(machine).run(eq("Mjölnir"), anyMapOf(String.class, Object.class), 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);
} finally {
// To avoid buffer leak errors
protocol.close();
}
}
use of org.neo4j.bolt.v1.runtime.SynchronousBoltWorker in project neo4j by neo4j.
the class SocketTransportHandlerTest method protocolChooser.
private ProtocolChooser protocolChooser(final BoltStateMachine machine) {
Map<Long, BiFunction<Channel, Boolean, BoltProtocol>> availableVersions = new HashMap<>();
availableVersions.put((long) BoltProtocolV1.VERSION, (channel, isSecure) -> new BoltProtocolV1(new SynchronousBoltWorker(machine), channel, NullLogService.getInstance()));
return new ProtocolChooser(availableVersions, false, true);
}
use of org.neo4j.bolt.v1.runtime.SynchronousBoltWorker in project neo4j by neo4j.
the class BoltProtocolV1Test method closesInputAndOutput.
@Test
public void closesInputAndOutput() {
Channel outputChannel = mock(Channel.class);
ByteBufAllocator allocator = mock(ByteBufAllocator.class);
ByteBuf buffer = mock(ByteBuf.class);
when(outputChannel.alloc()).thenReturn(allocator);
when(allocator.buffer(anyInt(), anyInt())).thenReturn(buffer);
BoltStateMachine machine = mock(BoltStateMachine.class);
BoltProtocolV1 protocol = new BoltProtocolV1(new SynchronousBoltWorker(machine), outputChannel, NullLogService.getInstance());
protocol.close();
verify(machine).close();
verify(buffer).release();
}
Aggregations