@Test
  public void testValidDataSizeAfterDeletes() throws StoreException {
    assumeTrue(!bucketingEnabled);
    BlobStoreStats blobStoreStats = setupBlobStoreStats(0, 0);
    int numEntries =
        state.getMaxInMemElements() - state.referenceIndex.lastEntry().getValue().size() + state.getMaxInMemElements()
            - 2;
    state.addPutEntries(numEntries, PUT_RECORD_SIZE, Utils.Infinite_Time);

    long timeInMsBeforeDeletes = state.time.milliseconds();
    long totalLogSegmentValidSizeBeforeDeletes =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsBeforeDeletes, 0L));
    long totalContainerValidSizeBeforeDeletes =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsBeforeDeletes);

    // advance time to the next seconds before adding the deletes
    advanceTimeToNextSecond();
    // 2 deletes from the last index segment
    state.addDeleteEntry(state.getIdToDeleteFromIndexSegment(state.referenceIndex.lastKey(), false));
    state.addDeleteEntry(state.getIdToDeleteFromIndexSegment(state.referenceIndex.lastKey(), false));

    long expectedDeltaBeforeDeletesRelevant = 2 * DELETE_RECORD_SIZE;
    long totalLogSegmentValidSizeBeforeDeletesRelevant =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsBeforeDeletes, 0L));
    long totalContainerValidSizeBeforeDeletesRelevant =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsBeforeDeletes);
    assertEquals("Delete entries are not properly counted for log segment valid size",
        totalLogSegmentValidSizeBeforeDeletesRelevant,
        totalLogSegmentValidSizeBeforeDeletes + expectedDeltaBeforeDeletesRelevant);
    assertEquals("Delete entries are not properly counted for container valid size",
        totalContainerValidSizeBeforeDeletesRelevant, totalContainerValidSizeBeforeDeletes);

    // advance time to the next second for deletes/expiration to take effect
    advanceTimeToNextSecond();

    long timeInMsAfterDeletes = state.time.milliseconds();
    long totalLogSegmentValidSizeAfterDeletes =
        verifyAndGetLogSegmentValidSize(blobStoreStats, new TimeRange(timeInMsAfterDeletes, 0L));
    long totalContainerValidSizeAfterDeletes =
        verifyContainerStorageStatsAndGetTotalValidSize(blobStoreStats, timeInMsAfterDeletes);
    long expectedLogSegmentDecrement = 2 * (PUT_RECORD_SIZE - DELETE_RECORD_SIZE);
    long expectedContainerDecrement = 2 * PUT_RECORD_SIZE;
    assertEquals("Delete entries are not properly counted for log segment valid size",
        totalLogSegmentValidSizeAfterDeletes, totalLogSegmentValidSizeBeforeDeletes - expectedLogSegmentDecrement);
    assertEquals("Delete entries are not properly counted for container valid size",
        totalContainerValidSizeAfterDeletes, totalContainerValidSizeBeforeDeletes - expectedContainerDecrement);
    blobStoreStats.close();
  }
Tests to verify the correctness of reported stats with after new deletes via the following steps:
1. Add new puts that are going to be deleted later.
2. Verify reported stats and record the total valid size before new deletes.
3. Perform the deletes.
4. Verify reported stats after the deletes but at a time point before the deletes are relevant.
5. Verify reported stats and record the total valid size after the deletes.
6. Verify the delta of total valid size prior to the new deletes and after matches with the expected delta.
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/BlobStoreStatsTest.java