Search in sources :

Example 16 with DefaultEventLoopGroup

use of io.netty.channel.DefaultEventLoopGroup in project netty by netty.

the class LocalTransportThreadModelTest2 method testSocketReuse.

@Test(timeout = 15000)
public void testSocketReuse() throws InterruptedException {
    ServerBootstrap serverBootstrap = new ServerBootstrap();
    LocalHander serverHandler = new LocalHander("SERVER");
    serverBootstrap.group(new DefaultEventLoopGroup(), new DefaultEventLoopGroup()).channel(LocalServerChannel.class).childHandler(serverHandler);
    Bootstrap clientBootstrap = new Bootstrap();
    LocalHander clientHandler = new LocalHander("CLIENT");
    clientBootstrap.group(new DefaultEventLoopGroup()).channel(LocalChannel.class).remoteAddress(new LocalAddress(LOCAL_CHANNEL)).handler(clientHandler);
    serverBootstrap.bind(new LocalAddress(LOCAL_CHANNEL)).sync();
    int count = 100;
    for (int i = 1; i < count + 1; i++) {
        Channel ch = clientBootstrap.connect().sync().channel();
        // SPIN until we get what we are looking for.
        int target = i * messageCountPerRun;
        while (serverHandler.count.get() != target || clientHandler.count.get() != target) {
            Thread.sleep(50);
        }
        close(ch, clientHandler);
    }
    assertEquals(count * 2 * messageCountPerRun, serverHandler.count.get() + clientHandler.count.get());
}
Also used : Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Test(org.junit.Test)

Example 17 with DefaultEventLoopGroup

use of io.netty.channel.DefaultEventLoopGroup in project netty by netty.

the class LocalTransportThreadModelTest3 method init.

@BeforeClass
public static void init() {
    // Configure a test server
    group = new DefaultEventLoopGroup();
    ServerBootstrap sb = new ServerBootstrap();
    sb.group(group).channel(LocalServerChannel.class).childHandler(new ChannelInitializer<LocalChannel>() {

        @Override
        public void initChannel(LocalChannel ch) throws Exception {
            ch.pipeline().addLast(new ChannelInboundHandlerAdapter() {

                @Override
                public void channelRead(ChannelHandlerContext ctx, Object msg) {
                    // Discard
                    ReferenceCountUtil.release(msg);
                }
            });
        }
    });
    localAddr = (LocalAddress) sb.bind(LocalAddress.ANY).syncUninterruptibly().channel().localAddress();
}
Also used : ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) DefaultEventLoopGroup(io.netty.channel.DefaultEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)17 Channel (io.netty.channel.Channel)14 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)12 Bootstrap (io.netty.bootstrap.Bootstrap)10 EventLoopGroup (io.netty.channel.EventLoopGroup)9 LocalAddress (io.netty.channel.local.LocalAddress)9 LocalChannel (io.netty.channel.local.LocalChannel)9 LocalServerChannel (io.netty.channel.local.LocalServerChannel)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)8 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)7 Test (org.junit.Test)7 ChannelFuture (io.netty.channel.ChannelFuture)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 ChannelHandler (io.netty.channel.ChannelHandler)3 ChannelPipeline (io.netty.channel.ChannelPipeline)3 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)3 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)3 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)3 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 LocalEventLoopGroup (io.netty.channel.local.LocalEventLoopGroup)2