Search in sources :

Example 21 with AnomalyDetectorJobResponse

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());
}
Also used : TestHelpers.randomUser(org.opensearch.ad.TestHelpers.randomUser) User(org.opensearch.commons.authuser.User) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) AnomalyDetector(org.opensearch.ad.model.AnomalyDetector) TestHelpers.randomAnomalyDetector(org.opensearch.ad.TestHelpers.randomAnomalyDetector) TestHelpers.randomDetectionDateRange(org.opensearch.ad.TestHelpers.randomDetectionDateRange) DetectionDateRange(org.opensearch.ad.model.DetectionDateRange)

Example 22 with AnomalyDetectorJobResponse

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());
}
Also used : Optional(java.util.Optional) AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 23 with AnomalyDetectorJobResponse

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());
}
Also used : AnomalyDetectorJobResponse(org.opensearch.ad.transport.AnomalyDetectorJobResponse) ADTask(org.opensearch.ad.model.ADTask) ExecutorService(java.util.concurrent.ExecutorService) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

AnomalyDetectorJobResponse (org.opensearch.ad.transport.AnomalyDetectorJobResponse)23 Optional (java.util.Optional)13 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)13 DetectionDateRange (org.opensearch.ad.model.DetectionDateRange)13 ADTask (org.opensearch.ad.model.ADTask)12 IOException (java.io.IOException)10 ResourceAlreadyExistsException (org.opensearch.ResourceAlreadyExistsException)10 SearchResponse (org.opensearch.action.search.SearchResponse)10 DuplicateTaskException (org.opensearch.ad.common.exception.DuplicateTaskException)10 User (org.opensearch.commons.authuser.User)10 IndexNotFoundException (org.opensearch.index.IndexNotFoundException)10 Instant (java.time.Instant)9 TotalHits (org.apache.lucene.search.TotalHits)9 OpenSearchStatusException (org.opensearch.OpenSearchStatusException)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 ChronoUnit (java.time.temporal.ChronoUnit)8 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Locale (java.util.Locale)8