Search in sources :

Example 1 with SynchronousBoltWorker

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();
}
Also used : SynchronousBoltWorker(org.neo4j.bolt.v1.runtime.SynchronousBoltWorker) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 2 with SynchronousBoltWorker

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();
    }
}
Also used : SynchronousBoltWorker(org.neo4j.bolt.v1.runtime.SynchronousBoltWorker) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) RecordingByteChannel(org.neo4j.bolt.v1.messaging.RecordingByteChannel) Channel(io.netty.channel.Channel) BoltResponseHandler(org.neo4j.bolt.v1.runtime.BoltResponseHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) BoltProtocolV1(org.neo4j.bolt.v1.transport.BoltProtocolV1) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with SynchronousBoltWorker

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);
}
Also used : SynchronousBoltWorker(org.neo4j.bolt.v1.runtime.SynchronousBoltWorker) HashMap(java.util.HashMap) BiFunction(java.util.function.BiFunction) BoltProtocolV1(org.neo4j.bolt.v1.transport.BoltProtocolV1) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser)

Example 4 with SynchronousBoltWorker

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();
}
Also used : ByteBufAllocator(io.netty.buffer.ByteBufAllocator) SynchronousBoltWorker(org.neo4j.bolt.v1.runtime.SynchronousBoltWorker) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) Channel(io.netty.channel.Channel) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

SynchronousBoltWorker (org.neo4j.bolt.v1.runtime.SynchronousBoltWorker)4 ByteBuf (io.netty.buffer.ByteBuf)3 Channel (io.netty.channel.Channel)3 BoltStateMachine (org.neo4j.bolt.v1.runtime.BoltStateMachine)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 Test (org.junit.Test)2 BoltProtocolV1 (org.neo4j.bolt.v1.transport.BoltProtocolV1)2 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 HashMap (java.util.HashMap)1 BiFunction (java.util.function.BiFunction)1 ProtocolChooser (org.neo4j.bolt.transport.ProtocolChooser)1 RecordingByteChannel (org.neo4j.bolt.v1.messaging.RecordingByteChannel)1 BoltResponseHandler (org.neo4j.bolt.v1.runtime.BoltResponseHandler)1