@Test public void testWriteFailsFastOnClosedChannel() throws Exception { Bootstrap cb = new Bootstrap(); ServerBootstrap sb = new ServerBootstrap(); cb.group(group1) .channel(LocalChannel.class) .handler(new TestHandler()); sb.group(group2) .channel(LocalServerChannel.class) .childHandler(new ChannelInitializer<LocalChannel>() { @Override public void initChannel(LocalChannel ch) throws Exception { ch.pipeline().addLast(new TestHandler()); } }); Channel sc = null; Channel cc = null; try { sc = sb.bind(TEST_ADDRESS).sync().channel(); cc = cb.connect(sc.localAddress()).sync().channel(); cc.close().sync(); try { cc.writeAndFlush(new Object()).sync(); fail("must raise a ClosedChannelException"); } catch (Exception e) { assertThat(e, is(instanceOf(ClosedChannelException.class))); if (e.getStackTrace().length > 0) { assertThat( e.getStackTrace()[0].getClassName(), is(AbstractChannel.class.getName() + "$AbstractUnsafe")); e.printStackTrace(); } } } finally { closeChannel(cc); closeChannel(sc); } }
@Override public LocalAddress localAddress() { return (LocalAddress) super.localAddress(); }
LocalChannel extends AbstractChannel { @Override public LocalAddress localAddress() { return (LocalAddress) super.localAddress(); } }
LocalChannel extends AbstractChannel { @Override public LocalAddress localAddress() { return (LocalAddress) super.localAddress(); } LocalChannel(); protected  LocalChannel(LocalServerChannel parent, LocalChannel peer); }
LocalChannel extends AbstractChannel { @Override public LocalAddress localAddress() { return (LocalAddress) super.localAddress(); } LocalChannel(); protected  LocalChannel(LocalServerChannel parent, LocalChannel peer); @Override ChannelMetadata metadata(); @Override ChannelConfig config(); @Override LocalServerChannel parent(); @Override LocalAddress localAddress(); @Override LocalAddress remoteAddress(); @Override boolean isOpen(); @Override boolean isActive(); }
LocalChannel extends AbstractChannel { @Override public LocalAddress localAddress() { return (LocalAddress) super.localAddress(); } LocalChannel(); protected  LocalChannel(LocalServerChannel parent, LocalChannel peer); @Override ChannelMetadata metadata(); @Override ChannelConfig config(); @Override LocalServerChannel parent(); @Override LocalAddress localAddress(); @Override LocalAddress remoteAddress(); @Override boolean isOpen(); @Override boolean isActive();  }