use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testParseEntityForSingleCategoryHC.
public void testParseEntityForSingleCategoryHC() throws IOException {
ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5))));
String entityValue = adTaskManager.convertEntityToString(adTask);
Entity entity = adTaskManager.parseEntityFromString(entityValue, adTask);
assertEquals(entity, adTask.getEntity());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testCreateADTaskDirectlyWithException.
@SuppressWarnings("unchecked")
public void testCreateADTaskDirectlyWithException() throws IOException {
ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_DETECTOR);
Consumer<IndexResponse> function = mock(Consumer.class);
ActionListener<IndexResponse> listener = mock(ActionListener.class);
doThrow(new RuntimeException("test")).when(client).index(any(), any());
adTaskManager.createADTaskDirectly(adTask, function, listener);
verify(listener, times(1)).onFailure(any());
doAnswer(invocation -> {
ActionListener<IndexResponse> actionListener = invocation.getArgument(1);
actionListener.onFailure(new RuntimeException("test"));
return null;
}).when(client).index(any(), any());
adTaskManager.createADTaskDirectly(adTask, function, listener);
verify(listener, times(2)).onFailure(any());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testDeleteDuplicateTasks.
public void testDeleteDuplicateTasks() throws IOException {
ADTask adTask = randomAdTask();
adTaskManager.handleADTaskException(adTask, new DuplicateTaskException("test"));
verify(client, times(1)).delete(any(), any());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testCheckTaskSlotsWithAvailableTaskSlotsForSingleEntityDetector.
public void testCheckTaskSlotsWithAvailableTaskSlotsForSingleEntityDetector() throws IOException {
ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of()));
setupHashRingWithSameLocalADVersionNodes();
setupTaskSlots(0, 2, 2, 1);
adTaskManager.checkTaskSlots(adTask, adTask.getDetector(), detectionDateRange, randomUser(), ADTaskAction.START, transportService, listener);
verify(adTaskManager, times(1)).startHistoricalAnalysis(eq(adTask.getDetector()), eq(detectionDateRange), any(), eq(1), eq(transportService), any());
}
use of org.opensearch.ad.model.ADTask in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testCheckTaskSlotsWithAvailableTaskSlotsAndNoEntity.
public void testCheckTaskSlotsWithAvailableTaskSlotsAndNoEntity() throws IOException {
ADTask adTask = randomAdTask(randomAlphaOfLength(5), ADTaskState.INIT, Instant.now(), randomAlphaOfLength(5), TestHelpers.randomAnomalyDetectorUsingCategoryFields(randomAlphaOfLength(5), ImmutableList.of(randomAlphaOfLength(5))));
setupSearchTopEntities(0);
setupHashRingWithSameLocalADVersionNodes();
setupTaskSlots(0, 2, 2, 1);
adTaskManager.checkTaskSlots(adTask, adTask.getDetector(), detectionDateRange, randomUser(), ADTaskAction.START, transportService, listener);
verify(adTaskManager, times(1)).startHistoricalAnalysis(any(), any(), any(), anyInt(), any(), any());
}
Aggregations