@Test public void shouldIgnoreHitLimitIfNotYetReached() { indexerConfigMock.setHitLimit(10); when(queryMock.getResultList()).thenReturn(Collections.emptyList()); boolean result = testee.checkIndexerHitLimit(indexer); assertTrue(result); verify(entityManagerMock).createNativeQuery(anyString()); }
protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; }
IndexerForSearchSelector { protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; } }
IndexerForSearchSelector { protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; }  }
IndexerForSearchSelector { protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); }
IndexerForSearchSelector { protected boolean checkIndexerHitLimit(Indexer indexer) { Stopwatch stopwatch = Stopwatch.createStarted(); IndexerConfig indexerConfig = indexer.getConfig(); if (!indexerConfig.getHitLimit().isPresent() && !indexerConfig.getDownloadLimit().isPresent()) { return true; } LocalDateTime comparisonTime; LocalDateTime now = LocalDateTime.now(clock); if (indexerConfig.getHitLimitResetTime().isPresent()) { comparisonTime = now.with(ChronoField.HOUR_OF_DAY, indexerConfig.getHitLimitResetTime().get()); if (comparisonTime.isAfter(now)) { comparisonTime = comparisonTime.minus(1, ChronoUnit.DAYS); } } else { comparisonTime = now.minus(1, ChronoUnit.DAYS); } if (indexerConfig.getHitLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.SEARCH, indexerConfig.getHitLimit().get(), "API hit"); if (limitExceeded) { return false; } } if (indexerConfig.getDownloadLimit().isPresent()) { boolean limitExceeded = checkIfHitLimitIsExceeded(indexer, indexerConfig, comparisonTime, IndexerApiAccessType.NZB, indexerConfig.getDownloadLimit().get(), "download"); if (limitExceeded) { return false; } } logger.debug(LoggingMarkers.PERFORMANCE, "Detection that hit limits were not reached for indexer {} took {}ms", indexer.getName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); return true; }  IndexerForSearchSelection pickIndexers(SearchRequest searchRequest); static final Pattern SCHEDULER_PATTERN; }