use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testStartHistoricalAnalysisWithNoOwningNode.
@SuppressWarnings("unchecked")
public void testStartHistoricalAnalysisWithNoOwningNode() throws IOException {
AnomalyDetector detector = TestHelpers.randomAnomalyDetector(ImmutableList.of());
DetectionDateRange detectionDateRange = TestHelpers.randomDetectionDateRange();
User user = null;
int availableTaskSlots = randomIntBetween(1, 10);
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
doAnswer(invocation -> {
Consumer<Optional<DiscoveryNode>> function = invocation.getArgument(1);
function.accept(Optional.empty());
return null;
}).when(hashRing).buildAndGetOwningNodeWithSameLocalAdVersion(anyString(), any(), any());
adTaskManager.startHistoricalAnalysis(detector, detectionDateRange, user, availableTaskSlots, 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 testScaleTaskLaneOnCoordinatingNode.
@SuppressWarnings("unchecked")
public void testScaleTaskLaneOnCoordinatingNode() {
ADTask adTask = mock(ADTask.class);
when(adTask.getCoordinatingNode()).thenReturn(node1.getId());
when(nodeFilter.getEligibleDataNodes()).thenReturn(new DiscoveryNode[] { node1, node2 });
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
adTaskManager.scaleTaskLaneOnCoordinatingNode(adTask, 2, transportService, listener);
}
use of org.opensearch.ad.transport.AnomalyDetectorJobResponse in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testStopDetectorWithNonExistingTask.
@SuppressWarnings("unchecked")
public void testStopDetectorWithNonExistingTask() {
String detectorId = randomAlphaOfLength(5);
boolean historical = true;
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
doAnswer(invocation -> {
Consumer<Optional<AnomalyDetector>> function = invocation.getArgument(1);
AnomalyDetector detector = randomAnomalyDetector(ImmutableList.of(randomFeature(true)));
function.accept(Optional.of(detector));
return null;
}).when(adTaskManager).getDetector(anyString(), any(), any());
doAnswer(invocation -> {
ActionListener<SearchResponse> actionListener = invocation.getArgument(1);
actionListener.onResponse(null);
return null;
}).when(client).search(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 testForwardRequestToLeadNodeWithNotExistingNode.
@SuppressWarnings("unchecked")
public void testForwardRequestToLeadNodeWithNotExistingNode() throws IOException {
ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_ENTITY);
ForwardADTaskRequest forwardADTaskRequest = new ForwardADTaskRequest(adTask, ADTaskAction.APPLY_FOR_TASK_SLOTS);
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
doAnswer(invocation -> {
Consumer<Optional<DiscoveryNode>> function = invocation.getArgument(1);
function.accept(Optional.empty());
return null;
}).when(hashRing).buildAndGetOwningNodeWithSameLocalAdVersion(any(), any(), any());
adTaskManager.forwardRequestToLeadNode(forwardADTaskRequest, 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 testScaleUpTaskSlots.
@SuppressWarnings("unchecked")
public void testScaleUpTaskSlots() throws IOException {
ADTask adTask = randomAdTask(ADTaskType.HISTORICAL_HC_ENTITY);
ActionListener<AnomalyDetectorJobResponse> listener = mock(ActionListener.class);
when(adTaskCacheManager.getAvailableNewEntityTaskLanes(anyString())).thenReturn(0);
doReturn(2).when(adTaskManager).detectorTaskSlotScaleDelta(anyString());
when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(null);
assertEquals(0, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(Instant.now());
assertEquals(2, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
when(adTaskCacheManager.getLastScaleEntityTaskLaneTime(anyString())).thenReturn(Instant.now().minus(10, ChronoUnit.DAYS));
assertEquals(2, adTaskManager.scaleTaskSlots(adTask, transportService, listener));
verify(adTaskCacheManager, times(1)).refreshLastScaleEntityTaskLaneTime(anyString());
verify(adTaskManager, times(1)).forwardScaleTaskSlotRequestToLeadNode(any(), any(), any());
}
Aggregations