Search in sources :

Example 41 with ChannelHandlerContext

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project neo4j by neo4j.

the class SocketTransportHandlerTest method shouldInitializeProtocolOnFirstMessage.

@Test
public void shouldInitializeProtocolOnFirstMessage() throws Exception {
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ProtocolChooser chooser = protocolChooser(machine);
    ChannelHandlerContext context = channelHandlerContextMock();
    SocketTransportHandler handler = new SocketTransportHandler(chooser, NullLogProvider.getInstance());
    handler.channelRead(context, handshake());
    BoltProtocol protocol1 = chooser.chosenProtocol();
    handler.channelRead(context, handshake());
    BoltProtocol protocol2 = chooser.chosenProtocol();
    assertSame(protocol1, protocol2);
}
Also used : BoltProtocol(org.neo4j.bolt.transport.BoltProtocol) BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) Test(org.junit.Test)

Example 42 with ChannelHandlerContext

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project neo4j by neo4j.

the class SocketTransportHandlerTest method shouldCloseContextWhenProtocolNotInitializedOnHandlerRemoved.

@Test
public void shouldCloseContextWhenProtocolNotInitializedOnHandlerRemoved() throws Throwable {
    // Given
    ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    SocketTransportHandler handler = newSocketTransportHandler(mock(ProtocolChooser.class));
    // When
    handler.handlerRemoved(context);
    // Then
    verify(context).close();
}
Also used : SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProtocolChooser(org.neo4j.bolt.transport.ProtocolChooser) Test(org.junit.Test)

Example 43 with ChannelHandlerContext

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project neo4j by neo4j.

the class SocketTransportHandlerTest method shouldCloseProtocolOnChannelInactive.

@Test
public void shouldCloseProtocolOnChannelInactive() throws Throwable {
    // Given
    BoltStateMachine machine = mock(BoltStateMachine.class);
    ChannelHandlerContext ctx = channelHandlerContextMock();
    SocketTransportHandler handler = newSocketTransportHandler(protocolChooser(machine));
    // And Given a session has been established
    handler.channelRead(ctx, handshake());
    // When
    handler.channelInactive(ctx);
    // Then
    verify(machine).close();
}
Also used : BoltStateMachine(org.neo4j.bolt.v1.runtime.BoltStateMachine) SocketTransportHandler(org.neo4j.bolt.transport.SocketTransportHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) Test(org.junit.Test)

Example 44 with ChannelHandlerContext

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project neo4j by neo4j.

the class SocketTransportHandlerTest method channelHandlerContextMock.

private static ChannelHandlerContext channelHandlerContextMock() {
    Channel channel = mock(Channel.class);
    ChannelHandlerContext context = mock(ChannelHandlerContext.class);
    when(context.channel()).thenReturn(channel);
    when(channel.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
    when(context.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
    return context;
}
Also used : Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext)

Example 45 with ChannelHandlerContext

use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext in project neo4j by neo4j.

the class RequestDecoderDispatcherTest method shouldDispatchToRegisteredDecoder.

@Test
public void shouldDispatchToRegisteredDecoder() throws Exception {
    // given
    RequestDecoderDispatcher<State> dispatcher = new RequestDecoderDispatcher<>(protocol, logProvider);
    ChannelInboundHandler delegateOne = mock(ChannelInboundHandler.class);
    ChannelInboundHandler delegateTwo = mock(ChannelInboundHandler.class);
    ChannelInboundHandler delegateThree = mock(ChannelInboundHandler.class);
    dispatcher.register(State.one, delegateOne);
    dispatcher.register(State.two, delegateTwo);
    dispatcher.register(State.three, delegateThree);
    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    Object msg = new Object();
    // when
    dispatcher.channelRead(ctx, msg);
    // then
    verify(delegateTwo).channelRead(ctx, msg);
    verifyNoMoreInteractions(delegateTwo);
    verifyZeroInteractions(delegateOne, delegateThree);
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelInboundHandler(io.netty.channel.ChannelInboundHandler) Test(org.junit.Test)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)661 Channel (io.netty.channel.Channel)274 ByteBuf (io.netty.buffer.ByteBuf)234 ChannelFuture (io.netty.channel.ChannelFuture)210 Test (org.junit.Test)208 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)201 Bootstrap (io.netty.bootstrap.Bootstrap)177 InetSocketAddress (java.net.InetSocketAddress)160 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)156 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)154 Test (org.junit.jupiter.api.Test)153 ChannelPipeline (io.netty.channel.ChannelPipeline)151 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)141 AtomicReference (java.util.concurrent.atomic.AtomicReference)140 IOException (java.io.IOException)137 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)120 ClosedChannelException (java.nio.channels.ClosedChannelException)119 CountDownLatch (java.util.concurrent.CountDownLatch)115 ArrayList (java.util.ArrayList)113 List (java.util.List)111