DetectorManager { void detectorLastUsedTimeSync(long currentTime) { long updateDurationInSeconds = (currentTime - detectorsLastUsedSyncedTillTime) / 1000; if (updateDurationInSeconds <= 0 || detectorsLastUsedTimeToBeUpdatedQueue.isEmpty()) { return; } processDetectorsLastTimeUsedQueue(); detectorsLastUsedSyncedTillTime = currentTime; } 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 testDetectorLastUsedTimeSync_unique_detectors() { int setSize = 50; populateSetWithUniqueUUIDs(setSize); managerUnderTest.detectorLastUsedTimeSync(System.currentTimeMillis() + 1000 * 60); verify(detectorSource, atMost(setSize)).updatedDetectorLastUsed(any(UUID.class)); }
@Test public void testDetectorLastUsedTimeSync_duplicate_detectors() { int setSize = 4; populateSetWithDuplicateUUIDs(setSize); managerUnderTest.detectorLastUsedTimeSync(System.currentTimeMillis() + 1000 * 60); verify(detectorSource, atMost(1)).updatedDetectorLastUsed(any(UUID.class)); }
@Test public void testDetectorLastUsedTimeSync_invalid_time() { managerUnderTest.detectorLastUsedTimeSync(System.currentTimeMillis()); verify(detectorSource, never()).updatedDetectorLastUsed(any(UUID.class)); }
@Test public void testDetectorLastUsedTimeSync_emptyQueue() { managerUnderTest.detectorLastUsedTimeSync(System.currentTimeMillis() + 1000 * 60); verify(detectorSource, never()).updatedDetectorLastUsed(any(UUID.class)); }