|
8 | 8 | package org.elasticsearch.xpack.esql.action; |
9 | 9 |
|
10 | 10 | import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; |
| 11 | +import org.elasticsearch.client.internal.Client; |
11 | 12 | import org.elasticsearch.common.bytes.BytesReference; |
12 | 13 | import org.elasticsearch.common.xcontent.XContentHelper; |
| 14 | +import org.elasticsearch.compute.operator.DriverStatus; |
| 15 | +import org.elasticsearch.compute.operator.DriverTaskRunner; |
13 | 16 | import org.elasticsearch.plugins.Plugin; |
| 17 | +import org.elasticsearch.tasks.TaskInfo; |
14 | 18 | import org.elasticsearch.xcontent.json.JsonXContent; |
15 | 19 | import org.elasticsearch.xpack.core.async.AsyncStopRequest; |
16 | 20 | import org.elasticsearch.xpack.esql.plan.logical.Enrich; |
|
31 | 35 | import static org.elasticsearch.xpack.esql.action.EsqlAsyncTestUtils.deleteAsyncId; |
32 | 36 | import static org.elasticsearch.xpack.esql.action.EsqlAsyncTestUtils.startAsyncQuery; |
33 | 37 | import static org.elasticsearch.xpack.esql.action.EsqlAsyncTestUtils.waitForCluster; |
| 38 | +import static org.hamcrest.Matchers.empty; |
34 | 39 | import static org.hamcrest.Matchers.equalTo; |
| 40 | +import static org.hamcrest.Matchers.not; |
35 | 41 |
|
36 | 42 | // This tests if enrich after stop works correctly |
37 | 43 | public class CrossClusterAsyncEnrichStopIT extends AbstractEnrichBasedCrossClusterTestCase { |
@@ -87,10 +93,27 @@ public void testEnrichAfterStop() throws Exception { |
87 | 93 | // wait until c1 is done |
88 | 94 | waitForCluster(client(), "c1", asyncExecutionId); |
89 | 95 | waitForCluster(client(), LOCAL_CLUSTER, asyncExecutionId); |
| 96 | + // wait until remote reduce task starts on c2 |
| 97 | + assertBusy(() -> { |
| 98 | + List<TaskInfo> tasks = getDriverTasks(client(REMOTE_CLUSTER_2)); |
| 99 | + List<TaskInfo> reduceTasks = tasks.stream() |
| 100 | + .filter(t -> t.status() instanceof DriverStatus ds && ds.taskDescription().equals("remote_reduce")) |
| 101 | + .toList(); |
| 102 | + assertThat(reduceTasks, not(empty())); |
| 103 | + }); |
90 | 104 |
|
91 | 105 | // Run the stop request |
92 | 106 | var stopRequest = new AsyncStopRequest(asyncExecutionId); |
93 | 107 | var stopAction = client().execute(EsqlAsyncStopAction.INSTANCE, stopRequest); |
| 108 | + // wait until remote reduce tasks are gone |
| 109 | + assertBusy(() -> { |
| 110 | + List<TaskInfo> tasks = getDriverTasks(client(REMOTE_CLUSTER_2)); |
| 111 | + List<TaskInfo> reduceTasks = tasks.stream() |
| 112 | + .filter(t -> t.status() instanceof DriverStatus ds && ds.taskDescription().equals("remote_reduce")) |
| 113 | + .toList(); |
| 114 | + assertThat(reduceTasks, empty()); |
| 115 | + }); |
| 116 | + |
94 | 117 | // Allow the processing to proceed |
95 | 118 | SimplePauseFieldPlugin.allowEmitting.countDown(); |
96 | 119 |
|
@@ -153,4 +176,8 @@ record Event(long timestamp, String user, String host) {} |
153 | 176 | } |
154 | 177 | client.admin().indices().prepareRefresh("events").get(); |
155 | 178 | } |
| 179 | + |
| 180 | + static List<TaskInfo> getDriverTasks(Client client) { |
| 181 | + return client.admin().cluster().prepareListTasks().setActions(DriverTaskRunner.ACTION_NAME).setDetailed(true).get().getTasks(); |
| 182 | + } |
156 | 183 | } |
0 commit comments