use of org.opensearch.ad.transport.RCFPollingResponse in project anomaly-detection by opensearch-project.
the class AnomalyDetectorProfileRunnerTests method setUpClientExecuteRCFPollingAction.
@SuppressWarnings("unchecked")
private void setUpClientExecuteRCFPollingAction(RCFPollingStatus inittedEverResultStatus) {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<RCFPollingResponse> listener = (ActionListener<RCFPollingResponse>) args[2];
Exception cause = null;
String detectorId = "123";
if (inittedEverResultStatus == RCFPollingStatus.INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.REMOTE_INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.INDEX_NOT_FOUND || inittedEverResultStatus == RCFPollingStatus.REMOTE_INDEX_NOT_FOUND) {
switch(inittedEverResultStatus) {
case INIT_NOT_EXIT:
case REMOTE_INIT_NOT_EXIT:
cause = new ResourceNotFoundException(detectorId, messaingExceptionError);
break;
case INDEX_NOT_FOUND:
case REMOTE_INDEX_NOT_FOUND:
cause = new IndexNotFoundException(detectorId, CommonName.CHECKPOINT_INDEX_NAME);
break;
default:
assertTrue("should not reach here", false);
break;
}
cause = new AnomalyDetectionException(detectorId, cause);
if (inittedEverResultStatus == RCFPollingStatus.REMOTE_INIT_NOT_EXIT || inittedEverResultStatus == RCFPollingStatus.REMOTE_INDEX_NOT_FOUND) {
cause = new RemoteTransportException(RCFPollingAction.NAME, new NotSerializableExceptionWrapper(cause));
}
listener.onFailure(cause);
} else {
RCFPollingResponse result = null;
switch(inittedEverResultStatus) {
case INIT_DONE:
result = new RCFPollingResponse(requiredSamples + 1);
break;
case INITTING:
result = new RCFPollingResponse(requiredSamples - neededSamples);
break;
case EMPTY:
result = new RCFPollingResponse(0);
break;
case EXCEPTION:
listener.onFailure(new RuntimeException());
break;
default:
assertTrue("should not reach here", false);
break;
}
listener.onResponse(result);
}
return null;
}).when(client).execute(any(RCFPollingAction.class), any(), any());
}
Aggregations