private long verifyAndGetLogSegmentValidSize(BlobStoreStats blobStoreStats, TimeRange timeRange)
      throws StoreException {
    long expiryReferenceTime = state.time.milliseconds();
    Pair<Long, NavigableMap<LogSegmentName, Long>> actualLogSegmentValidSizeMap =
        blobStoreStats.getValidDataSizeByLogSegment(timeRange, expiryReferenceTime);
    assertTrue("Valid data size collection time should be in the range",
        timeRange.getStartTimeInMs() <= actualLogSegmentValidSizeMap.getFirst()
            && timeRange.getEndTimeInMs() >= actualLogSegmentValidSizeMap.getFirst());

    int expectedNumberOfLogSegments = 0;
    long expectedTotalLogSegmentValidSize = 0L;
    LogSegment logSegment = state.log.getFirstSegment();
    Pair<Set<MockId>, Set<MockId>> expiredDeletes = new Pair<>(new HashSet<>(), new HashSet<>());
    DeleteTombstoneStats.Builder builder = new DeleteTombstoneStats.Builder(state.time);
    while (logSegment != null) {
      LogSegmentName logSegmentName = logSegment.getName();
      assertTrue("Log segment: " + logSegmentName + " not found in TimeRange " + timeRange,
          actualLogSegmentValidSizeMap.getSecond().containsKey(logSegmentName));

      long expectedLogSegmentValidSize =
          state.getValidDataSizeForLogSegment(logSegment, timeRange.getEndTimeInMs(), expiryReferenceTime, null,
              builder, expiredDeletes, true);
      long actualLogSegmentValidSize = actualLogSegmentValidSizeMap.getSecond().get(logSegmentName);
      assertEquals("Valid data size mismatch for log segment: " + logSegmentName + " in TimeRange " + timeRange,
          expectedLogSegmentValidSize, actualLogSegmentValidSize);

      expectedTotalLogSegmentValidSize += expectedLogSegmentValidSize;
      expectedNumberOfLogSegments++;
      logSegment = state.log.getNextSegment(logSegment);
    }

    assertEquals("Mismatch in number of log segments", expectedNumberOfLogSegments,
        actualLogSegmentValidSizeMap.getSecond().size());

    Pair<Long, Long> actualTotalValidSize = blobStoreStats.getValidSize(timeRange);
    assertTrue("Returned collection time should be in the range",
        timeRange.getStartTimeInMs() <= actualTotalValidSize.getFirst()
            && timeRange.getEndTimeInMs() >= actualLogSegmentValidSizeMap.getFirst());
    assertEquals("Total valid data size of all log segments mismatch", expectedTotalLogSegmentValidSize,
        actualTotalValidSize.getSecond().longValue());
    verifyDeleteTombstoneStats(blobStoreStats, builder.build());
    return actualTotalValidSize.getSecond();
  }
Verify the correctness of valid data size information per log segment returned by BlobStoreStats for a given
{@link TimeRange} and return the total valid data size of all log segments.
@param blobStoreStats the {@link BlobStoreStats} to be verified
@param timeRange the {@link TimeRange} to be used for the verification
@return the total valid data size of all log segments
@throws StoreException
ambry-store/src/test/java/com/github/ambry/store/BlobStoreStatsTest.java