|
9 | 9 | import org.elasticsearch.ElasticsearchException;
|
10 | 10 | import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksRequest;
|
11 | 11 | import org.elasticsearch.action.admin.cluster.node.tasks.list.ListTasksResponse;
|
| 12 | +import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; |
12 | 13 | import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
|
13 | 14 | import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
| 15 | +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; |
| 16 | +import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse; |
14 | 17 | import org.elasticsearch.action.admin.indices.open.OpenIndexRequest;
|
15 | 18 | import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
|
16 | 19 | import org.elasticsearch.action.admin.indices.stats.ShardStats;
|
|
19 | 22 | import org.elasticsearch.action.bulk.BulkResponse;
|
20 | 23 | import org.elasticsearch.action.get.GetResponse;
|
21 | 24 | import org.elasticsearch.action.index.IndexRequest;
|
| 25 | +import org.elasticsearch.action.support.ActiveShardCount; |
22 | 26 | import org.elasticsearch.action.support.WriteRequest;
|
23 | 27 | import org.elasticsearch.action.support.ActiveShardCount;
|
24 | 28 | import org.elasticsearch.cluster.ClusterState;
|
@@ -553,6 +557,35 @@ public void testUnknownClusterAlias() throws Exception {
|
553 | 557 | assertThat(e.getMessage(), equalTo("unknown cluster alias [another_cluster]"));
|
554 | 558 | }
|
555 | 559 |
|
| 560 | + public void testLeaderIndexRed() throws Exception { |
| 561 | + try { |
| 562 | + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); |
| 563 | + updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", "none")); |
| 564 | + assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); |
| 565 | + assertAcked(leaderClient().admin().indices().prepareCreate("index1") |
| 566 | + .setWaitForActiveShards(ActiveShardCount.NONE) |
| 567 | + .setSettings(Settings.builder() |
| 568 | + .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) |
| 569 | + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 570 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 571 | + .build())); |
| 572 | + |
| 573 | + final PutFollowAction.Request followRequest = putFollow("index1", "index2"); |
| 574 | + Exception e = expectThrows(IllegalArgumentException.class, |
| 575 | + () -> followerClient().execute(PutFollowAction.INSTANCE, followRequest).actionGet()); |
| 576 | + assertThat(e.getMessage(), equalTo("no index stats available for the leader index")); |
| 577 | + |
| 578 | + IndicesExistsResponse existsResponse = followerClient().admin().indices().exists(new IndicesExistsRequest("index2")) |
| 579 | + .actionGet(); |
| 580 | + assertThat(existsResponse.isExists(), is(false)); |
| 581 | + } finally { |
| 582 | + // Always unset allocation enable setting to avoid other assertions from failing too when this test fails: |
| 583 | + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); |
| 584 | + updateSettingsRequest.transientSettings(Settings.builder().put("cluster.routing.allocation.enable", (String) null)); |
| 585 | + assertAcked(leaderClient().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); |
| 586 | + } |
| 587 | + } |
| 588 | + |
556 | 589 | private CheckedRunnable<Exception> assertTask(final int numberOfPrimaryShards, final Map<ShardId, Long> numDocsPerShard) {
|
557 | 590 | return () -> {
|
558 | 591 | final ClusterState clusterState = followerClient().admin().cluster().prepareState().get().getState();
|
|
0 commit comments