SimpleLoggerResultCallback implements FeedClient.ResultCallback { protected DocumentRate newSamplingPeriod(Instant now) { double docsDelta = resultCounter - failureCounter - startSampleResultCount; Duration duration = Duration.between(startSampleInstant, now); startSampleInstant = now; startSampleResultCount = resultCounter - failureCounter; long durationMilliSecs = duration.toMillis() + 1; return new DocumentRate(1000. * docsDelta / durationMilliSecs); } SimpleLoggerResultCallback(AtomicInteger sentDocumentCounter, int printStatsForEveryXDocument); void printProgress(); @Override void onCompletion(String docId, Result documentResult);  }
@Test public void testAverageCalculationExteremeValues() { SimpleLoggerResultCallback logger = new SimpleLoggerResultCallback(new AtomicInteger(3), 0); Instant now = Instant.now(); logger.newSamplingPeriod(now); double rate = logger.newSamplingPeriod(now).rate; assertEquals(rate, 0, 0.1 ); }