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);
}
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();
}
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();
}
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;
}
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);
}
Aggregations