EmbeddedChannel extends AbstractChannel { @Override public final ChannelFuture close() { return close(newPromise()); } EmbeddedChannel();  EmbeddedChannel(ChannelId channelId);  EmbeddedChannel(ChannelHandler... handlers);  EmbeddedChannel(boolean hasDisconnect, ChannelHandler... handlers);  EmbeddedChannel(boolean register, boolean hasDisconnect, ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, boolean register, boolean hasDisconnect,
                           final ChannelHandler... handlers);  EmbeddedChannel(ChannelId channelId, boolean hasDisconnect, final ChannelConfig config,
                           final ChannelHandler... handlers); void register(); @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); ChannelFuture writeOneInbound(Object msg); ChannelFuture writeOneInbound(Object msg, ChannelPromise promise); EmbeddedChannel flushInbound(); boolean writeOutbound(Object... msgs); ChannelFuture writeOneOutbound(Object msg); ChannelFuture writeOneOutbound(Object msg, ChannelPromise promise); EmbeddedChannel flushOutbound(); boolean finish(); boolean finishAndReleaseAll(); boolean releaseInbound(); boolean releaseOutbound(); @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(); @Override Unsafe unsafe();  }
@Test(timeout = 2000) public void testFireChannelInactiveAndUnregisteredOnClose() throws InterruptedException { testFireChannelInactiveAndUnregistered(new Action() { @Override public ChannelFuture doRun(Channel channel) { return channel.close(); } }); testFireChannelInactiveAndUnregistered(new Action() { @Override public ChannelFuture doRun(Channel channel) { return channel.close(channel.newPromise()); } }); }
@Test(timeout = 5000) public void testChannelInactiveFired() throws InterruptedException { final AtomicBoolean inactive = new AtomicBoolean(); EmbeddedChannel channel = new EmbeddedChannel(new ChannelInboundHandlerAdapter() { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.close(); } @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { inactive.set(true); } }); channel.pipeline().fireExceptionCaught(new IllegalStateException()); assertTrue(inactive.get()); }
@Test(timeout = 2000) public void promiseDoesNotInfiniteLoop() throws InterruptedException { EmbeddedChannel channel = new EmbeddedChannel(); channel.closeFuture().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { future.channel().close(); } }); channel.close().syncUninterruptibly(); }