@Test
  public void testSegmentedLogInitWithExistingSegments() throws Exception {
    int totalSegments = 5, existingSegments = 2;
    long totalCapacity = totalSegments * SEGMENT_CAPACITY;

    for (int i = 0; i < existingSegments; i++) {
      File segmentFile = new File(tempDir, LogSegmentName.fromPositionAndGeneration(i, 0).toFilename());
      assert segmentFile.createNewFile();
    }
    DiskSpaceAllocator mockDiskSpaceAllocator = mock(DiskSpaceAllocator.class);
    StoreConfig storeConfig = createStoreConfig(SEGMENT_CAPACITY, setFilePermissionEnabled);

    Log log =
        new Log(tempDir.getAbsolutePath(), totalCapacity, mockDiskSpaceAllocator, storeConfig, metrics, null, false);

    long expectedRemainingSegments = totalSegments - existingSegments;
    assertEquals("Remaining unallocated segments mismatch", expectedRemainingSegments,
        log.getRemainingUnallocatedSegments());
  }
Tests the initialization of a segmented log when segments exist in the directory.
@throws Exception if an error occurs during the test.
ambry-store/src/test/java/com/github/ambry/store/LogTest.java