@Test
  public void testValidDataSizeAfterUndeletes() throws Exception {
    assumeTrue(!bucketingEnabled);
    BlobStoreStats blobStoreStats = setupBlobStoreStats(0, 0);

    // Undelete two deleted blob, it will bring two PUT blob back to life.
    List<IndexEntry> puts = state.addPutEntries(2, PUT_RECORD_SIZE, Utils.Infinite_Time);
    advanceTimeToNextSecond();
    MockId firstId = (MockId) puts.get(0).getKey();
    MockId secondId = (MockId) puts.get(1).getKey();
    // Now add a TTL_UPDATE record for first ID
    state.makePermanent(firstId, false);

    // Now delete those two
    state.addDeleteEntry(firstId);
    state.addDeleteEntry(secondId);
    // Make sure deletes are taking effect
    advanceTimeToNextSecond();

    long timeInMsBeforeUndeletes = state.time.milliseconds();
    long totalLogSegmentValidSizeBeforeUndeletes =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsBeforeUndeletes, 0L));
    long totalContainerValidSizeBeforeUndeletes =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsBeforeUndeletes);

    state.addUndeleteEntry(firstId);
    state.addUndeleteEntry(secondId);

    long timeInMsAfterUndeletes = state.time.milliseconds();
    long expectedContainerIncrement = 2 * PUT_RECORD_SIZE;
    long expectedLogSegmentIncrement =
        2 * PUT_RECORD_SIZE - 2 * DELETE_RECORD_SIZE + 2 * UNDELETE_RECORD_SIZE + TTL_UPDATE_RECORD_SIZE;
    long totalLogSegmentValidSizeAfterUndeletes =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsAfterUndeletes, 0L));
    long totalContainerValidSizeAfterUndeletes =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsAfterUndeletes);
    assertEquals("Undelete entries are not properly counted for container valid size",
        totalContainerValidSizeAfterUndeletes, totalContainerValidSizeBeforeUndeletes + expectedContainerIncrement);
    assertEquals("Undelete entries are not properly counted for log segment valid size",
        totalLogSegmentValidSizeAfterUndeletes, totalLogSegmentValidSizeBeforeUndeletes + expectedLogSegmentIncrement);

    // Add another UNDELETE to second ID would not change validSize
    state.addDeleteEntry(secondId, null, (short) 2);
    totalLogSegmentValidSizeAfterUndeletes =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsAfterUndeletes, 0L));
    totalContainerValidSizeAfterUndeletes =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsAfterUndeletes);
    assertEquals("Undelete entries are not properly counted for container valid size",
        totalContainerValidSizeAfterUndeletes, totalContainerValidSizeBeforeUndeletes + expectedContainerIncrement);
    assertEquals("Undelete entries are not properly counted for log segment valid size",
        totalLogSegmentValidSizeAfterUndeletes, totalLogSegmentValidSizeBeforeUndeletes + expectedLogSegmentIncrement);
    blobStoreStats.close();
  }
Tests to verify the correctness of reported stats with after new undeletes via the following steps:
1. Add new 2 new PUTs and 1 TTL_UPDATE
2. Delete these 2 newly added PUTs
3. Verify reported stats and records the total valid size before new undeletes.
4. Undelete these 2 PUTs.
5. Verify reported stats and record the total valid size after the undeletes.
6. Verify the delta of the total valid size prior to the new undeletes matches the expected value.
@throws Exception
ambry-store/src/test/java/com/github/ambry/store/BlobStoreStatsTest.java