@Test public void shouldCalculateNextHitWithRollingTimeWindows() throws Exception { indexerConfigMock.setHitLimitResetTime(null); Instant firstInWindow = Instant.now().minus(12, ChronoUnit.HOURS); LocalDateTime nextHit = testee.calculateNextPossibleHit(indexerConfigMock, firstInWindow); assertEquals(LocalDateTime.ofInstant(firstInWindow, ZoneOffset.UTC).plus(24, ChronoUnit.HOURS), nextHit); }
LocalDateTime calculateNextPossibleHit(IndexerConfig indexerConfig, Instant firstInWindowAccessTime) { LocalDateTime nextPossibleHit; if (indexerConfig.getHitLimitResetTime().isPresent()) { LocalDateTime now = LocalDateTime.now(clock); nextPossibleHit = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()).with(ChronoField.MINUTE_OF_HOUR, 0); if (nextPossibleHit.isBefore(now)) { nextPossibleHit = nextPossibleHit.plus(1, ChronoUnit.DAYS); } } else { nextPossibleHit = LocalDateTime.ofInstant(firstInWindowAccessTime, ZoneOffset.UTC).plus(1, ChronoUnit.DAYS); } return nextPossibleHit; }
IndexerForSearchSelector { LocalDateTime calculateNextPossibleHit(IndexerConfig indexerConfig, Instant firstInWindowAccessTime) { LocalDateTime nextPossibleHit; if (indexerConfig.getHitLimitResetTime().isPresent()) { LocalDateTime now = LocalDateTime.now(clock); nextPossibleHit = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()).with(ChronoField.MINUTE_OF_HOUR, 0); if (nextPossibleHit.isBefore(now)) { nextPossibleHit = nextPossibleHit.plus(1, ChronoUnit.DAYS); } } else { nextPossibleHit = LocalDateTime.ofInstant(firstInWindowAccessTime, ZoneOffset.UTC).plus(1, ChronoUnit.DAYS); } return nextPossibleHit; } }
IndexerForSearchSelector { LocalDateTime calculateNextPossibleHit(IndexerConfig indexerConfig, Instant firstInWindowAccessTime) { LocalDateTime nextPossibleHit; if (indexerConfig.getHitLimitResetTime().isPresent()) { LocalDateTime now = LocalDateTime.now(clock); nextPossibleHit = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()).with(ChronoField.MINUTE_OF_HOUR, 0); if (nextPossibleHit.isBefore(now)) { nextPossibleHit = nextPossibleHit.plus(1, ChronoUnit.DAYS); } } else { nextPossibleHit = LocalDateTime.ofInstant(firstInWindowAccessTime, ZoneOffset.UTC).plus(1, ChronoUnit.DAYS); } return nextPossibleHit; }  }
IndexerForSearchSelector { LocalDateTime calculateNextPossibleHit(IndexerConfig indexerConfig, Instant firstInWindowAccessTime) { LocalDateTime nextPossibleHit; if (indexerConfig.getHitLimitResetTime().isPresent()) { LocalDateTime now = LocalDateTime.now(clock); nextPossibleHit = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()).with(ChronoField.MINUTE_OF_HOUR, 0); if (nextPossibleHit.isBefore(now)) { nextPossibleHit = nextPossibleHit.plus(1, ChronoUnit.DAYS); } } else { nextPossibleHit = LocalDateTime.ofInstant(firstInWindowAccessTime, ZoneOffset.UTC).plus(1, ChronoUnit.DAYS); } return nextPossibleHit; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); }
IndexerForSearchSelector { LocalDateTime calculateNextPossibleHit(IndexerConfig indexerConfig, Instant firstInWindowAccessTime) { LocalDateTime nextPossibleHit; if (indexerConfig.getHitLimitResetTime().isPresent()) { LocalDateTime now = LocalDateTime.now(clock); nextPossibleHit = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()).with(ChronoField.MINUTE_OF_HOUR, 0); if (nextPossibleHit.isBefore(now)) { nextPossibleHit = nextPossibleHit.plus(1, ChronoUnit.DAYS); } } else { nextPossibleHit = LocalDateTime.ofInstant(firstInWindowAccessTime, ZoneOffset.UTC).plus(1, ChronoUnit.DAYS); } return nextPossibleHit; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); static final Pattern SCHEDULER_PATTERN; }