use of org.opensearch.ad.model.DetectorState in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testInitOrRunningStateTemplate.
public void testInitOrRunningStateTemplate(RCFPollingStatus status, DetectorState expectedState) throws IOException, InterruptedException {
setUpClientGet(DetectorStatus.EXIST, JobStatus.ENABLED, status, ErrorResultStatus.NO_ERROR);
DetectorProfile expectedProfile = new DetectorProfile.Builder().state(expectedState).build();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
logger.error(exception);
for (StackTraceElement ste : exception.getStackTrace()) {
logger.info(ste);
}
assertTrue("Should not reach here ", false);
inProgressLatch.countDown();
}), stateOnly);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
use of org.opensearch.ad.model.DetectorState in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method testErrorStateTemplate.
@SuppressWarnings("unchecked")
public void testErrorStateTemplate(RCFPollingStatus initStatus, ErrorResultStatus status, DetectorState state, String error, JobStatus jobStatus, Set<DetectorProfileName> profilesToCollect) throws IOException, InterruptedException {
ADTask adTask = TestHelpers.randomAdTask();
adTask.setError(getError(status));
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
Consumer<Optional<ADTask>> function = (Consumer<Optional<ADTask>>) args[2];
function.accept(Optional.of(adTask));
return null;
}).when(adTaskManager).getAndExecuteOnLatestDetectorLevelTask(any(), any(), any(), any(), anyBoolean(), any());
setUpClientExecuteRCFPollingAction(initStatus);
setUpClientGet(DetectorStatus.EXIST, jobStatus, initStatus, status);
DetectorProfile.Builder builder = new DetectorProfile.Builder();
if (profilesToCollect.contains(DetectorProfileName.STATE)) {
builder.state(state);
}
if (profilesToCollect.contains(DetectorProfileName.ERROR)) {
builder.error(error);
}
DetectorProfile expectedProfile = builder.build();
final CountDownLatch inProgressLatch = new CountDownLatch(1);
runner.profile(detector.getDetectorId(), ActionListener.wrap(response -> {
assertEquals(expectedProfile, response);
inProgressLatch.countDown();
}, exception -> {
logger.info(exception);
for (StackTraceElement ste : exception.getStackTrace()) {
logger.info(ste);
}
assertTrue("Should not reach here", false);
inProgressLatch.countDown();
}), profilesToCollect);
assertTrue(inProgressLatch.await(100, TimeUnit.SECONDS));
}
Aggregations