DetectorManager { List<UUID> detectorCacheSync(long currentTime) { List<UUID> updatedDetectors = new ArrayList<>(); long updateDurationInSeconds = (currentTime - cacheSyncedTillTime) / 1000; if (updateDurationInSeconds <= 0) { return updatedDetectors; } detectorSource.findUpdatedDetectors(updateDurationInSeconds).forEach(key -> { if (cachedDetectors.containsKey(key)) { cachedDetectors.remove(key); updatedDetectors.add(key); } }); if (!updatedDetectors.isEmpty()) { log.info("Removed these updated detectors from cache (so they can be reloaded at time of next metric observation): {}", updatedDetectors); } cacheSyncedTillTime = currentTime; return updatedDetectors; } DetectorManager(DetectorSource detectorSource,
                           DataInitializer dataInitializer,
                           Config config,
                           Map<UUID, DetectorContainer> cachedDetectors,
                           MetricRegistry metricRegistry);  DetectorManager(DetectorSource detectorSource,
                           DataInitializer dataInitializer,
                           Config config,
                           MetricRegistry metricRegistry); DetectorResult detect(@NonNull MappedMetricData mappedMetricData); Meter getDetectorAndLevelMeter(String name, AnomalyLevel anomalyLevel);  }
@Test public void testDetectorRefresh() { val result = managerUnderTest.detectorCacheSync(System.currentTimeMillis() + 1000 * 60); assertNotNull(result); assertEquals(updatedDetectors, result); }
@Test public void testDetectorRefresh_invalid_time() { val result = managerUnderTest.detectorCacheSync(System.currentTimeMillis()); assertNotNull(result); val emptyList = new ArrayList<>(); assertEquals(emptyList, result); }