@Test
  public void useAfterCloseTest() throws Exception {
    ByteBufferAsyncWritableChannel channel = new ByteBufferAsyncWritableChannel();
    channel.write(ByteBuffer.allocate(5), null);
    channel.getNextChunk();
    channel.close();
    assertFalse("Channel is still open", channel.isOpen());

    // ok to close again
    channel.close();

    // ok to resolve chunk
    channel.resolveOldestChunk(null);

    // not ok to write.
    WriteCallback writeCallback = new WriteCallback(0);
    try {
      channel.write(ByteBuffer.allocate(0), writeCallback).get();
      fail("Write should have failed");
    } catch (ExecutionException e) {
      Exception exception = (Exception) Utils.getRootCause(e);
      assertTrue("Unexpected exception (future)", exception instanceof ClosedChannelException);
      assertTrue("Unexpected exception (callback)", writeCallback.exception instanceof ClosedChannelException);
    }

    // no chunks on getNextChunk()
    assertNull("There should have been no chunk returned", channel.getNextChunk());
    assertNull("There should have been no chunk returned", channel.getNextChunk(0));
  }
Checks the case where a {@link ByteBufferAsyncWritableChannel} is used after it has been closed.
@throws Exception
ambry-commons/src/test/java/com/github/ambry/commons/ByteBufferAsyncWritableChannelTest.java