|
21 | 21 |
|
22 | 22 | import org.elasticsearch.action.ActionFuture;
|
23 | 23 | import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
| 24 | +import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; |
24 | 25 | import org.elasticsearch.action.support.IndicesOptions;
|
25 | 26 | import org.elasticsearch.action.support.PlainActionFuture;
|
26 | 27 | import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
@@ -309,14 +310,29 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
|
309 | 310 |
|
310 | 311 | public void testHealthOnMasterFailover() throws Exception {
|
311 | 312 | final String node = internalCluster().startDataOnlyNode();
|
| 313 | + boolean withIndex = randomBoolean(); |
| 314 | + if (withIndex) { |
| 315 | + // Create index with many shards to provoke the health request to wait (for green) while master is being shut down. |
| 316 | + // Notice that this is set to 0 after the test completed starting a number of health requests and master restarts. |
| 317 | + // This ensures that the cluster is yellow when the health request is made, making the health request wait on the observer, |
| 318 | + // triggering a call to observer.onClusterServiceClose when master is shutdown. |
| 319 | + createIndex("test", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, randomIntBetween(0, 10)).build()); |
| 320 | + } |
312 | 321 | final List<ActionFuture<ClusterHealthResponse>> responseFutures = new ArrayList<>();
|
313 | 322 | // Run a few health requests concurrent to master fail-overs against a data-node to make sure master failover is handled
|
314 | 323 | // without exceptions
|
315 | 324 | for (int i = 0; i < 20; ++i) {
|
316 | 325 | responseFutures.add(client(node).admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID)
|
317 |
| - .setWaitForGreenStatus().execute()); |
| 326 | + .setWaitForGreenStatus().setMasterNodeTimeout(TimeValue.timeValueMinutes(1)).execute()); |
318 | 327 | internalCluster().restartNode(internalCluster().getMasterName(), InternalTestCluster.EMPTY_CALLBACK);
|
319 | 328 | }
|
| 329 | + if (withIndex) { |
| 330 | + assertAcked( |
| 331 | + client().admin().indices() |
| 332 | + .updateSettings(new UpdateSettingsRequest("test") |
| 333 | + .settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0))).get() |
| 334 | + ); |
| 335 | + } |
320 | 336 | for (ActionFuture<ClusterHealthResponse> responseFuture : responseFutures) {
|
321 | 337 | assertSame(responseFuture.get().getStatus(), ClusterHealthStatus.GREEN);
|
322 | 338 | }
|
|
0 commit comments