@Test public void alertingStateNull() { lifecycleManager.valid(null); verifyZeroInteractions(alertingActionService); } }
@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); }
/** * 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 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(2); lifecycleManager.thresholdResetCount = 2; lifecycleManager.valid(alertingState); verify(alertingState).isAlertActive(); verify(alertingState).getValidCount(); verifyNoMoreInteractions(alertingState); verify(alertingActionService).alertEnding(alertingState); verifyNoMoreInteractions(alertingActionService); }
@Test public void noViolationUpperThreshold() throws BusinessException, Exception { long time = System.currentTimeMillis(); when(influxDao.isConnected()).thenReturn(true); when(influxDao.query(any(String.class))).thenReturn(queryResult); when(alertingState.getAlertingDefinition()).thenReturn(alertingDefinition); when(alertingDefinition.getThresholdType()).thenReturn(ThresholdType.UPPER_THRESHOLD); when(alertingDefinition.getThreshold()).thenReturn(15D); thresholdChecker.checkThreshold(alertingState); ArgumentCaptor<Long> timeCaptor = ArgumentCaptor.forClass(Long.class); verify(alertingState, times(2)).getLastCheckTime(); verify(alertingState).setLastCheckTime(timeCaptor.capture()); verify(alertingState, times(2)).getAlertingDefinition(); assertThat(timeCaptor.getValue(), greaterThanOrEqualTo(time)); verify(influxDao).query(any(String.class)); verify(influxDao).isConnected(); verify(stateManager).valid(alertingState); verify(alertingDefinition, times(2)).getThresholdType(); verify(alertingDefinition).getThreshold(); verify(alertingDefinition).getField(); verify(alertingDefinition).getTags(); verify(alertingDefinition).getMeasurement(); verify(alertingDefinition).getTimeRange(TimeUnit.MILLISECONDS); verifyNoMoreInteractions(influxDao, alertingState, stateManager, alertingDefinition); }
@Test public void noViolationLowerThreshold() throws BusinessException, Exception { long time = System.currentTimeMillis(); when(influxDao.isConnected()).thenReturn(true); when(influxDao.query(any(String.class))).thenReturn(queryResult); when(alertingState.getAlertingDefinition()).thenReturn(alertingDefinition); when(alertingDefinition.getThresholdType()).thenReturn(ThresholdType.LOWER_THRESHOLD); when(alertingDefinition.getThreshold()).thenReturn(5D); thresholdChecker.checkThreshold(alertingState); ArgumentCaptor<Long> timeCaptor = ArgumentCaptor.forClass(Long.class); verify(alertingState, times(2)).getLastCheckTime(); verify(alertingState).setLastCheckTime(timeCaptor.capture()); verify(alertingState, times(2)).getAlertingDefinition(); assertThat(timeCaptor.getValue(), greaterThanOrEqualTo(time)); verify(influxDao).query(any(String.class)); verify(influxDao).isConnected(); verify(stateManager).valid(alertingState); verify(alertingDefinition, times(2)).getThresholdType(); verify(alertingDefinition).getThreshold(); verify(alertingDefinition).getField(); verify(alertingDefinition).getTags(); verify(alertingDefinition).getMeasurement(); verify(alertingDefinition).getTimeRange(TimeUnit.MILLISECONDS); verifyNoMoreInteractions(influxDao, alertingState, stateManager, alertingDefinition); }
stateManager.violation(alertingState, extremeValue); } else { stateManager.valid(alertingState);