@Test public void noAlertActive() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(false); lifecycleManager.noData(alertingState); verifyZeroInteractions(alertingActionService); verify(alertingState, times(2)).isAlertActive(); verifyNoMoreInteractions(alertingState); }
@Test public void noAlertActive() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(false); lifecycleManager.valid(alertingState); verify(alertingState).isAlertActive(); verifyNoMoreInteractions(alertingState); verifyZeroInteractions(alertingActionService); }
@Test public void alertStarted() { double violationValue = 100D; AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(false); lifecycleManager.violation(alertingState, violationValue); verify(alertingState).isAlertActive(); verifyNoMoreInteractions(alertingState); verify(alertingActionService).alertStarting(alertingState, violationValue); verifyNoMoreInteractions(alertingActionService); }
@Test public void noAlertActiveCountPositive() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(false); when(alertingState.getValidCount()).thenReturn(10); lifecycleManager.noData(alertingState); verifyZeroInteractions(alertingActionService); verify(alertingState, times(2)).isAlertActive(); verifyNoMoreInteractions(alertingState); }
@Test public void alertOngoing() { double violationValue = 100D; AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); lifecycleManager.violation(alertingState, violationValue); verify(alertingState).isAlertActive(); verify(alertingState).setValidCount(0); verifyNoMoreInteractions(alertingState); verify(alertingActionService).alertOngoing(alertingState, violationValue); verifyNoMoreInteractions(alertingActionService); }
@Test public void alertActiveNoReset() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); when(alertingState.getValidCount()).thenReturn(1); lifecycleManager.thresholdResetCount = 2; lifecycleManager.valid(alertingState); verify(alertingState).isAlertActive(); verify(alertingState).getValidCount(); verify(alertingState).setValidCount(2); verifyNoMoreInteractions(alertingState); verifyZeroInteractions(alertingActionService); }
@Test public void alertActiveDataWasValid() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); when(alertingState.getValidCount()).thenReturn(1); lifecycleManager.thresholdResetCount = 2; lifecycleManager.noData(alertingState); verify(alertingState, times(2)).isAlertActive(); verify(alertingState, times(2)).getValidCount(); verify(alertingState).setValidCount(2); verifyNoMoreInteractions(alertingState); verifyZeroInteractions(alertingActionService); }
@Test public void resetActiveAlert() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); when(alertingState.getValidCount()).thenReturn(1); lifecycleManager.thresholdResetCount = 0; lifecycleManager.noData(alertingState); verify(alertingState, times(2)).isAlertActive(); verify(alertingState, times(2)).getValidCount(); verifyNoMoreInteractions(alertingState); verify(alertingActionService).alertEnding(alertingState); verifyNoMoreInteractions(alertingActionService); }
@Test public void resetActiveAlert() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); when(alertingState.getValidCount()).thenReturn(2); lifecycleManager.thresholdResetCount = 2; lifecycleManager.valid(alertingState); verify(alertingState).isAlertActive(); verify(alertingState).getValidCount(); verifyNoMoreInteractions(alertingState); verify(alertingActionService).alertEnding(alertingState); verifyNoMoreInteractions(alertingActionService); }
/** * This method is called when no data is existing for the given threshold in the latest period. * * @param alertingState * the threshold which has been checked */ public void noData(AlertingState alertingState) { if (alertingState == null) { return; } if (log.isDebugEnabled()) { log.debug("||-No data available for alerting definition '{}'. Expecting the same behavior as before.", alertingState.getAlertingDefinition().getName()); } if (!alertingState.isAlertActive() || (alertingState.getValidCount() > 0)) { valid(alertingState); } else { violation(alertingState, Double.NaN); } } }
@Test public void alertActiveContinuousViolation() { AlertingState alertingState = Mockito.mock(AlertingState.class); when(alertingState.isAlertActive()).thenReturn(true); when(alertingState.getValidCount()).thenReturn(0); lifecycleManager.thresholdResetCount = 0; lifecycleManager.noData(alertingState); verify(alertingActionService, times(1)).alertOngoing(alertingState, Double.NaN); verifyNoMoreInteractions(alertingActionService); verify(alertingState, times(2)).isAlertActive(); verify(alertingState).setValidCount(0); verify(alertingState).getValidCount(); verifyNoMoreInteractions(alertingState); }
/** * This method is called if the given threshold (specified by the {@link AlertingDefinition} * contained in the {@link AlertingState}) has been violated in the latest interval. The given * value showed the largest deviation to the threshold. * * @param alertingState * the threshold which has been violated * @param violationValue * the value which violated the threshold */ public void violation(AlertingState alertingState, double violationValue) { if (alertingState == null) { return; } if (alertingState.isAlertActive()) { // alert is ongoing if (log.isDebugEnabled()) { log.debug("||-Violation of threshold '{}' is ongoing.", alertingState.getAlertingDefinition().getName()); } alertingState.setValidCount(0); alertingActionService.alertOngoing(alertingState, violationValue); } else { // alert is new if (log.isDebugEnabled()) { log.debug("||-Threshold violation. Value '{}' violated threshold '{}' and started a new alert.", violationValue, alertingState.getAlertingDefinition().toString()); } alertingActionService.alertStarting(alertingState, violationValue); } }
/** * This method is called when the given threshold has not been violated in the latest period. * * @param alertingState * the threshold which has not been violated */ public void valid(AlertingState alertingState) { if (alertingState == null) { return; } if (log.isDebugEnabled()) { log.debug("||-Threshold '{}' has not been violated in the last interval.", alertingState.getAlertingDefinition().getName()); } if (!alertingState.isAlertActive()) { // threshold is not in a violation series return; } int validCount = alertingState.getValidCount(); if (validCount >= thresholdResetCount) { // alert ended if (log.isDebugEnabled()) { log.debug("||-Ended threshold violation series of '{}'.", alertingState.getAlertingDefinition().getName()); } alertingActionService.alertEnding(alertingState); } else { // alert is waiting for reset alertingState.setValidCount(validCount + 1); } }