From 952097b1c063e566851eb4aea1af28cb1acaf9c2 Mon Sep 17 00:00:00 2001 From: Yannick Welsch Date: Thu, 27 Oct 2016 12:02:00 +0200 Subject: [PATCH] [TEST] Fix testDelayShards to wait for master to remove stopped node This test failed when the node that was shutting down was not yet removed from the cluster state on the master. The cluster allocation explain API will not see any unassigned shards until the node shutting down is removed from the cluster state. --- .../allocation/ClusterAllocationExplainIT.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java index 97c1a20c33f..23fdf3499b2 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainIT.java @@ -19,7 +19,6 @@ package org.elasticsearch.action.admin.cluster.allocation; -import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse; import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresResponse; import org.elasticsearch.action.support.ActiveShardCount; import org.elasticsearch.client.Requests; @@ -31,7 +30,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; -import java.util.List; import java.util.Map; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; @@ -47,14 +45,11 @@ public final class ClusterAllocationExplainIT extends ESIntegTestCase { @TestLogging("_root:DEBUG") public void testDelayShards() throws Exception { logger.info("--> starting 3 nodes"); - List nodes = internalCluster().startNodesAsync(3).get(); + internalCluster().startNodesAsync(3).get(); // Wait for all 3 nodes to be up logger.info("--> waiting for 3 nodes to be up"); - assertBusy(() -> { - NodesStatsResponse resp = client().admin().cluster().prepareNodesStats().get(); - assertThat(resp.getNodes().size(), equalTo(3)); - }); + ensureStableCluster(3); logger.info("--> creating 'test' index"); assertAcked(prepareCreate("test").setSettings(Settings.builder() @@ -66,7 +61,8 @@ public final class ClusterAllocationExplainIT extends ESIntegTestCase { logger.info("--> stopping a random node"); assertTrue(internalCluster().stopRandomDataNode()); - ensureYellow("test"); + logger.info("--> waiting for the master to remove the stopped node from the cluster state"); + ensureStableCluster(2); ClusterAllocationExplainResponse resp = client().admin().cluster().prepareAllocationExplain().useAnyUnassignedShard().get(); ClusterAllocationExplanation cae = resp.getExplanation();