EmbeddedChannel extends AbstractChannel { public boolean finish() { close(); checkException(); return isNotEmpty(inboundMessages) || isNotEmpty(outboundMessages); } EmbeddedChannel();  EmbeddedChannel(ChannelId channelId);  EmbeddedChannel(ChannelHandler... handlers);  EmbeddedChannel(boolean hasDisconnect, ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, final ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, final ChannelHandler... handlers); @Override ChannelMetadata metadata(); @Override ChannelConfig config(); @Override boolean isOpen(); @Override boolean isActive(); Queue<Object> inboundMessages(); @Deprecated Queue<Object> lastInboundBuffer(); Queue<Object> outboundMessages(); @Deprecated Queue<Object> lastOutboundBuffer(); @SuppressWarnings("unchecked") T readInbound(); @SuppressWarnings("unchecked") T readOutbound(); boolean writeInbound(Object... msgs); boolean writeOutbound(Object... msgs); boolean finish(); @Override final ChannelFuture close(); @Override final ChannelFuture disconnect(); @Override final ChannelFuture close(ChannelPromise promise); @Override final ChannelFuture disconnect(ChannelPromise promise); void runPendingTasks(); long runScheduledPendingTasks(); void checkException();  }
@Test public void testScheduledCancelled() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter()); ScheduledFuture<?> future = ch.eventLoop().schedule(new Runnable() { @Override public void run() { } }, 1, TimeUnit.DAYS); ch.finish(); assertTrue(future.isCancelled()); }
@Test(timeout = 3000) public void testHandlerAddedExecutedInEventLoop() throws Throwable { final CountDownLatch latch = new CountDownLatch(1); final AtomicReference<Throwable> error = new AtomicReference<Throwable>(); final ChannelHandler handler = new ChannelHandlerAdapter() { @Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { try { assertTrue(ctx.executor().inEventLoop()); } catch (Throwable cause) { error.set(cause); } finally { latch.countDown(); } } }; EmbeddedChannel channel = new EmbeddedChannel(handler); assertFalse(channel.finish()); latch.await(); Throwable cause = error.get(); if (cause != null) { throw cause; } }