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
This commit is contained in:
parent
5a7c8bb04e
commit
a4fae1540e
|
@ -18,12 +18,9 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.cluster.routing.allocation;
|
package org.elasticsearch.cluster.routing.allocation;
|
||||||
|
|
||||||
import org.elasticsearch.action.index.IndexRequest;
|
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
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.IndexService;
|
||||||
import org.elasticsearch.index.shard.IndexShard;
|
import org.elasticsearch.index.shard.IndexShard;
|
||||||
import org.elasticsearch.indices.IndicesService;
|
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);
|
indicesService.indexService(resolveIndex("test")).getShard(shard).failShard("simulated test failure", null);
|
||||||
|
|
||||||
logger.info("--> waiting for a yellow index");
|
logger.info("--> waiting for a yellow index");
|
||||||
ensureYellow();
|
// we can't use ensureYellow since that one is just as happy with a GREEN status.
|
||||||
|
assertBusy(() ->
|
||||||
// this forces the primary term to propagate to the replicas
|
assertThat(client().admin().cluster().prepareHealth("test").get().getStatus(), equalTo(ClusterHealthStatus.YELLOW)));
|
||||||
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final long term0 = shard == 0 ? 2 : 1;
|
final long term0 = shard == 0 ? 2 : 1;
|
||||||
final long term1 = shard == 1 ? 2 : 1;
|
final long term1 = shard == 1 ? 2 : 1;
|
||||||
|
|
Loading…
Reference in New Issue