@Test
  public void testWeightOnBenefitStatsBasedCompactionGetCompactionDetails() throws Exception {
    long logSegmentCount = blobStore.capacityInBytes / blobStore.segmentCapacity;
    // the test is designed to use for 10 log segments.
    assertEquals(logSegmentCount, 10);

    /**
     * test the fine tuned stats based compaction which weighs more the benefits
     */
    // existing stats base compaction will prefer the compaction group with least IO effort.
    // the new compaction weights more on the compaction benefits as long as the IO effort is reasonable.
    blobStore.logSegmentsNotInJournal = CompactionPolicyTest.generateRandomLogSegmentName((int) logSegmentCount);
    double[] validPercentage = {0.9, 0.8, 0.05, 0.01, 0.01, 0.05, 0.1, 0.2, 0.4, 0.7};
    // with the existing stats based compaction, we'll compact two log segments.
    int[] expectedCandidateIndex = {3, 4};
    verifyMiddleRangeCompactionDetails(blobStore.logSegmentsNotInJournal, validPercentage, expectedCandidateIndex);

    Properties benefitBasedCompactionProperties = new Properties();
    // enable the stats based compaction which weights more on the benefit
    benefitBasedCompactionProperties.setProperty("store.stats.based.weight.on.benefit.enabled", "true");
    setupBlobStore(benefitBasedCompactionProperties);
    blobStore.logSegmentsNotInJournal = CompactionPolicyTest.generateRandomLogSegmentName((int) logSegmentCount);

    // with the tuned stats based compaction, we'll compact four log segment.
    // by default store.stats.based.compaction.min.cost.in.percentage = 0.06
    // the log segments which has less than 6% valid data are all picked.
    expectedCandidateIndex = new int[]{2, 3, 4, 5};
    verifyMiddleRangeCompactionDetails(blobStore.logSegmentsNotInJournal, validPercentage, expectedCandidateIndex);
  }
Test the benefits oriented stats cost tuning
@throws StoreException, InterruptedException
ambry-store/src/test/java/com/github/ambry/store/StatsBasedCompactionPolicyTest.java