Example usage for io.netty.channel ChannelInboundHandler channelRead

List of usage examples for io.netty.channel ChannelInboundHandler channelRead

Introduction

In this page you can find the example usage for io.netty.channel ChannelInboundHandler channelRead.

Prototype

void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception;

Source Link

Document

Invoked when the current Channel has read a message from the peer.

Usage

From source file:org.anhonesteffort.chnlzr.ServerHandlerTest.java

License:Open Source License

@Test
public void testContextClosedOnChannelRequestAfterChannelAllocation() throws Exception {
    final ChnlzrServerConfig CONFIG = config();
    final SamplesSinkFactory SINK_FACTORY = Mockito.mock(SamplesSinkFactory.class);
    final SamplesSink SINK = Mockito.mock(SamplesSink.class);
    final SamplesSourceController SOURCE_CONTROLLER = Mockito.mock(SamplesSourceController.class);
    final ChannelSpec SPEC = ChannelSpec.fromMinMax(1337d, 9001d);

    Mockito.when(SOURCE_CONTROLLER.getCapabilities()).thenReturn(SPEC);
    Mockito.when(SOURCE_CONTROLLER.configureSourceForSink(Mockito.any())).thenReturn(0x00);

    Mockito.when(SINK.getSpec()).thenReturn(new ChannelSpec(1337d, 9001d));
    Mockito.when(SINK_FACTORY.create(Mockito.any(), Mockito.any())).thenReturn(SINK);

    final ChannelInboundHandler HANDLER = new ServerHandler(CONFIG, SINK_FACTORY, SOURCE_CONTROLLER);
    final EmbeddedChannel CHANNEL = new EmbeddedChannel(HANDLER);

    assert CHANNEL.readOutbound() != null;

    CHANNEL.writeInbound(request().getRoot(BaseMessage.factory).asReader());

    Mockito.verify(SOURCE_CONTROLLER, Mockito.times(1)).configureSourceForSink(Mockito.any());

    final ChannelHandlerContext CONTEXT = Mockito.mock(ChannelHandlerContext.class);
    HANDLER.channelRead(CONTEXT, request().getRoot(BaseMessage.factory).asReader());

    Mockito.verify(CONTEXT, Mockito.times(1)).close();
}