|
59 | 59 | import org.elasticsearch.script.Script; |
60 | 60 | import org.elasticsearch.script.ScriptType; |
61 | 61 | import org.elasticsearch.search.fetch.subphase.FetchSourceContext; |
62 | | -import org.elasticsearch.threadpool.Scheduler; |
63 | 62 |
|
64 | 63 | import java.io.IOException; |
65 | 64 | import java.util.Collections; |
|
87 | 86 | */ |
88 | 87 | public class CRUDDocumentationIT extends ESRestHighLevelClientTestCase { |
89 | 88 |
|
90 | | - public void testIndex() throws IOException { |
| 89 | + public void testIndex() throws Exception { |
91 | 90 | RestHighLevelClient client = highLevelClient(); |
92 | 91 |
|
93 | 92 | { |
@@ -167,20 +166,6 @@ public void testIndex() throws IOException { |
167 | 166 | } |
168 | 167 | } |
169 | 168 | // end::index-response |
170 | | - |
171 | | - // tag::index-execute-async |
172 | | - client.indexAsync(request, new ActionListener<IndexResponse>() { |
173 | | - @Override |
174 | | - public void onResponse(IndexResponse indexResponse) { |
175 | | - // <1> |
176 | | - } |
177 | | - |
178 | | - @Override |
179 | | - public void onFailure(Exception e) { |
180 | | - // <2> |
181 | | - } |
182 | | - }); |
183 | | - // end::index-execute-async |
184 | 169 | } |
185 | 170 | { |
186 | 171 | IndexRequest request = new IndexRequest("posts", "doc", "1"); |
@@ -240,9 +225,28 @@ public void onFailure(Exception e) { |
240 | 225 | } |
241 | 226 | // end::index-optype |
242 | 227 | } |
| 228 | + { |
| 229 | + IndexRequest request = new IndexRequest("posts", "doc", "async").source("field", "value"); |
| 230 | + |
| 231 | + // tag::index-execute-async |
| 232 | + client.indexAsync(request, new ActionListener<IndexResponse>() { |
| 233 | + @Override |
| 234 | + public void onResponse(IndexResponse indexResponse) { |
| 235 | + // <1> |
| 236 | + } |
| 237 | + |
| 238 | + @Override |
| 239 | + public void onFailure(Exception e) { |
| 240 | + // <2> |
| 241 | + } |
| 242 | + }); |
| 243 | + // end::index-execute-async |
| 244 | + |
| 245 | + assertBusy(() -> assertTrue(client.exists(new GetRequest("posts", "doc", "async")))); |
| 246 | + } |
243 | 247 | } |
244 | 248 |
|
245 | | - public void testUpdate() throws IOException { |
| 249 | + public void testUpdate() throws Exception { |
246 | 250 | RestHighLevelClient client = highLevelClient(); |
247 | 251 | { |
248 | 252 | IndexRequest indexRequest = new IndexRequest("posts", "doc", "1").source("field", 0); |
@@ -378,20 +382,6 @@ public void testUpdate() throws IOException { |
378 | 382 | } |
379 | 383 | } |
380 | 384 | // end::update-failure |
381 | | - |
382 | | - // tag::update-execute-async |
383 | | - client.updateAsync(request, new ActionListener<UpdateResponse>() { |
384 | | - @Override |
385 | | - public void onResponse(UpdateResponse updateResponse) { |
386 | | - // <1> |
387 | | - } |
388 | | - |
389 | | - @Override |
390 | | - public void onFailure(Exception e) { |
391 | | - // <2> |
392 | | - } |
393 | | - }); |
394 | | - // end::update-execute-async |
395 | 385 | } |
396 | 386 | { |
397 | 387 | //tag::update-docnotfound |
@@ -497,9 +487,28 @@ public void onFailure(Exception e) { |
497 | 487 | request.waitForActiveShards(ActiveShardCount.ALL); // <2> |
498 | 488 | // end::update-request-active-shards |
499 | 489 | } |
| 490 | + { |
| 491 | + UpdateRequest request = new UpdateRequest("posts", "doc", "async").doc("reason", "async update").docAsUpsert(true); |
| 492 | + |
| 493 | + // tag::update-execute-async |
| 494 | + client.updateAsync(request, new ActionListener<UpdateResponse>() { |
| 495 | + @Override |
| 496 | + public void onResponse(UpdateResponse updateResponse) { |
| 497 | + // <1> |
| 498 | + } |
| 499 | + |
| 500 | + @Override |
| 501 | + public void onFailure(Exception e) { |
| 502 | + // <2> |
| 503 | + } |
| 504 | + }); |
| 505 | + // end::update-execute-async |
| 506 | + |
| 507 | + assertBusy(() -> assertTrue(client.exists(new GetRequest("posts", "doc", "async")))); |
| 508 | + } |
500 | 509 | } |
501 | 510 |
|
502 | | - public void testDelete() throws IOException { |
| 511 | + public void testDelete() throws Exception { |
503 | 512 | RestHighLevelClient client = highLevelClient(); |
504 | 513 |
|
505 | 514 | { |
@@ -536,20 +545,6 @@ public void testDelete() throws IOException { |
536 | 545 | } |
537 | 546 | } |
538 | 547 | // end::delete-response |
539 | | - |
540 | | - // tag::delete-execute-async |
541 | | - client.deleteAsync(request, new ActionListener<DeleteResponse>() { |
542 | | - @Override |
543 | | - public void onResponse(DeleteResponse deleteResponse) { |
544 | | - // <1> |
545 | | - } |
546 | | - |
547 | | - @Override |
548 | | - public void onFailure(Exception e) { |
549 | | - // <2> |
550 | | - } |
551 | | - }); |
552 | | - // end::delete-execute-async |
553 | 548 | } |
554 | 549 |
|
555 | 550 | { |
@@ -601,6 +596,28 @@ public void onFailure(Exception e) { |
601 | 596 | } |
602 | 597 | // end::delete-conflict |
603 | 598 | } |
| 599 | + { |
| 600 | + IndexResponse indexResponse = client.index(new IndexRequest("posts", "doc", "async").source("field", "value")); |
| 601 | + assertSame(indexResponse.status(), RestStatus.CREATED); |
| 602 | + |
| 603 | + DeleteRequest request = new DeleteRequest("posts", "doc", "async"); |
| 604 | + |
| 605 | + // tag::delete-execute-async |
| 606 | + client.deleteAsync(request, new ActionListener<DeleteResponse>() { |
| 607 | + @Override |
| 608 | + public void onResponse(DeleteResponse deleteResponse) { |
| 609 | + // <1> |
| 610 | + } |
| 611 | + |
| 612 | + @Override |
| 613 | + public void onFailure(Exception e) { |
| 614 | + // <2> |
| 615 | + } |
| 616 | + }); |
| 617 | + // end::delete-execute-async |
| 618 | + |
| 619 | + assertBusy(() -> assertFalse(client.exists(new GetRequest("posts", "doc", "async")))); |
| 620 | + } |
604 | 621 | } |
605 | 622 |
|
606 | 623 | public void testBulk() throws IOException { |
|
0 commit comments