@Test public void alertingStateNull() { lifecycleManager.noData(null); 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 alertingStateNull() { lifecycleManager.valid(null); verifyZeroInteractions(alertingActionService); } }
@Test public void alertingStateNull() { lifecycleManager.violation(null, 0); 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); }
@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 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 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 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 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); }
@Test public void violationUpperThreshold() 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(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).violation(alertingState, 10D); 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 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 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 violationLowerThreshold() 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(15D); thresholdChecker.checkThreshold(alertingState); ArgumentCaptor<Long> timeCaptor = ArgumentCaptor.forClass(Long.class); verify(alertingState).setLastCheckTime(timeCaptor.capture()); verify(alertingState, times(2)).getLastCheckTime(); verify(alertingState, times(2)).getAlertingDefinition(); assertThat(timeCaptor.getValue(), greaterThanOrEqualTo(time)); verify(influxDao).query(any(String.class)); verify(influxDao).isConnected(); verify(stateManager).violation(alertingState, 10D); 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 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 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); }
@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); }
@Test public void noData() throws BusinessException, Exception { long time = System.currentTimeMillis(); when(influxDao.isConnected()).thenReturn(true); when(influxDao.query(any(String.class))).thenReturn(new QueryResult()); when(alertingState.getAlertingDefinition()).thenReturn(alertingDefinition); thresholdChecker.checkThreshold(alertingState); ArgumentCaptor<Long> timeCaptor = ArgumentCaptor.forClass(Long.class); verify(alertingState, times(2)).getLastCheckTime(); verify(alertingState).setLastCheckTime(timeCaptor.capture()); verify(alertingState).getAlertingDefinition(); assertThat(timeCaptor.getValue(), greaterThanOrEqualTo(time)); verify(influxDao).query(any(String.class)); verify(influxDao).isConnected(); verify(stateManager).noData(alertingState); verify(alertingDefinition).getThresholdType(); verify(alertingDefinition).getField(); verify(alertingDefinition).getTags(); verify(alertingDefinition).getMeasurement(); verify(alertingDefinition).getTimeRange(TimeUnit.MILLISECONDS); verifyNoMoreInteractions(influxDao, alertingState, stateManager, alertingDefinition); }