use of org.opensearch.action.ActionRequest in project OpenSearch by opensearch-project.
the class RestHighLevelClientTests method testRequestValidation.
public void testRequestValidation() {
ActionRequestValidationException validationException = new ActionRequestValidationException();
validationException.addValidationError("validation error");
ActionRequest request = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return validationException;
}
};
{
ActionRequestValidationException actualException = expectThrows(ActionRequestValidationException.class, () -> restHighLevelClient.performRequest(request, null, RequestOptions.DEFAULT, null, null));
assertSame(validationException, actualException);
}
{
TrackingActionListener trackingActionListener = new TrackingActionListener();
restHighLevelClient.performRequestAsync(request, null, RequestOptions.DEFAULT, null, trackingActionListener, null);
assertSame(validationException, trackingActionListener.exception.get());
}
}
use of org.opensearch.action.ActionRequest in project OpenSearch by opensearch-project.
the class TransportBulkActionTookTests method createAction.
private TransportBulkAction createAction(boolean controlled, AtomicLong expected) {
CapturingTransport capturingTransport = new CapturingTransport();
TransportService transportService = capturingTransport.createTransportService(clusterService.getSettings(), threadPool, TransportService.NOOP_TRANSPORT_INTERCEPTOR, boundAddress -> clusterService.localNode(), null, Collections.emptySet());
transportService.start();
transportService.acceptIncomingRequests();
IndexNameExpressionResolver resolver = new Resolver();
ActionFilters actionFilters = new ActionFilters(new HashSet<>());
NodeClient client = new NodeClient(Settings.EMPTY, threadPool) {
@Override
public <Request extends ActionRequest, Response extends ActionResponse> void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
listener.onResponse((Response) new CreateIndexResponse(false, false, null));
}
};
if (controlled) {
return new TestTransportBulkAction(threadPool, transportService, clusterService, null, client, actionFilters, resolver, null, expected::get) {
@Override
void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses, Map<String, IndexNotFoundException> indicesThatCannotBeCreated) {
expected.set(1000000);
super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses, indicesThatCannotBeCreated);
}
};
} else {
return new TestTransportBulkAction(threadPool, transportService, clusterService, null, client, actionFilters, resolver, null, System::nanoTime) {
@Override
void executeBulk(Task task, BulkRequest bulkRequest, long startTimeNanos, ActionListener<BulkResponse> listener, AtomicArray<BulkItemResponse> responses, Map<String, IndexNotFoundException> indicesThatCannotBeCreated) {
long elapsed = spinForAtLeastOneMillisecond();
expected.set(elapsed);
super.executeBulk(task, bulkRequest, startTimeNanos, listener, responses, indicesThatCannotBeCreated);
}
};
}
}
use of org.opensearch.action.ActionRequest in project OpenSearch by opensearch-project.
the class RestValidateQueryActionTests method stubValidateQueryAction.
/**
* Configures {@link NodeClient} to stub {@link ValidateQueryAction} transport action.
* <p>
* This lower level of validation is out of the scope of this test.
*/
@BeforeClass
public static void stubValidateQueryAction() {
final TaskManager taskManager = new TaskManager(Settings.EMPTY, threadPool, Collections.emptySet());
final TransportAction transportAction = new TransportAction(ValidateQueryAction.NAME, new ActionFilters(Collections.emptySet()), taskManager) {
@Override
protected void doExecute(Task task, ActionRequest request, ActionListener listener) {
}
};
final Map<ActionType, TransportAction> actions = new HashMap<>();
actions.put(ValidateQueryAction.INSTANCE, transportAction);
client.initialize(actions, () -> "local", null, new NamedWriteableRegistry(Collections.emptyList()));
controller.registerHandler(action);
}
use of org.opensearch.action.ActionRequest in project ml-commons by opensearch-project.
the class MLTaskGetRequestTest method fromActionRequest_IOException.
@Test(expected = UncheckedIOException.class)
public void fromActionRequest_IOException() {
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new IOException("test");
}
};
MLTaskGetRequest.fromActionRequest(actionRequest);
}
use of org.opensearch.action.ActionRequest in project ml-commons by opensearch-project.
the class MLModelDeleteRequestTest method fromActionRequest_Success.
@Test
public void fromActionRequest_Success() {
MLModelDeleteRequest mlModelDeleteRequest = MLModelDeleteRequest.builder().modelId(modelId).build();
ActionRequest actionRequest = new ActionRequest() {
@Override
public ActionRequestValidationException validate() {
return null;
}
@Override
public void writeTo(StreamOutput out) throws IOException {
mlModelDeleteRequest.writeTo(out);
}
};
MLModelDeleteRequest result = MLModelDeleteRequest.fromActionRequest(actionRequest);
assertNotSame(result, mlModelDeleteRequest);
assertEquals(result.getModelId(), mlModelDeleteRequest.getModelId());
}
Aggregations