Search in sources :

Example 1 with TestHelpers.randomAnomalyDetector

use of org.opensearch.ad.TestHelpers.randomAnomalyDetector 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());
}
Also used : TestHelpers.randomUser(org.opensearch.ad.TestHelpers.randomUser) User(org.opensearch.commons.authuser.User) Optional(java.util.Optional) 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)

Aggregations

Optional (java.util.Optional)1 TestHelpers.randomAnomalyDetector (org.opensearch.ad.TestHelpers.randomAnomalyDetector)1 TestHelpers.randomDetectionDateRange (org.opensearch.ad.TestHelpers.randomDetectionDateRange)1 TestHelpers.randomUser (org.opensearch.ad.TestHelpers.randomUser)1 AnomalyDetector (org.opensearch.ad.model.AnomalyDetector)1 DetectionDateRange (org.opensearch.ad.model.DetectionDateRange)1 AnomalyDetectorJobResponse (org.opensearch.ad.transport.AnomalyDetectorJobResponse)1 User (org.opensearch.commons.authuser.User)1