private Pair<LogSegment, FileChannel> getSegmentAndFileChannel(String name) throws Exception {
    File file = new File(tempDir, name);
    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();
    FileChannel fileChannel = Utils.openChannel(file, true);
    FileChannel mockFileChannel = Mockito.spy(fileChannel);
    LogSegment segment = new LogSegment(file, STANDARD_SEGMENT_SIZE, config, metrics, mockFileChannel);
    return new Pair<>(segment, mockFileChannel);
  }
Create a {@link LogSegment} and a mock file channel associated with it for testing.
@param name the name of log segment file.
@return a pair that contains log segment and mock file channel
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/LogSegmentTest.java