@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 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 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 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 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 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); } }