Fix AwarenessAllocationIT.testAwarenessZones test
This test sometimes fails because the first node is elected as master and waits 30s for incoming joins but in the meanwhile the 3 other nodes form a cluster on their side. The index will be created and its shards allocated on these 3 nodes, then the test checks for the number of shards on each node (it should be 2 or 3) but because the first node has not fully join the cluster yet one node will have 5 shards. closes #13305
This commit is contained in:
parent
b4adad7c0a
commit
561f5b590f
|
@ -25,10 +25,12 @@ import org.elasticsearch.cluster.ClusterState;
|
|||
import org.elasticsearch.cluster.routing.IndexRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
||||
import org.elasticsearch.cluster.routing.ShardRouting;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.discovery.zen.ZenDiscovery;
|
||||
import org.elasticsearch.discovery.zen.elect.ElectMasterService;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||
|
@ -106,26 +108,36 @@ public class AwarenessAllocationIT extends ESIntegTestCase {
|
|||
@Test
|
||||
public void testAwarenessZones() throws Exception {
|
||||
Settings commonSettings = Settings.settingsBuilder()
|
||||
.put("cluster.routing.allocation.awareness.force.zone.values", "a,b")
|
||||
.put("cluster.routing.allocation.awareness.attributes", "zone")
|
||||
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP + "zone.values", "a,b")
|
||||
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTES, "zone")
|
||||
.put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, 3)
|
||||
.put(ZenDiscovery.SETTING_JOIN_TIMEOUT, "10s")
|
||||
.build();
|
||||
|
||||
logger.info("--> starting 4 nodes on different zones");
|
||||
List<String> nodes = internalCluster().startNodesAsync(
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "a").put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, 3).build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "b").put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, 3).build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "b").put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, 3).build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "a").put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES, 3).build()
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "a").build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "b").build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "b").build(),
|
||||
Settings.settingsBuilder().put(commonSettings).put("node.zone", "a").build()
|
||||
).get();
|
||||
String A_0 = nodes.get(0);
|
||||
String B_0 = nodes.get(1);
|
||||
String B_1 = nodes.get(2);
|
||||
String A_1 = nodes.get(3);
|
||||
|
||||
logger.info("--> waiting for nodes to form a cluster");
|
||||
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("4").execute().actionGet();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
|
||||
client().admin().indices().prepareCreate("test")
|
||||
.setSettings(settingsBuilder().put("index.number_of_shards", 5)
|
||||
.put("index.number_of_replicas", 1)).execute().actionGet();
|
||||
ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("4").setWaitForRelocatingShards(0).execute().actionGet();
|
||||
|
||||
logger.info("--> waiting for shards to be allocated");
|
||||
health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForRelocatingShards(0).execute().actionGet();
|
||||
assertThat(health.isTimedOut(), equalTo(false));
|
||||
|
||||
ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
|
||||
ObjectIntHashMap<String> counts = new ObjectIntHashMap<>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue