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());
}
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());
}
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());
}
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();
}
}
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;
}
}
Aggregations