private void sourceSmallerThanChannelBufferTest() throws ClosedChannelException {
    byte[] in = new byte[1024];
    byte[] out = new byte[2048];
    ByteBuffer inBuf = ByteBuffer.wrap(in);
    ByteBufferChannel channel = new ByteBufferChannel(ByteBuffer.wrap(out));
    ByteBuffer outBuf = channel.getBuffer();

    new Random().nextBytes(in);
    assertEquals("Bytes written is not as expected", inBuf.capacity(), channel.write(inBuf));
    assertArrayEquals("Bytes read from channel not equal to bytes written into channel", inBuf.array(),
        Arrays.copyOfRange(outBuf.array(), 0, 1024));
    assertEquals("No data should have been written into the channel", 0, channel.write(inBuf));

    new Random().nextBytes(in);
    inBuf.rewind();
    assertEquals("Bytes written is not as expected", inBuf.capacity(), channel.write(inBuf));
    assertArrayEquals("Bytes read from channel not equal to bytes written into channel", inBuf.array(),
        Arrays.copyOfRange(outBuf.array(), 1024, 2048));
    assertEquals("No data should have been written into the channel", 0, channel.write(inBuf));
  }
Checks the case where a {@link ByteBufferChannel} is used after it has been closed.
@throws ClosedChannelException
ambry-utils/src/test/java/com/github/ambry/utils/ByteBufferChannelTest.java