Search in sources :

Example 1 with ActionRequestBuilder

use of org.elasticsearch.action.ActionRequestBuilder in project elasticsearch by elastic.

the class ParentTaskAssigningClientTests method testSetsParentId.

public void testSetsParentId() {
    TaskId[] parentTaskId = new TaskId[] { new TaskId(randomAsciiOfLength(3), randomLong()) };
    // This mock will do nothing but verify that parentTaskId is set on all requests sent to it.
    NoOpClient mock = new NoOpClient(getTestName()) {

        @Override
        protected <Request extends ActionRequest, Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder<Request, Response, RequestBuilder>> void doExecute(Action<Request, Response, RequestBuilder> action, Request request, ActionListener<Response> listener) {
            assertEquals(parentTaskId[0], request.getParentTask());
            super.doExecute(action, request, listener);
        }
    };
    try (ParentTaskAssigningClient client = new ParentTaskAssigningClient(mock, parentTaskId[0])) {
        // All of these should have the parentTaskId set
        client.bulk(new BulkRequest());
        client.search(new SearchRequest());
        client.clearScroll(new ClearScrollRequest());
        // Now lets verify that unwrapped calls don't have the parentTaskId set
        parentTaskId[0] = TaskId.EMPTY_TASK_ID;
        client.unwrap().bulk(new BulkRequest());
        client.unwrap().search(new SearchRequest());
        client.unwrap().clearScroll(new ClearScrollRequest());
    }
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) Action(org.elasticsearch.action.Action) TaskId(org.elasticsearch.tasks.TaskId) ActionRequest(org.elasticsearch.action.ActionRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) SearchRequest(org.elasticsearch.action.search.SearchRequest) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ActionResponse(org.elasticsearch.action.ActionResponse) ActionRequestBuilder(org.elasticsearch.action.ActionRequestBuilder) ActionListener(org.elasticsearch.action.ActionListener) ActionRequest(org.elasticsearch.action.ActionRequest) NoOpClient(org.elasticsearch.test.client.NoOpClient) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest)

Aggregations

Action (org.elasticsearch.action.Action)1 ActionListener (org.elasticsearch.action.ActionListener)1 ActionRequest (org.elasticsearch.action.ActionRequest)1 ActionRequestBuilder (org.elasticsearch.action.ActionRequestBuilder)1 ActionResponse (org.elasticsearch.action.ActionResponse)1 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)1 ClearScrollRequest (org.elasticsearch.action.search.ClearScrollRequest)1 SearchRequest (org.elasticsearch.action.search.SearchRequest)1 TaskId (org.elasticsearch.tasks.TaskId)1 NoOpClient (org.elasticsearch.test.client.NoOpClient)1