Skip to content

Commit 388d3a6

Browse files
committed
fix comments
1 parent 84835fd commit 388d3a6

File tree

1 file changed

+38
-14
lines changed

1 file changed

+38
-14
lines changed

server/src/internalClusterTest/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.action.ActionRequestBuilder;
1616
import org.elasticsearch.action.ActionResponse;
1717
import org.elasticsearch.action.index.IndexResponse;
18+
import org.elasticsearch.action.support.PlainActionFuture;
1819
import org.elasticsearch.action.support.master.AcknowledgedResponse;
1920
import org.elasticsearch.cluster.ClusterState;
2021
import org.elasticsearch.cluster.ClusterStateUpdateTask;
@@ -28,6 +29,7 @@
2829
import org.elasticsearch.cluster.routing.ShardRouting;
2930
import org.elasticsearch.cluster.routing.allocation.AllocationService;
3031
import org.elasticsearch.cluster.service.ClusterService;
32+
import org.elasticsearch.common.Priority;
3133
import org.elasticsearch.common.settings.Settings;
3234
import org.elasticsearch.core.TimeValue;
3335
import org.elasticsearch.index.Index;
@@ -37,7 +39,6 @@
3739
import org.elasticsearch.indices.IndicesService;
3840
import org.elasticsearch.test.ESIntegTestCase;
3941
import org.elasticsearch.test.disruption.BlockClusterStateProcessing;
40-
import org.elasticsearch.threadpool.ThreadPool;
4142
import org.elasticsearch.transport.TransportSettings;
4243

4344
import java.util.List;
@@ -133,20 +134,43 @@ private <Req extends ActionRequest, Res extends ActionResponse> ActionFuture<Res
133134
// Wait for no publication in progress to not accidentally cancel a publication different from the one triggered by the given
134135
// request.
135136
final Coordinator masterCoordinator = internalCluster().getCurrentMasterNodeInstance(Coordinator.class);
136-
assertBusy(() -> {
137-
assertFalse(masterCoordinator.publicationInProgress());
138-
final long applierVersion = masterCoordinator.getApplierState().version();
139-
for (Coordinator instance : internalCluster().getInstances(Coordinator.class)) {
140-
assertEquals(instance.getApplierState().version(), applierVersion);
141-
}
142-
});
137+
138+
ensureNoPendingMasterTasks().actionGet(TimeValue.timeValueSeconds(30));
143139
ActionFuture<Res> future = req.execute();
144-
// cancel all commit publications produced by the request
145-
internalCluster().getCurrentMasterNodeInstance(ThreadPool.class).generic().execute(() -> {
146-
while (!future.isDone()) {
147-
masterCoordinator.cancelCommittedPublication();
148-
}
149-
});
140+
141+
// cancel the first cluster state update produced by the request above
142+
assertBusy(() -> assertTrue(masterCoordinator.cancelCommittedPublication()));
143+
// await and cancel any other forked cluster state updates that might be produced by the request
144+
var task = ensureNoPendingMasterTasks();
145+
while (task.isDone() == false) {
146+
masterCoordinator.cancelCommittedPublication();
147+
Thread.onSpinWait();
148+
}
149+
task.actionGet(TimeValue.timeValueSeconds(30));
150+
151+
return future;
152+
}
153+
154+
private PlainActionFuture<Void> ensureNoPendingMasterTasks() {
155+
var future = new PlainActionFuture<Void>();
156+
internalCluster().getCurrentMasterNodeInstance(ClusterService.class)
157+
.submitUnbatchedStateUpdateTask("test", new ClusterStateUpdateTask(Priority.LANGUID, TimeValue.timeValueSeconds(30)) {
158+
159+
@Override
160+
public ClusterState execute(ClusterState currentState) {
161+
return currentState;
162+
}
163+
164+
@Override
165+
public void clusterStateProcessed(ClusterState oldState, ClusterState newState) {
166+
future.onResponse(null);
167+
}
168+
169+
@Override
170+
public void onFailure(Exception e) {
171+
future.onFailure(e);
172+
}
173+
});
150174
return future;
151175
}
152176

0 commit comments

Comments
 (0)