Skip to content

Commit 8953adc

Browse files
committed
Remove leftover usage of deprecated client API
See #31200 & ##31069
1 parent 9d3f278 commit 8953adc

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

client/rest-high-level/src/main/java/org/elasticsearch/client/TasksClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public CancelTasksResponse cancel(CancelTasksRequest cancelTasksRequest, Request
8484
cancelTasksRequest,
8585
RequestConverters::cancelTasks,
8686
options,
87-
parser -> CancelTasksResponse.fromXContent(parser),
87+
CancelTasksResponse::fromXContent,
8888
emptySet()
8989
);
9090
}
@@ -103,7 +103,7 @@ public void cancelAsync(CancelTasksRequest cancelTasksRequest, RequestOptions op
103103
cancelTasksRequest,
104104
RequestConverters::cancelTasks,
105105
options,
106-
parser -> CancelTasksResponse.fromXContent(parser),
106+
CancelTasksResponse::fromXContent,
107107
listener,
108108
emptySet()
109109
);

client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
public class BulkProcessorIT extends ESRestHighLevelClientTestCase {
5757

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

6263
public void testThatBulkProcessorCountIsCorrect() throws Exception {

client/rest-high-level/src/test/java/org/elasticsearch/client/BulkProcessorRetryIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class BulkProcessorRetryIT extends ESRestHighLevelClientTestCase {
4848
private static final String TYPE_NAME = "type";
4949

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

5455
public void testBulkRejectionLoadWithoutBackoff() throws Exception {

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ public ActionRequestValidationException validate() {
189189

190190
{
191191
ActionRequestValidationException actualException = expectThrows(ActionRequestValidationException.class,
192-
() -> restHighLevelClient.performRequest(request, null, null, null));
192+
() -> restHighLevelClient.performRequest(request, null, RequestOptions.DEFAULT, null, null));
193193
assertSame(validationException, actualException);
194194
}
195195
{
196196
TrackingActionListener trackingActionListener = new TrackingActionListener();
197-
restHighLevelClient.performRequestAsync(request, null, null, trackingActionListener, null);
197+
restHighLevelClient.performRequestAsync(request, null, RequestOptions.DEFAULT, null, trackingActionListener, null);
198198
assertSame(validationException, trackingActionListener.exception.get());
199199
}
200200
}
@@ -308,13 +308,13 @@ public void testPerformRequestOnSuccess() throws IOException {
308308
Response mockResponse = new Response(REQUEST_LINE, new HttpHost("localhost", 9200), httpResponse);
309309
when(restClient.performRequest(any(Request.class))).thenReturn(mockResponse);
310310
{
311-
Integer result = restHighLevelClient.performRequest(mainRequest, requestConverter,
311+
Integer result = restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
312312
response -> response.getStatusLine().getStatusCode(), Collections.emptySet());
313313
assertEquals(restStatus.getStatus(), result.intValue());
314314
}
315315
{
316316
IOException ioe = expectThrows(IOException.class, () -> restHighLevelClient.performRequest(mainRequest,
317-
requestConverter, response -> {throw new IllegalStateException();}, Collections.emptySet()));
317+
requestConverter, RequestOptions.DEFAULT, response -> {throw new IllegalStateException();}, Collections.emptySet()));
318318
assertEquals("Unable to parse response body for Response{requestLine=GET / http/1.1, host=http://localhost:9200, " +
319319
"response=http/1.1 " + restStatus.getStatus() + " " + restStatus.name() + "}", ioe.getMessage());
320320
}
@@ -329,7 +329,7 @@ public void testPerformRequestOnResponseExceptionWithoutEntity() throws IOExcept
329329
ResponseException responseException = new ResponseException(mockResponse);
330330
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
331331
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
332-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
332+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
333333
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
334334
assertEquals(responseException.getMessage(), elasticsearchException.getMessage());
335335
assertEquals(restStatus, elasticsearchException.status());
@@ -347,7 +347,7 @@ public void testPerformRequestOnResponseExceptionWithEntity() throws IOException
347347
ResponseException responseException = new ResponseException(mockResponse);
348348
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
349349
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
350-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
350+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
351351
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
352352
assertEquals("Elasticsearch exception [type=exception, reason=test error message]", elasticsearchException.getMessage());
353353
assertEquals(restStatus, elasticsearchException.status());
@@ -364,7 +364,7 @@ public void testPerformRequestOnResponseExceptionWithBrokenEntity() throws IOExc
364364
ResponseException responseException = new ResponseException(mockResponse);
365365
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
366366
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
367-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
367+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
368368
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
369369
assertEquals("Unable to parse response body", elasticsearchException.getMessage());
370370
assertEquals(restStatus, elasticsearchException.status());
@@ -382,7 +382,7 @@ public void testPerformRequestOnResponseExceptionWithBrokenEntity2() throws IOEx
382382
ResponseException responseException = new ResponseException(mockResponse);
383383
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
384384
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
385-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
385+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
386386
response -> response.getStatusLine().getStatusCode(), Collections.emptySet()));
387387
assertEquals("Unable to parse response body", elasticsearchException.getMessage());
388388
assertEquals(restStatus, elasticsearchException.status());
@@ -398,7 +398,7 @@ public void testPerformRequestOnResponseExceptionWithIgnores() throws IOExceptio
398398
ResponseException responseException = new ResponseException(mockResponse);
399399
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
400400
//although we got an exception, we turn it into a successful response because the status code was provided among ignores
401-
assertEquals(Integer.valueOf(404), restHighLevelClient.performRequest(mainRequest, requestConverter,
401+
assertEquals(Integer.valueOf(404), restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
402402
response -> response.getStatusLine().getStatusCode(), Collections.singleton(404)));
403403
}
404404

@@ -410,7 +410,7 @@ public void testPerformRequestOnResponseExceptionWithIgnoresErrorNoBody() throws
410410
ResponseException responseException = new ResponseException(mockResponse);
411411
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
412412
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
413-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
413+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
414414
response -> {throw new IllegalStateException();}, Collections.singleton(404)));
415415
assertEquals(RestStatus.NOT_FOUND, elasticsearchException.status());
416416
assertSame(responseException, elasticsearchException.getCause());
@@ -427,7 +427,7 @@ public void testPerformRequestOnResponseExceptionWithIgnoresErrorValidBody() thr
427427
ResponseException responseException = new ResponseException(mockResponse);
428428
when(restClient.performRequest(any(Request.class))).thenThrow(responseException);
429429
ElasticsearchException elasticsearchException = expectThrows(ElasticsearchException.class,
430-
() -> restHighLevelClient.performRequest(mainRequest, requestConverter,
430+
() -> restHighLevelClient.performRequest(mainRequest, requestConverter, RequestOptions.DEFAULT,
431431
response -> {throw new IllegalStateException();}, Collections.singleton(404)));
432432
assertEquals(RestStatus.NOT_FOUND, elasticsearchException.status());
433433
assertSame(responseException, elasticsearchException.getSuppressed()[0]);

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/CRUDDocumentationIT.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import java.util.Map;
7373
import java.util.concurrent.CountDownLatch;
7474
import java.util.concurrent.TimeUnit;
75+
import java.util.function.BiConsumer;
7576

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

757758
// tag::bulk-execute-async
758-
client.bulkAsync(request, listener); // <1>
759+
client.bulkAsync(request, RequestOptions.DEFAULT, listener); // <1>
759760
// end::bulk-execute-async
760761

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

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

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

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

11911195
// tag::multi-get-execute-async
1192-
client.multiGetAsync(request, listener); // <1>
1196+
client.multiGetAsync(request, RequestOptions.DEFAULT, listener); // <1>
11931197
// end::multi-get-execute-async
11941198

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

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ public void testGetMapping() throws IOException {
576576
RestHighLevelClient client = highLevelClient();
577577

578578
{
579-
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
579+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
580580
assertTrue(createIndexResponse.isAcknowledged());
581581
PutMappingRequest request = new PutMappingRequest("twitter");
582582
request.type("tweet");
@@ -589,7 +589,7 @@ public void testGetMapping() throws IOException {
589589
" }\n" +
590590
"}", // <1>
591591
XContentType.JSON);
592-
PutMappingResponse putMappingResponse = client.indices().putMapping(request);
592+
PutMappingResponse putMappingResponse = client.indices().putMapping(request, RequestOptions.DEFAULT);
593593
assertTrue(putMappingResponse.isAcknowledged());
594594
}
595595

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

635635
{
636-
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"));
636+
CreateIndexResponse createIndexResponse = client.indices().create(new CreateIndexRequest("twitter"), RequestOptions.DEFAULT);
637637
assertTrue(createIndexResponse.isAcknowledged());
638638
PutMappingRequest request = new PutMappingRequest("twitter");
639639
request.type("tweet");

client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/SearchDocumentationIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public void onFailure(Exception e) {
628628
scrollListener = new LatchedActionListener<>(scrollListener, latch);
629629

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

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

0 commit comments

Comments
 (0)