ValidationManager { public static int countMissingSegments(long[] sortedStartTimes, TimeUnit frequency) { if (sortedStartTimes.length < 2) { return 0; } final long frequencyMillis = frequency.toMillis(1); final long halfFrequencyMillis = frequencyMillis / 2; final long firstStartTime = sortedStartTimes[0]; final long lastStartTime = sortedStartTimes[sortedStartTimes.length - 1]; final int expectedSegmentCount = (int) ((lastStartTime + halfFrequencyMillis - firstStartTime) / frequencyMillis); int missingSegments = 0; int currentIndex = 1; for (int expectedIntervalCount = 1; expectedIntervalCount <= expectedSegmentCount;) { final int intervalCount = (int) ((sortedStartTimes[currentIndex] + halfFrequencyMillis - firstStartTime) / frequencyMillis); if (intervalCount == expectedIntervalCount) { ++expectedIntervalCount; ++currentIndex; } else { if (intervalCount < expectedIntervalCount) { ++currentIndex; } else { missingSegments += intervalCount - expectedIntervalCount; expectedIntervalCount = intervalCount + 1; ++currentIndex; } } } return missingSegments; } ValidationManager(ValidationMetrics validationMetrics, PinotHelixResourceManager pinotHelixResourceManager,
      ControllerConf config); void start(); void stop(); void runValidation(); static List<Interval> computeMissingIntervals(List<Interval> segmentIntervals, Duration frequency); static int countMissingSegments(long[] sortedStartTimes, TimeUnit frequency);  }
@Test public void testCountMissingSegments() { ValidationManager.countMissingSegments(new long[0], TimeUnit.DAYS); ValidationManager.countMissingSegments(new long[1], TimeUnit.DAYS); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 2, 22, 0).toInstant().getMillis(), }, TimeUnit.DAYS), 0); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 2, 22, 0).toInstant().getMillis(), new DateTime(2014, 1, 3, 22, 0) .toInstant().getMillis(), new DateTime(2014, 1, 4, 22, 0).toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 0).toInstant().getMillis(), }, TimeUnit.DAYS), 0); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 2, 21, 0).toInstant().getMillis(), new DateTime(2014, 1, 3, 23, 0) .toInstant().getMillis(), new DateTime(2014, 1, 4, 21, 5).toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 0); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 2, 21, 0).toInstant().getMillis(), new DateTime(2014, 1, 3, 22, 0) .toInstant().getMillis(), new DateTime(2014, 1, 3, 23, 0).toInstant().getMillis(), new DateTime(2014, 1, 4, 21, 5).toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 0); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 2, 21, 0).toInstant().getMillis(), new DateTime(2014, 1, 4, 21, 5) .toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 1); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 3, 22, 0).toInstant().getMillis(), new DateTime(2014, 1, 3, 23, 0) .toInstant().getMillis(), new DateTime(2014, 1, 4, 21, 5).toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 1); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 3, 23, 0).toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15) .toInstant().getMillis(), }, TimeUnit.DAYS), 2); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 0).toInstant() .getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 3); Assert.assertEquals(ValidationManager.countMissingSegments(new long[] { new DateTime(2014, 1, 1, 22, 25) .toInstant().getMillis(), new DateTime(2014, 1, 5, 22, 15).toInstant().getMillis(), }, TimeUnit.DAYS), 3); }