Search in sources :

Example 1 with ServerSocketChannel

use of io.netty.channel.socket.ServerSocketChannel in project netty by netty.

the class AbstractEventLoopTest method testReregister.

/**
     * Test for https://github.com/netty/netty/issues/803
     */
@Test
public void testReregister() {
    EventLoopGroup group = newEventLoopGroup();
    EventLoopGroup group2 = newEventLoopGroup();
    final EventExecutorGroup eventExecutorGroup = new DefaultEventExecutorGroup(2);
    ServerBootstrap bootstrap = new ServerBootstrap();
    ChannelFuture future = bootstrap.channel(newChannel()).group(group).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        public void initChannel(SocketChannel ch) throws Exception {
        }
    }).handler(new ChannelInitializer<ServerSocketChannel>() {

        @Override
        public void initChannel(ServerSocketChannel ch) throws Exception {
            ch.pipeline().addLast(new TestChannelHandler());
            ch.pipeline().addLast(eventExecutorGroup, new TestChannelHandler2());
        }
    }).bind(0).awaitUninterruptibly();
    EventExecutor executor = future.channel().pipeline().context(TestChannelHandler2.class).executor();
    EventExecutor executor1 = future.channel().pipeline().context(TestChannelHandler.class).executor();
    future.channel().deregister().awaitUninterruptibly();
    Channel channel = group2.register(future.channel()).awaitUninterruptibly().channel();
    EventExecutor executorNew = channel.pipeline().context(TestChannelHandler.class).executor();
    assertNotSame(executor1, executorNew);
    assertSame(executor, future.channel().pipeline().context(TestChannelHandler2.class).executor());
}
Also used : DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) EventExecutor(io.netty.util.concurrent.EventExecutor) ServerSocketChannel(io.netty.channel.socket.ServerSocketChannel) Test(org.junit.Test)

Aggregations

ServerBootstrap (io.netty.bootstrap.ServerBootstrap)1 ServerSocketChannel (io.netty.channel.socket.ServerSocketChannel)1 SocketChannel (io.netty.channel.socket.SocketChannel)1 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)1 EventExecutor (io.netty.util.concurrent.EventExecutor)1 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)1 Test (org.junit.Test)1