public void writeToChannel(int writeCount) {
    for (int i = 0; i < writeCount; i++) {
      WriteCallback writeCallback = new WriteCallback(i);
      byte[] data = new byte[100];
      random.nextBytes(data);
      Future<Long> future = null;
      if (useNettyByteBuf) {
        ByteBuf chunk = null;
        if (!useCompositeByteBuf) {
          chunk = ByteBufAllocator.DEFAULT.heapBuffer(data.length);
          chunk.writeBytes(data);
        } else {
          CompositeByteBuf composite = ByteBufAllocator.DEFAULT.compositeHeapBuffer(100);
          ByteBuf c = ByteBufAllocator.DEFAULT.heapBuffer(50);
          c.writeBytes(data, 0, 50);
          composite.addComponent(true, c);
          c = ByteBufAllocator.DEFAULT.heapBuffer(50);
          c.writeBytes(data, 50, 50);
          composite.addComponent(true, c);
          chunk = composite;
        }
        final ByteBuf finalByteBuf = chunk;
        future = channel.write(finalByteBuf, (result, exception) -> {
          finalByteBuf.release();
          writeCallback.onCompletion(result, exception);
        });
      } else {
        ByteBuffer chunk = ByteBuffer.wrap(data);
        future = channel.write(chunk, writeCallback);
      }
      writes.add(new WriteData(data, future, writeCallback));
    }
  }
Writes {@code writeCount} number of random chunks to the given {@link ByteBufferAsyncWritableChannel}.
@param writeCount the number of chunks to write.
ambry-commons/src/test/java/com/github/ambry/commons/ByteBufferAsyncWritableChannelTest.java