Search in sources :

Example 1 with NoOpClient

use of org.opensearch.test.client.NoOpClient in project OpenSearch by opensearch-project.

the class CreateIndexRequestBuilderTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.testClient = new NoOpClient(getTestName());
}
Also used : NoOpClient(org.opensearch.test.client.NoOpClient) Before(org.junit.Before)

Example 2 with NoOpClient

use of org.opensearch.test.client.NoOpClient in project OpenSearch by opensearch-project.

the class IndexRequestBuilderTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.testClient = new NoOpClient(getTestName());
}
Also used : NoOpClient(org.opensearch.test.client.NoOpClient) Before(org.junit.Before)

Example 3 with NoOpClient

use of org.opensearch.test.client.NoOpClient in project OpenSearch by opensearch-project.

the class ParentTaskAssigningClientTests method testSetsParentId.

public void testSetsParentId() {
    TaskId[] parentTaskId = new TaskId[] { new TaskId(randomAlphaOfLength(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> void doExecute(ActionType<Response> 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.opensearch.action.search.SearchRequest) TaskId(org.opensearch.tasks.TaskId) ActionType(org.opensearch.action.ActionType) ActionListener(org.opensearch.action.ActionListener) ActionRequest(org.opensearch.action.ActionRequest) NoOpClient(org.opensearch.test.client.NoOpClient) BulkRequest(org.opensearch.action.bulk.BulkRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) SearchRequest(org.opensearch.action.search.SearchRequest) ActionRequest(org.opensearch.action.ActionRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) ActionResponse(org.opensearch.action.ActionResponse)

Example 4 with NoOpClient

use of org.opensearch.test.client.NoOpClient in project OpenSearch by opensearch-project.

the class OriginSettingClientTests method testSetsParentId.

public void testSetsParentId() {
    String origin = randomAlphaOfLength(7);
    /*
         * This mock will do nothing but verify that origin is set in the
         * thread context before executing the action.
         */
    NoOpClient mock = new NoOpClient(getTestName()) {

        @Override
        protected <Request extends ActionRequest, Response extends ActionResponse> void doExecute(ActionType<Response> action, Request request, ActionListener<Response> listener) {
            assertEquals(origin, threadPool().getThreadContext().getTransient(ThreadContext.ACTION_ORIGIN_TRANSIENT_NAME));
            super.doExecute(action, request, listener);
        }
    };
    try (OriginSettingClient client = new OriginSettingClient(mock, origin)) {
        // All of these should have the origin set
        client.bulk(new BulkRequest());
        client.search(new SearchRequest());
        client.clearScroll(new ClearScrollRequest());
        ThreadContext threadContext = client.threadPool().getThreadContext();
        client.bulk(new BulkRequest(), listenerThatAssertsOriginNotSet(threadContext));
        client.search(new SearchRequest(), listenerThatAssertsOriginNotSet(threadContext));
        client.clearScroll(new ClearScrollRequest(), listenerThatAssertsOriginNotSet(threadContext));
    }
}
Also used : SearchRequest(org.opensearch.action.search.SearchRequest) ActionType(org.opensearch.action.ActionType) ActionListener(org.opensearch.action.ActionListener) ActionRequest(org.opensearch.action.ActionRequest) NoOpClient(org.opensearch.test.client.NoOpClient) BulkRequest(org.opensearch.action.bulk.BulkRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) SearchRequest(org.opensearch.action.search.SearchRequest) ActionRequest(org.opensearch.action.ActionRequest) ThreadContext(org.opensearch.common.util.concurrent.ThreadContext) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) ActionResponse(org.opensearch.action.ActionResponse)

Aggregations

NoOpClient (org.opensearch.test.client.NoOpClient)4 Before (org.junit.Before)2 ActionListener (org.opensearch.action.ActionListener)2 ActionRequest (org.opensearch.action.ActionRequest)2 ActionResponse (org.opensearch.action.ActionResponse)2 ActionType (org.opensearch.action.ActionType)2 BulkRequest (org.opensearch.action.bulk.BulkRequest)2 ClearScrollRequest (org.opensearch.action.search.ClearScrollRequest)2 SearchRequest (org.opensearch.action.search.SearchRequest)2 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)1 TaskId (org.opensearch.tasks.TaskId)1