From a4fae1540ea14331467199309d4eb7551a91f700 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Sun, 2 Jul 2017 21:19:51 +0200 Subject: [PATCH] testPrimaryFailureIncreasesTerm should use assertBusy to wait for yellow ensureYellow ensures at least yellow. Also, since we only have 1 replica, we don't need to index for it to know about the primary term promotion Closes #25287 --- .../routing/allocation/ShardStateIT.java | 23 +++---------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java index 01c335e6ec4..de82e72f9dc 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ShardStateIT.java @@ -18,12 +18,9 @@ */ package org.elasticsearch.cluster.routing.allocation; -import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.health.ClusterHealthStatus; import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.routing.Murmur3HashFunction; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexService; import org.elasticsearch.index.shard.IndexShard; import org.elasticsearch.indices.IndicesService; @@ -51,23 +48,9 @@ public class ShardStateIT extends ESIntegTestCase { indicesService.indexService(resolveIndex("test")).getShard(shard).failShard("simulated test failure", null); logger.info("--> waiting for a yellow index"); - ensureYellow(); - - // this forces the primary term to propagate to the replicas - int id = 0; - while (true) { - // find an ID that routes to the right shard, we will only index to the shard that saw a primary failure - final String idAsString = Integer.toString(id); - final int hash = Math.floorMod(Murmur3HashFunction.hash(idAsString), 2); - if (hash == shard) { - client() - .index(new IndexRequest("test", "type", idAsString).source("{ \"f\": \"" + idAsString + "\"}", XContentType.JSON)) - .get(); - break; - } else { - id++; - } - } + // we can't use ensureYellow since that one is just as happy with a GREEN status. + assertBusy(() -> + assertThat(client().admin().cluster().prepareHealth("test").get().getStatus(), equalTo(ClusterHealthStatus.YELLOW))); final long term0 = shard == 0 ? 2 : 1; final long term1 = shard == 1 ? 2 : 1;