use of org.opensearch.ad.settings.AnomalyDetectorSettings.MAX_BATCH_TASK_PER_NODE in project anomaly-detection by opensearch-project.
the class ADTaskManagerTests method testCleanADResultOfDeletedDetectorWithException.
public void testCleanADResultOfDeletedDetectorWithException() {
String detectorId = randomAlphaOfLength(5);
when(adTaskCacheManager.pollDeletedDetector()).thenReturn(detectorId);
doAnswer(invocation -> {
ActionListener<BulkByScrollResponse> listener = invocation.getArgument(2);
listener.onFailure(new RuntimeException("test"));
return null;
}).doAnswer(invocation -> {
ActionListener<BulkByScrollResponse> listener = invocation.getArgument(2);
BulkByScrollResponse deleteByQueryResponse = mock(BulkByScrollResponse.class);
listener.onResponse(deleteByQueryResponse);
return null;
}).when(client).execute(any(), any(), any());
settings = Settings.builder().put(MAX_OLD_AD_TASK_DOCS_PER_DETECTOR.getKey(), 2).put(BATCH_TASK_PIECE_INTERVAL_SECONDS.getKey(), 1).put(REQUEST_TIMEOUT.getKey(), TimeValue.timeValueSeconds(10)).put(DELETE_AD_RESULT_WHEN_DELETE_DETECTOR.getKey(), true).build();
clusterSettings = clusterSetting(settings, MAX_OLD_AD_TASK_DOCS_PER_DETECTOR, BATCH_TASK_PIECE_INTERVAL_SECONDS, REQUEST_TIMEOUT, DELETE_AD_RESULT_WHEN_DELETE_DETECTOR, MAX_BATCH_TASK_PER_NODE, MAX_RUNNING_ENTITIES_PER_DETECTOR_FOR_HISTORICAL_ANALYSIS);
clusterService = spy(new ClusterService(settings, clusterSettings, null));
ADTaskManager adTaskManager = spy(new ADTaskManager(settings, clusterService, client, TestHelpers.xContentRegistry(), detectionIndices, nodeFilter, hashRing, adTaskCacheManager, threadPool));
adTaskManager.cleanADResultOfDeletedDetector();
verify(client, times(1)).execute(eq(DeleteByQueryAction.INSTANCE), any(), any());
verify(adTaskCacheManager, times(1)).addDeletedDetector(eq(detectorId));
adTaskManager.cleanADResultOfDeletedDetector();
verify(client, times(2)).execute(eq(DeleteByQueryAction.INSTANCE), any(), any());
verify(adTaskCacheManager, times(1)).addDeletedDetector(eq(detectorId));
}
Aggregations