use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testStartDetectorWithException.
@SuppressWarnings("unchecked")
public void testStartDetectorWithException() throws IOException {
AnomalyDetector detector = randomAnomalyDetector(ImmutableList.of(randomFeature(true)));
DetectionDateRange detectionDateRange = randomDetectionDateRange();
User user = null;
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
when(detectionIndices.doesDetectorStateIndexExist()).thenReturn(false);
doThrow(new RuntimeException("test")).when(detectionIndices).initDetectionStateIndex(any());
adTaskManager.startDetector(detector, detectionDateRange, user, transportService, listener);
verify(listener, times(1)).onFailure(any());
}
use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testStopDetectorWithNonExistingDetector.
@SuppressWarnings("unchecked")
public void testStopDetectorWithNonExistingDetector() {
String detectorId = randomAlphaOfLength(5);
boolean historical = true;
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
doAnswer(invocation -> {
Consumer<Optional<AnomalyDetector>> function = invocation.getArgument(1);
function.accept(Optional.empty());
return null;
}).when(adTaskManager).getDetector(anyString(), any(), any());
adTaskManager.stopDetector(detectorId, historical, indexAnomalyDetectorJobActionHandler, null, transportService, listener);
verify(listener, times(1)).onFailure(any());
}
use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testRemoveStaleRunningEntity.
@SuppressWarnings("unchecked")
public void testRemoveStaleRunningEntity() throws IOException {
ActionListener<AnomalyDetectorJobResponse> actionListener = mock(ActionListener.class);
ADTask adTask = randomAdTask();
String entity = randomAlphaOfLength(5);
ExecutorService executeService = mock(ExecutorService.class);
when(threadPool.executor(anyString())).thenReturn(executeService);
doAnswer(invocation -> {
Runnable runnable = invocation.getArgument(0);
runnable.run();
return null;
}).when(executeService).execute(any());
when(adTaskCacheManager.removeRunningEntity(anyString(), anyString())).thenReturn(true);
when(adTaskCacheManager.getPendingEntityCount(anyString())).thenReturn(randomIntBetween(1, 10));
adTaskManager.removeStaleRunningEntity(adTask, entity, transportService, actionListener);
verify(adTaskManager, times(1)).runNextEntityForHCADHistorical(any(), any(), any());
when(adTaskCacheManager.removeRunningEntity(anyString(), anyString())).thenReturn(false);
when(adTaskCacheManager.hasEntity(anyString())).thenReturn(false);
adTaskManager.removeStaleRunningEntity(adTask, entity, transportService, actionListener);
verify(adTaskManager, times(1)).setHCDetectorTaskDone(any(), any(), any());
when(adTaskCacheManager.hasEntity(anyString())).thenReturn(true);
adTaskManager.removeStaleRunningEntity(adTask, entity, transportService, actionListener);
verify(adTaskManager, times(1)).setHCDetectorTaskDone(any(), any(), any());
}
Aggregations