Skip to content

Commit

Permalink
Remove leftover usage of deprecated client API
Browse files Browse the repository at this point in the history
See #31200 & ##31069
  • Loading branch information
javanna committed Jun 13, 2018
1 parent 9d3f278 commit 8953adc
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public CancelTasksResponse cancel(CancelTasksRequest cancelTasksRequest, Request
cancelTasksRequest,
RequestConverters::cancelTasks,
options,
parser -> CancelTasksResponse.fromXContent(parser),
CancelTasksResponse::fromXContent,
emptySet()
);
}
Expand All @@ -103,7 +103,7 @@ public void cancelAsync(CancelTasksRequest cancelTasksRequest, RequestOptions op
cancelTasksRequest,
RequestConverters::cancelTasks,
options,
parser -> CancelTasksResponse.fromXContent(parser),
CancelTasksResponse::fromXContent,
listener,
emptySet()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
public class BulkProcessorIT extends ESRestHighLevelClientTestCase {

private static BulkProcessor.Builder initBulkProcessorBuilder(BulkProcessor.Listener listener) {
return BulkProcessor.builder(highLevelClient()::bulkAsync, listener);
return BulkProcessor.builder(
(request, bulkListener) -> highLevelClient().bulkAsync(request, RequestOptions.DEFAULT, bulkListener), listener);
}

public void testThatBulkProcessorCountIsCorrect() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
private static final String TYPE_NAME = "type";

private static BulkProcessor.Builder initBulkProcessorBuilder(BulkProcessor.Listener listener) {
return BulkProcessor.builder(highLevelClient()::bulkAsync, listener);
return BulkProcessor.builder(
(request, bulkListener) -> highLevelClient().bulkAsync(request, RequestOptions.DEFAULT, bulkListener), listener);
}

public void testBulkRejectionLoadWithoutBackoff() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ public ActionRequestValidationException validate() {

{
ActionRequestValidationException actualException = expectThrows(ActionRequestValidationException.class,
() -> restHighLevelClient.performRequest(request, null, null, null));
() -> restHighLevelClient.performRequest(request, null, RequestOptions.DEFAULT, null, null));
assertSame(validationException, actualException);
}
{
TrackingActionListener trackingActionListener = new TrackingActionListener();
restHighLevelClient.performRequestAsync(request, null, null, trackingActionListener, null);
restHighLevelClient.performRequestAsync(request, null, RequestOptions.DEFAULT, null, trackingActionListener, null);
assertSame(validationException, trackingActionListener.exception.get());
}
}
Expand Down Expand Up @@ -308,13 +308,13 @@ public void testPerformRequestOnSuccess() throws IOException {
Response mockResponse = new Response(REQUEST_LINE, new HttpHost("localhost", 9200), httpResponse);
when(restClient.performRequest(any(Request.class))).thenReturn(mockResponse);
{
Integer result = restHighLevelClient.performRequest(mainRequest, requestConverter,
Integer result = restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.emptySet());
assertEquals(restStatus.getStatus(), result.intValue());
}
{
IOException ioe = expectThrows(IOException.class, () -> restHighLevelClient.performRequest(mainRequest,
requestConverter, response -> {throw new IllegalStateException();}, Collections.emptySet()));
requestConverter, RequestOptions.DEFAULT, response -> {throw new IllegalStateException();}, Collections.emptySet()));
assertEquals("Unable to parse response body for Response{requestLine=GET / http/1.1, host=http://localhost:9200, " +
"response=http/1.1 " + restStatus.getStatus() + " " + restStatus.name() + "}", ioe.getMessage());
}
Expand All @@ -329,7 +329,7 @@ public void testPerformRequestOnResponseExceptionWithoutEntity() throws IOExcept
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
assertEquals(responseException.getMessage(), elasticsearchException.getMessage());
assertEquals(restStatus, elasticsearchException.status());
Expand All @@ -347,7 +347,7 @@ public void testPerformRequestOnResponseExceptionWithEntity() throws IOException
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
assertEquals("Elasticsearch exception [type=exception, reason=test error message]", elasticsearchException.getMessage());
assertEquals(restStatus, elasticsearchException.status());
Expand All @@ -364,7 +364,7 @@ public void testPerformRequestOnResponseExceptionWithBrokenEntity() throws IOExc
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
assertEquals("Unable to parse response body", elasticsearchException.getMessage());
assertEquals(restStatus, elasticsearchException.status());
Expand All @@ -382,7 +382,7 @@ public void testPerformRequestOnResponseExceptionWithBrokenEntity2() throws IOEx
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
assertEquals("Unable to parse response body", elasticsearchException.getMessage());
assertEquals(restStatus, elasticsearchException.status());
Expand All @@ -398,7 +398,7 @@ public void testPerformRequestOnResponseExceptionWithIgnores() throws IOExceptio
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
//although we got an exception, we turn it into a successful response because the status code was provided among ignores
assertEquals(Integer.valueOf(404), restHighLevelClient.performRequest(mainRequest, requestConverter,
assertEquals(Integer.valueOf(404), restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> response.getStatusLine().getStatusCode(), Collections.singleton(404)));
}

Expand All @@ -410,7 +410,7 @@ public void testPerformRequestOnResponseExceptionWithIgnoresErrorNoBody() throws
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> {throw new IllegalStateException();}, Collections.singleton(404)));
assertEquals(RestStatus.NOT_FOUND, elasticsearchException.status());
assertSame(responseException, elasticsearchException.getCause());
Expand All @@ -427,7 +427,7 @@ public void testPerformRequestOnResponseExceptionWithIgnoresErrorValidBody() thr
ResponseException responseException = new ResponseException(mockResponse);
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
response -> {throw new IllegalStateException();}, Collections.singleton(404)));
assertEquals(RestStatus.NOT_FOUND, elasticsearchException.status());
assertSame(responseException, elasticsearchException.getSuppressed()[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import static java.util.Collections.singletonMap;
import static org.hamcrest.Matchers.arrayWithSize;
Expand Down Expand Up @@ -755,7 +756,7 @@ public void onFailure(Exception e) {
listener = new LatchedActionListener<>(listener, latch);

// tag::bulk-execute-async
client.bulkAsync(request, listener); // <1>
client.bulkAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::bulk-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand Down Expand Up @@ -1007,8 +1008,9 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
}
};

BulkProcessor bulkProcessor =
BulkProcessor.builder(client::bulkAsync, listener).build(); // <5>
BiConsumer<BulkRequest, ActionListener<BulkResponse>> bulkConsumer =
(request, bulkListener) -> highLevelClient().bulkAsync(request, RequestOptions.DEFAULT, bulkListener);
BulkProcessor bulkProcessor = BulkProcessor.builder(bulkConsumer, listener).build(); // <5>
// end::bulk-processor-init
assertNotNull(bulkProcessor);

Expand Down Expand Up @@ -1066,7 +1068,9 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
// end::bulk-processor-listener

// tag::bulk-processor-options
BulkProcessor.Builder builder = BulkProcessor.builder(client::bulkAsync, listener);
BiConsumer<BulkRequest, ActionListener<BulkResponse>> bulkConsumer =
(request, bulkListener) -> highLevelClient().bulkAsync(request, RequestOptions.DEFAULT, bulkListener);
BulkProcessor.Builder builder = BulkProcessor.builder(bulkConsumer, listener);
builder.setBulkActions(500); // <1>
builder.setBulkSize(new ByteSizeValue(1L, ByteSizeUnit.MB)); // <2>
builder.setConcurrentRequests(0); // <3>
Expand Down Expand Up @@ -1189,7 +1193,7 @@ public void onFailure(Exception e) {
listener = new LatchedActionListener<>(listener, latch);

// tag::multi-get-execute-async
client.multiGetAsync(request, listener); // <1>
client.multiGetAsync(request, RequestOptions.DEFAULT, listener); // <1>
// end::multi-get-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ public void testGetMapping() throws IOException {
RestHighLevelClient client = highLevelClient();

{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
Expand All @@ -589,7 +589,7 @@ public void testGetMapping() throws IOException {
" }\n" +
"}", // <1>
XContentType.JSON);
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
assertTrue(putMappingResponse.isAcknowledged());
}

Expand Down Expand Up @@ -633,7 +633,7 @@ public void testGetMappingAsync() throws Exception {
final RestHighLevelClient client = highLevelClient();

{
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
assertTrue(createIndexResponse.isAcknowledged());
PutMappingRequest request = new PutMappingRequest("twitter");
request.type("tweet");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public void onFailure(Exception e) {
scrollListener = new LatchedActionListener<>(scrollListener, latch);

// tag::search-scroll-execute-async
client.searchScrollAsync(scrollRequest, scrollListener); // <1>
client.searchScrollAsync(scrollRequest, RequestOptions.DEFAULT, scrollListener); // <1>
// end::search-scroll-execute-async

assertTrue(latch.await(30L, TimeUnit.SECONDS));
Expand Down

0 comments on commit 8953adc

Please sign in to comment.