@Test
  public void testChannelCloseBeforeWriting() {
    AmbrySendToHttp2Adaptor adaptor = new AmbrySendToHttp2Adaptor(true, 100);
    EmbeddedChannel channel = new EmbeddedChannel(adaptor);
    byte[] byteArray = new byte[100];
    new Random().nextBytes(byteArray);
    ByteBuf content = PooledByteBufAllocator.DEFAULT.heapBuffer(100).writeBytes(byteArray);

    // Get the context before closing the channel, since closing channel would remove all the context.
    ChannelHandlerContext ctx = channel.pipeline().firstContext();
    channel.close().getNow();
    adaptor.write(ctx, content, channel.newPromise());
  }
Test writing when the channel is closed.
ambry-network/src/test/java/com/github/ambry/network/http2/AmbrySendToHttp2AdaptorTest.java