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());
}
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());
}
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());
}
}
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));
}
}
Aggregations