private void doAppendTest(Appender appender) throws IOException, StoreException {
    LogSegmentName currSegmentName = LogSegmentName.generateFirstSegmentName(false);
    LogSegment segment = getSegment(currSegmentName, BIG_SEGMENT_SIZE, true);
    segment.initBufferForAppend();
    try {
      long writeStartOffset = segment.getStartOffset();
      byte[] bufOne = TestUtils.getRandomBytes(BIG_SEGMENT_SIZE / 6);
      byte[] bufTwo = TestUtils.getRandomBytes(BIG_SEGMENT_SIZE / 9);
      byte[] bufThree = TestUtils.getRandomBytes(LogSegment.BYTE_BUFFER_SIZE_FOR_APPEND * 2 + 3);

      appender.append(segment, ByteBuffer.wrap(bufOne));
      assertEquals("End offset is not as expected", writeStartOffset + bufOne.length, segment.getEndOffset());

      appender.append(segment, ByteBuffer.wrap(bufTwo));
      assertEquals("End offset is not as expected", writeStartOffset + bufOne.length + bufTwo.length,
          segment.getEndOffset());

      appender.append(segment, ByteBuffer.wrap(bufThree));
      assertEquals("End offset is not as expected", writeStartOffset + bufOne.length + bufTwo.length + bufThree.length,
          segment.getEndOffset());

      // try to do a write that won't fit
      ByteBuffer failBuf = ByteBuffer.wrap(TestUtils.getRandomBytes((int) (BIG_SEGMENT_SIZE - writeStartOffset + 1)));
      long writeOverFlowCount = metrics.overflowWriteError.getCount();
      try {
        appender.append(segment, failBuf);
        fail("Append should have failed because data won't fit in the segment");
      } catch (IllegalArgumentException e) {
        assertEquals("Write overflow should have been reported", writeOverFlowCount + 1,
            metrics.overflowWriteError.getCount());
        assertEquals("Position of buffer has changed", 0, failBuf.position());
      }

      // read and ensure data matches
      readAndEnsureMatch(segment, writeStartOffset, bufOne);
      readAndEnsureMatch(segment, writeStartOffset + bufOne.length, bufTwo);
      readAndEnsureMatch(segment, writeStartOffset + bufOne.length + bufTwo.length, bufThree);
      readDirectlyAndEnsureMatch(segment, writeStartOffset, bufOne);
      readDirectlyAndEnsureMatch(segment, writeStartOffset + bufOne.length, bufTwo);
      readDirectlyAndEnsureMatch(segment, writeStartOffset + bufOne.length + bufTwo.length, bufThree);

      segment.close(false);
      // ensure that append fails.
      ByteBuffer buffer = ByteBuffer.wrap(TestUtils.getRandomBytes(1));
      try {
        appender.append(segment, buffer);
        fail("Append should have failed because segments are closed");
      } catch (StoreException e) {
        assertEquals("Position of buffer has changed", 0, buffer.position());
      }
    } finally {
      closeSegmentAndDeleteFile(segment);
    }
  }
Using the given {@code appender}'s {@link Appender#append(LogSegment, ByteBuffer)} function, tests for various
cases for append operations.
@param appender the {@link Appender} to use
@throws IOException
ambry-store/src/test/java/com/github/ambry/store/LogSegmentTest.java