use of org.opensearch.test.client.NoOpNodeClient in project OpenSearch by opensearch-project.
the class RestBulkActionTests method testBulkPipelineUpsert.
public void testBulkPipelineUpsert() throws Exception {
SetOnce<Boolean> bulkCalled = new SetOnce<>();
try (NodeClient verifyingClient = new NoOpNodeClient(this.getTestName()) {
@Override
public void bulk(BulkRequest request, ActionListener<BulkResponse> listener) {
bulkCalled.set(true);
assertThat(request.requests(), hasSize(2));
UpdateRequest updateRequest = (UpdateRequest) request.requests().get(1);
assertThat(updateRequest.upsertRequest().getPipeline(), equalTo("timestamps"));
}
}) {
final Map<String, String> params = new HashMap<>();
params.put("pipeline", "timestamps");
new RestBulkAction(settings(Version.CURRENT).build()).handleRequest(new FakeRestRequest.Builder(xContentRegistry()).withPath("my_index/_bulk").withParams(params).withContent(new BytesArray("{\"index\":{\"_id\":\"1\"}}\n" + "{\"field1\":\"val1\"}\n" + "{\"update\":{\"_id\":\"2\"}}\n" + "{\"script\":{\"source\":\"ctx._source.counter++;\"},\"upsert\":{\"field1\":\"upserted_val\"}}\n"), XContentType.JSON).withMethod(RestRequest.Method.POST).build(), mock(RestChannel.class), verifyingClient);
assertThat(bulkCalled.get(), equalTo(true));
}
}
use of org.opensearch.test.client.NoOpNodeClient in project OpenSearch by opensearch-project.
the class RestAnalyzeActionTests method testParseXContentForAnalyzeRequestWithInvalidJsonThrowsException.
public void testParseXContentForAnalyzeRequestWithInvalidJsonThrowsException() {
RestAnalyzeAction action = new RestAnalyzeAction();
RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build();
try (NodeClient client = new NoOpNodeClient(this.getClass().getSimpleName())) {
IOException e = expectThrows(IOException.class, () -> action.handleRequest(request, null, client));
assertThat(e.getMessage(), containsString("expecting double-quote"));
}
}
Aggregations