|
33 | 33 | import org.elasticsearch.client.RequestOptions;
|
34 | 34 | import org.elasticsearch.client.Response;
|
35 | 35 | import org.elasticsearch.client.RestHighLevelClient;
|
| 36 | +import org.elasticsearch.client.ccr.DeleteAutoFollowPatternRequest; |
36 | 37 | import org.elasticsearch.client.ccr.PauseFollowRequest;
|
37 | 38 | import org.elasticsearch.client.ccr.PutAutoFollowPatternRequest;
|
38 | 39 | import org.elasticsearch.client.ccr.PutFollowRequest;
|
@@ -401,10 +402,9 @@ public void testPutAutoFollowPattern() throws Exception {
|
401 | 402 |
|
402 | 403 | // Delete auto follow pattern, so that we can store it again:
|
403 | 404 | {
|
404 |
| - // TODO: replace with hlrc delete auto follow pattern when it is available: |
405 |
| - final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern"); |
406 |
| - Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest)); |
407 |
| - assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true)); |
| 405 | + final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); |
| 406 | + AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); |
| 407 | + assertThat(deleteResponse.isAcknowledged(), is(true)); |
408 | 408 | }
|
409 | 409 |
|
410 | 410 | // tag::ccr-put-auto-follow-pattern-execute-listener
|
@@ -435,13 +435,72 @@ public void onFailure(Exception e) {
|
435 | 435 |
|
436 | 436 | // Cleanup:
|
437 | 437 | {
|
438 |
| - // TODO: replace with hlrc delete auto follow pattern when it is available: |
439 |
| - final Request deleteRequest = new Request("DELETE", "/_ccr/auto_follow/my_pattern"); |
440 |
| - Map<?, ?> deleteAutoFollowPatternResponse = toMap(client().performRequest(deleteRequest)); |
441 |
| - assertThat(deleteAutoFollowPatternResponse.get("acknowledged"), is(true)); |
| 438 | + final DeleteAutoFollowPatternRequest deleteRequest = new DeleteAutoFollowPatternRequest("my_pattern"); |
| 439 | + AcknowledgedResponse deleteResponse = client.ccr().deleteAutoFollowPattern(deleteRequest, RequestOptions.DEFAULT); |
| 440 | + assertThat(deleteResponse.isAcknowledged(), is(true)); |
442 | 441 | }
|
443 | 442 | }
|
444 | 443 |
|
| 444 | + public void testDeleteAutoFollowPattern() throws Exception { |
| 445 | + RestHighLevelClient client = highLevelClient(); |
| 446 | + |
| 447 | + // Put auto follow pattern, so that we can delete it: |
| 448 | + { |
| 449 | + final PutAutoFollowPatternRequest putRequest = |
| 450 | + new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*")); |
| 451 | + AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); |
| 452 | + assertThat(putResponse.isAcknowledged(), is(true)); |
| 453 | + } |
| 454 | + |
| 455 | + // tag::ccr-delete-auto-follow-pattern-request |
| 456 | + DeleteAutoFollowPatternRequest request = |
| 457 | + new DeleteAutoFollowPatternRequest("my_pattern"); // <1> |
| 458 | + // end::ccr-delete-auto-follow-pattern-request |
| 459 | + |
| 460 | + // tag::ccr-delete-auto-follow-pattern-execute |
| 461 | + AcknowledgedResponse response = client.ccr() |
| 462 | + .deleteAutoFollowPattern(request, RequestOptions.DEFAULT); |
| 463 | + // end::ccr-delete-auto-follow-pattern-execute |
| 464 | + |
| 465 | + // tag::ccr-delete-auto-follow-pattern-response |
| 466 | + boolean acknowledged = response.isAcknowledged(); // <1> |
| 467 | + // end::ccr-delete-auto-follow-pattern-response |
| 468 | + |
| 469 | + // Put auto follow pattern, so that we can delete it again: |
| 470 | + { |
| 471 | + final PutAutoFollowPatternRequest putRequest = |
| 472 | + new PutAutoFollowPatternRequest("my_pattern", "local", Collections.singletonList("logs-*")); |
| 473 | + AcknowledgedResponse putResponse = client.ccr().putAutoFollowPattern(putRequest, RequestOptions.DEFAULT); |
| 474 | + assertThat(putResponse.isAcknowledged(), is(true)); |
| 475 | + } |
| 476 | + |
| 477 | + // tag::ccr-delete-auto-follow-pattern-execute-listener |
| 478 | + ActionListener<AcknowledgedResponse> listener = |
| 479 | + new ActionListener<AcknowledgedResponse>() { |
| 480 | + @Override |
| 481 | + public void onResponse(AcknowledgedResponse response) { // <1> |
| 482 | + boolean acknowledged = response.isAcknowledged(); |
| 483 | + } |
| 484 | + |
| 485 | + @Override |
| 486 | + public void onFailure(Exception e) { |
| 487 | + // <2> |
| 488 | + } |
| 489 | + }; |
| 490 | + // end::ccr-delete-auto-follow-pattern-execute-listener |
| 491 | + |
| 492 | + // Replace the empty listener by a blocking listener in test |
| 493 | + final CountDownLatch latch = new CountDownLatch(1); |
| 494 | + listener = new LatchedActionListener<>(listener, latch); |
| 495 | + |
| 496 | + // tag::ccr-delete-auto-follow-pattern-execute-async |
| 497 | + client.ccr().deleteAutoFollowPatternAsync(request, |
| 498 | + RequestOptions.DEFAULT, listener); // <1> |
| 499 | + // end::ccr-delete-auto-follow-pattern-execute-async |
| 500 | + |
| 501 | + assertTrue(latch.await(30L, TimeUnit.SECONDS)); |
| 502 | + } |
| 503 | + |
445 | 504 | static Map<String, Object> toMap(Response response) throws IOException {
|
446 | 505 | return XContentHelper.convertToMap(JsonXContent.jsonXContent, EntityUtils.toString(response.getEntity()), false);
|
447 | 506 | }
|
|
0 commit comments