@Test public void alertingStateNull() { lifecycleManager.noData(null); verifyZeroInteractions(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 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 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 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); }
@Test public void neverChecked() 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); when(alertingState.getLastCheckTime()).thenReturn(-1L); thresholdChecker.checkThreshold(alertingState); ArgumentCaptor<Long> currentTimeCaptor = ArgumentCaptor.forClass(Long.class); verify(alertingState, times(2)).getLastCheckTime(); verify(alertingState, times(2)).setLastCheckTime(currentTimeCaptor.capture()); verify(alertingState, times(2)).getAlertingDefinition(); assertThat(currentTimeCaptor.getValue(), greaterThanOrEqualTo(time)); verify(alertingDefinition, times(2)).getTimeRange(TimeUnit.MILLISECONDS); 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, times(2)).getTimeRange(TimeUnit.MILLISECONDS); verifyNoMoreInteractions(influxDao, alertingState, stateManager, alertingDefinition); }
stateManager.noData(alertingState); } else { double extremeValue = resultWrapper.getDouble(0, 1);