Search in sources :

Example 41 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testCancelDeregister.

@Test
public void testCancelDeregister() throws Exception {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    group.register(pipeline.channel());
    ChannelPromise promise = pipeline.channel().newPromise();
    assertTrue(promise.cancel(false));
    ChannelFuture future = pipeline.deregister(promise);
    assertTrue(future.isCancelled());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 42 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testAddReplaceHandlerCalledOnceRegistered.

@Test(timeout = 3000)
public void testAddReplaceHandlerCalledOnceRegistered() throws Throwable {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    CallbackCheckHandler handler = new CallbackCheckHandler();
    CallbackCheckHandler handler2 = new CallbackCheckHandler();
    pipeline.addFirst(handler);
    pipeline.replace(handler, null, handler2);
    assertNull(handler.addedHandler.getNow());
    assertNull(handler.removedHandler.getNow());
    assertNull(handler2.addedHandler.getNow());
    assertNull(handler2.removedHandler.getNow());
    group.register(pipeline.channel()).syncUninterruptibly();
    Throwable cause = handler.error.get();
    if (cause != null) {
        throw cause;
    }
    assertTrue(handler.addedHandler.get());
    assertTrue(handler.removedHandler.get());
    Throwable cause2 = handler2.error.get();
    if (cause2 != null) {
        throw cause2;
    }
    assertTrue(handler2.addedHandler.get());
    assertNull(handler2.removedHandler.getNow());
    pipeline.remove(handler2);
    assertTrue(handler2.removedHandler.get());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 43 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testLastContextEmptyPipeline.

@Test
public void testLastContextEmptyPipeline() throws Exception {
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    assertNull(pipeline.lastContext());
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) Test(org.junit.Test)

Example 44 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testUnorderedEventExecutor.

@Test(timeout = 3000)
public void testUnorderedEventExecutor() throws Throwable {
    ChannelPipeline pipeline1 = new LocalChannel().pipeline();
    EventExecutorGroup eventExecutors = new UnorderedThreadPoolEventExecutor(2);
    EventLoopGroup defaultGroup = new DefaultEventLoopGroup(1);
    try {
        EventLoop eventLoop1 = defaultGroup.next();
        eventLoop1.register(pipeline1.channel()).syncUninterruptibly();
        final CountDownLatch latch = new CountDownLatch(1);
        pipeline1.addLast(eventExecutors, new ChannelInboundHandlerAdapter() {

            @Override
            public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
                // Just block one of the two threads.
                LockSupport.park();
            }

            @Override
            public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
                latch.countDown();
            }
        });
        // Trigger an event, as we use UnorderedEventExecutor userEventTriggered should be called even when
        // handlerAdded(...) blocks.
        pipeline1.fireUserEventTriggered("");
        latch.await();
    } finally {
        defaultGroup.shutdownGracefully(0, 0, TimeUnit.SECONDS).syncUninterruptibly();
        eventExecutors.shutdownGracefully(0, 0, TimeUnit.SECONDS).syncUninterruptibly();
    }
}
Also used : DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) LocalChannel(io.netty.channel.local.LocalChannel) UnorderedThreadPoolEventExecutor(io.netty.util.concurrent.UnorderedThreadPoolEventExecutor) CountDownLatch(java.util.concurrent.CountDownLatch) OioEventLoopGroup(io.netty.channel.oio.OioEventLoopGroup) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.Test)

Example 45 with LocalChannel

use of io.netty.channel.local.LocalChannel in project netty by netty.

the class DefaultChannelPipelineTest method testAddRemoveHandlerNotRegistered.

@Test
public void testAddRemoveHandlerNotRegistered() throws Throwable {
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
    ChannelHandler handler = new ErrorChannelHandler(error);
    ChannelPipeline pipeline = new LocalChannel().pipeline();
    pipeline.addFirst(handler);
    pipeline.remove(handler);
    Throwable cause = error.get();
    if (cause != null) {
        throw cause;
    }
}
Also used : LocalChannel(io.netty.channel.local.LocalChannel) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

LocalChannel (io.netty.channel.local.LocalChannel)53 Test (org.junit.Test)49 LocalServerChannel (io.netty.channel.local.LocalServerChannel)16 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)14 LocalAddress (io.netty.channel.local.LocalAddress)14 Bootstrap (io.netty.bootstrap.Bootstrap)13 Channel (io.netty.channel.Channel)12 EventLoopGroup (io.netty.channel.EventLoopGroup)12 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)11 LocalEventLoopGroup (io.netty.channel.local.LocalEventLoopGroup)11 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)8 DefaultEventExecutorGroup (io.netty.util.concurrent.DefaultEventExecutorGroup)7 EventExecutorGroup (io.netty.util.concurrent.EventExecutorGroup)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 TimeoutException (java.util.concurrent.TimeoutException)7 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)4 ExpectedException (org.junit.rules.ExpectedException)4 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)3 OioSocketChannel (io.netty.channel.socket.oio.OioSocketChannel)3