|
23 | 23 | import org.elasticsearch.action.index.IndexRequest;
|
24 | 24 | import org.elasticsearch.action.support.WriteRequest;
|
25 | 25 | import org.elasticsearch.client.tasks.TaskSubmissionResponse;
|
| 26 | +import org.elasticsearch.common.CheckedRunnable; |
26 | 27 | import org.elasticsearch.common.settings.Settings;
|
27 | 28 | import org.elasticsearch.common.xcontent.XContentType;
|
28 | 29 | import org.elasticsearch.index.query.IdsQueryBuilder;
|
|
32 | 33 |
|
33 | 34 | import java.io.IOException;
|
34 | 35 | import java.util.Collections;
|
35 |
| -import java.util.function.BooleanSupplier; |
36 | 36 |
|
37 | 37 | public class ReindexIT extends ESRestHighLevelClientTestCase {
|
38 | 38 |
|
@@ -82,7 +82,7 @@ public void testReindex() throws IOException {
|
82 | 82 | }
|
83 | 83 | }
|
84 | 84 |
|
85 |
| - public void testReindexTask() throws IOException, InterruptedException { |
| 85 | + public void testReindexTask() throws Exception { |
86 | 86 | final String sourceIndex = "source123";
|
87 | 87 | final String destinationIndex = "dest2";
|
88 | 88 | {
|
@@ -118,20 +118,14 @@ public void testReindexTask() throws IOException, InterruptedException {
|
118 | 118 | String taskId = reindexSubmission.getTask(); // <3>
|
119 | 119 | // end::submit-reindex-task
|
120 | 120 |
|
121 |
| - BooleanSupplier hasUpgradeCompleted = checkCompletionStatus(taskId); |
122 |
| - awaitBusy(hasUpgradeCompleted); |
| 121 | + assertBusy(checkCompletionStatus(client(), taskId)); |
123 | 122 | }
|
124 | 123 | }
|
125 | 124 |
|
126 |
| - private BooleanSupplier checkCompletionStatus(String taskId) { |
| 125 | + static CheckedRunnable<Exception> checkCompletionStatus(RestClient client, String taskId) { |
127 | 126 | return () -> {
|
128 |
| - try { |
129 |
| - Response response = client().performRequest(new Request("GET", "/_tasks/" + taskId)); |
130 |
| - return (boolean) entityAsMap(response).get("completed"); |
131 |
| - } catch (IOException e) { |
132 |
| - fail(e.getMessage()); |
133 |
| - return false; |
134 |
| - } |
| 127 | + Response response = client.performRequest(new Request("GET", "/_tasks/" + taskId)); |
| 128 | + assertTrue((boolean) entityAsMap(response).get("completed")); |
135 | 129 | };
|
136 | 130 | }
|
137 | 131 | }
|
0 commit comments