private LogSegment getSegment(LogSegmentName segmentName, long capacityInBytes, boolean writeHeaders)
      throws IOException, StoreException {
    File file = new File(tempDir, segmentName.toFilename());
    if (file.exists()) {
      assertTrue(file.getAbsolutePath() + " already exists and could not be deleted", file.delete());
    }
    assertTrue("Segment file could not be created at path " + file.getAbsolutePath(), file.createNewFile());
    file.deleteOnExit();
    try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
      return new LogSegment(segmentName, file, capacityInBytes, config, metrics, writeHeaders);
    }
  }
Creates and gets a {@link LogSegment}.
@param segmentName the name of the segment as well as the file backing the segment.
@param capacityInBytes the capacity of the file/segment.
@param writeHeaders if {@code true}, writes headers for the segment.
@return instance of {@link LogSegment} that is backed by the file with name {@code segmentName} of capacity
{@code capacityInBytes}.
@throws IOException
ambry-store/src/test/java/com/github/ambry/store/LogSegmentTest.java