@Test
  public void channelInactiveTest() {
    // request is keep-alive by default.
    HttpRequest request = createRequestWithHeaders(HttpMethod.GET, TestingUri.Close.toString());
    ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler();
    EmbeddedChannel channel = new EmbeddedChannel(chunkedWriteHandler);
    VerifiableProperties verifiableProperties = new VerifiableProperties(new Properties());
    NettyResponseChannel nettyResponseChannel =
        new NettyResponseChannel(new MockChannelHandlerContext(channel), new NettyMetrics(new MetricRegistry()),
            new PerformanceConfig(verifiableProperties), new NettyConfig(verifiableProperties));
    channel.disconnect().awaitUninterruptibly();
    assertFalse("Channel should be closed", channel.isOpen());
    Future<Long> future = nettyResponseChannel.write(Unpooled.buffer(1), null);
    try {
      future.get();
      fail("Future.get() should throw exception.");
    } catch (InterruptedException | ExecutionException e) {
      assertTrue("Should be ClosedChannelException", e.getCause() instanceof ClosedChannelException);
    }
  }
ClosedChannelException is expected when write to a NettyResponseChannel and channel is inactive.
ambry-rest/src/test/java/com/github/ambry/rest/NettyResponseChannelTest.java