DetectorMapper { public List<Detector> getDetectorsFromCache(MetricDefinition metricDefinition) { String cacheKey = CacheUtil.getKey(metricDefinition.getTags().getKv()); return cache.get(cacheKey); } DetectorMapper(DetectorSource detectorSource, DetectorMapperCache cache, int detectorCacheUpdateTimePeriod);  DetectorMapper(DetectorSource detectorSource, Config config, MetricRegistry metricRegistry); int optimalBatchSize(); List<Detector> getDetectorsFromCache(MetricDefinition metricDefinition); boolean isSuccessfulDetectorMappingLookup(List<Map<String, String>> cacheMissedMetricTags); void detectorMappingCacheSync(long currentTime);  }
@Test public void testGetDetectorsFromCache() throws IOException { this.detectorMapper = new DetectorMapper(detectorSource, config, new MetricRegistry()); this.initTagsFromFile(); detectorMapper.isSuccessfulDetectorMappingLookup(listOfMetricTags); Map<String, List<Detector>> detectorResults = new HashMap<>(); listOfMetricTags.forEach(tags -> { MetricData metricData = new MetricData(new MetricDefinition(new TagCollection(tags)), 0.0, 1L); List<Detector> detector = detectorMapper.getDetectorsFromCache(metricData.getMetricDefinition()); if (!detector.isEmpty()) detectorResults.put(CacheUtil.getKey(tags), detector); }); assertThat(detectorResults.size(), is(3)); assertThat(detectorResults, IsMapContaining.hasEntry("key->RHZGV1VodjI1aA==,name->NjFFS0JDcnd2SQ==", Collections.singletonList(buildDetector("cid", "2c49ba26-1a7d-43f4-b70c-c6644a2c1689")))); assertThat(detectorResults, IsMapContaining.hasEntry("key->ZEFxYlpaVlBaOA==,name->ZmJXVGlSbHhrdA==", Collections.singletonList(buildDetector("ad-manager", "5eaa54e9-7406-4a1d-bd9b-e055eca1a423")))); assertThat(detectorResults, IsMapContaining.hasEntry("name->aGl3,region->dXMtd2VzdC0y", Collections.singletonList(buildDetector("", "d86b798c-cfee-4a2c-a17a-aa2ba79ccf51")))); }