DataInitializer { public void initializeDetector(MappedMetricData mappedMetricData, Detector detector, DetectorMapping detectorMapping) { if (isSeasonalNaiveDetector(detector)) { if (throttleGate.isOpen()) { log.info("Throttle gate is open, initializing data and creating a detector"); val forecastingDetector = (ForecastingDetector) detector; initializeForecastingDetector(mappedMetricData, forecastingDetector, detectorMapping); } else { String message = "Throttle gate is closed, skipping data initialization"; log.info(message); throw new DetectorDataInitializationThrottledException(message); } } } DataInitializer(Config config, ThrottleGate throttleGate, DataSource dataSource); void initializeDetector(MappedMetricData mappedMetricData, Detector detector, DetectorMapping detectorMapping); static final String BASE_URI; static final String DATA_RETRIEVAL_TAG_KEY; static final String THROTTLE_GATE_LIKELIHOOD; static final String DEFAULT_GRAPHITE_FUNCTION; }
@Test public void testInitializeDetectorThrottleGateOpen() { initThrottleGate(true); initializerUnderTest.initializeDetector(mappedMetricData, seasonalNaiveDetector, detectorMapping); }
@Test(expected = DetectorDataInitializationThrottledException.class) public void testInitializeDetectorThrottleGateClosed() { initThrottleGate(false); initializerUnderTest.initializeDetector(mappedMetricData, seasonalNaiveDetector, detectorMapping); }
@Test public void testInitializeDetectorWithDuplicateMetric() { when(throttleGate.isOpen()).thenReturn(true); doThrow(new MetricDeliveryDuplicateException("Metric with dodgy timestamp")).when(seasonalPointForecaster).forecast(any(MetricData.class)); initializerUnderTest.initializeDetector(mappedMetricData, seasonalNaiveDetector, detectorMapping); }
@Test public void testInitializeDetectorWithTimeException() { initThrottleGate(true); doThrow(new MetricDeliveryTimeException("Metric with dodgy timestamp")).when(seasonalPointForecaster).forecast(any(MetricData.class)); initializerUnderTest.initializeDetector(mappedMetricData, seasonalNaiveDetector, detectorMapping); }
@Test(expected = RuntimeException.class) public void testInitializeDetector_illegal_point_forecaster() { val intervalParams = new MultiplicativeIntervalForecasterParams().setStrongMultiplier(3.0).setWeakMultiplier(1.0); val pointParams = new PewmaPointForecasterParams().setAlpha(1.0).setBeta(2.0); val pointForecaster = new PewmaPointForecaster(pointParams); val intervalForecaster = new MultiplicativeIntervalForecaster(intervalParams); val detector = new ForecastingDetector(randomUUID(), pointForecaster, intervalForecaster, TWO_TAILED, true, "seasonalnaive"); initializerUnderTest.initializeDetector(mappedMetricData, detector, detectorMapping); }