@Test
  public void testStoreFileChunkToBuffer() throws IOException {
    String fileName = "testFile";
    long fileSize = 12345L;
    ByteBuf byteBuf = Unpooled.buffer();
    byteBuf.writeBytes(fileName.getBytes());
    byteBuf.writeLong(fileSize);
    DataInputStream fileStream = new DataInputStream(new ByteBufferInputStream(byteBuf.nioBuffer()));

    // Create a StoreFileChunk object and write it to a byte buffer
    StoreFileChunk storeFileChunk = new StoreFileChunk(fileStream, fileStream.available());
    ByteBuffer storeFileChunkByteBuffer = storeFileChunk.toBuffer();
    ByteBuf storeFileChunkBuf = Unpooled.wrappedBuffer(storeFileChunkByteBuffer);

    // Assert that the byte buffer has the correct values
    Assert.assertEquals(fileName, storeFileChunkBuf.readCharSequence(fileName.length(), StandardCharsets.UTF_8));
    Assert.assertEquals(fileSize, storeFileChunkBuf.readLong());
    Assert.assertEquals(fileStream.available(), storeFileChunkBuf.readableBytes());
    byteBuf.release();
  }
Test the {@link StoreFileChunk#toBuffer} method.
@throws IOException
ambry-protocol/src/test/java/com/github/ambry/protocol/RequestResponseTest.java