Search in sources :

Example 1 with ChannelGroup

use of io.netty.channel.group.ChannelGroup in project netty by netty.

the class ThreadPerChannelEventLoopGroupTest method runTest.

private static void runTest(ThreadPerChannelEventLoopGroup loopGroup) throws InterruptedException {
    int taskCount = 100;
    EventExecutor testExecutor = new TestEventExecutor();
    ChannelGroup channelGroup = new DefaultChannelGroup(testExecutor);
    while (taskCount-- > 0) {
        Channel channel = new EmbeddedChannel(NOOP_HANDLER);
        loopGroup.register(new DefaultChannelPromise(channel, testExecutor));
        channelGroup.add(channel);
    }
    channelGroup.close().sync();
    loopGroup.shutdownGracefully(100, 200, TimeUnit.MILLISECONDS).sync();
    assertTrue(loopGroup.isTerminated());
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) EventExecutor(io.netty.util.concurrent.EventExecutor) SingleThreadEventExecutor(io.netty.util.concurrent.SingleThreadEventExecutor) GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup)

Example 2 with ChannelGroup

use of io.netty.channel.group.ChannelGroup in project riposte by Nike-Inc.

the class HttpChannelInitializerTest method initChannel_adds_OpenChannelLimitHandler_after_RequestInfoSetterHandler_and_uses_cached_ChannelGroup.

@Test
public void initChannel_adds_OpenChannelLimitHandler_after_RequestInfoSetterHandler_and_uses_cached_ChannelGroup() {
    // given
    HttpChannelInitializer hci = basicHttpChannelInitializer(null, 0, 42, false, null, null);
    // when
    hci.initChannel(socketChannelMock);
    // then
    ArgumentCaptor<ChannelHandler> channelHandlerArgumentCaptor = ArgumentCaptor.forClass(ChannelHandler.class);
    verify(channelPipelineMock, atLeastOnce()).addLast(anyString(), channelHandlerArgumentCaptor.capture());
    List<ChannelHandler> handlers = channelHandlerArgumentCaptor.getAllValues();
    Pair<Integer, RequestInfoSetterHandler> requestInfoSetterHandler = findChannelHandler(handlers, RequestInfoSetterHandler.class);
    Pair<Integer, OpenChannelLimitHandler> openChannelLimitHandler = findChannelHandler(handlers, OpenChannelLimitHandler.class);
    assertThat(requestInfoSetterHandler, notNullValue());
    assertThat(openChannelLimitHandler, notNullValue());
    assertThat(openChannelLimitHandler.getLeft(), is(requestInfoSetterHandler.getLeft() + 1));
    // and then
    ChannelGroup expectedChannelGroup = extractField(hci, "openChannelsGroup");
    ChannelGroup actualChannelGroup = (ChannelGroup) Whitebox.getInternalState(openChannelLimitHandler.getRight(), "openChannelsGroup");
    assertThat(actualChannelGroup, is(expectedChannelGroup));
}
Also used : RequestInfoSetterHandler(com.nike.riposte.server.handler.RequestInfoSetterHandler) ChannelHandler(io.netty.channel.ChannelHandler) OpenChannelLimitHandler(com.nike.riposte.server.handler.OpenChannelLimitHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) Test(org.junit.Test)

Aggregations

ChannelGroup (io.netty.channel.group.ChannelGroup)2 OpenChannelLimitHandler (com.nike.riposte.server.handler.OpenChannelLimitHandler)1 RequestInfoSetterHandler (com.nike.riposte.server.handler.RequestInfoSetterHandler)1 ChannelHandler (io.netty.channel.ChannelHandler)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)1 EventExecutor (io.netty.util.concurrent.EventExecutor)1 GlobalEventExecutor (io.netty.util.concurrent.GlobalEventExecutor)1 SingleThreadEventExecutor (io.netty.util.concurrent.SingleThreadEventExecutor)1 Test (org.junit.Test)1