diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index 6d999a5b2cf..5200259b501 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -969,14 +969,18 @@ public abstract class ESRestTestCase extends ESTestCase { } protected static void ensureHealth(String index, Consumer requestConsumer) throws IOException { + ensureHealth(client(), index, requestConsumer); + } + + protected static void ensureHealth(RestClient client, String index, Consumer requestConsumer) throws IOException { Request request = new Request("GET", "/_cluster/health" + (index.trim().isEmpty() ? "" : "/" + index)); requestConsumer.accept(request); try { - client().performRequest(request); + client.performRequest(request); } catch (ResponseException e) { if (e.getResponse().getStatusLine().getStatusCode() == HttpStatus.SC_REQUEST_TIMEOUT) { try { - final Response clusterStateResponse = client().performRequest(new Request("GET", "/_cluster/state?pretty")); + final Response clusterStateResponse = client.performRequest(new Request("GET", "/_cluster/state?pretty")); fail("timed out waiting for green state for index [" + index + "] " + "cluster state [" + EntityUtils.toString(clusterStateResponse.getEntity()) + "]"); } catch (Exception inner) { diff --git a/x-pack/plugin/ccr/qa/downgrade-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java b/x-pack/plugin/ccr/qa/downgrade-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java index cc8d399776e..9767a92c266 100644 --- a/x-pack/plugin/ccr/qa/downgrade-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java +++ b/x-pack/plugin/ccr/qa/downgrade-to-basic-license/src/test/java/org/elasticsearch/xpack/ccr/FollowIndexIT.java @@ -19,6 +19,7 @@ import org.hamcrest.Matchers; import java.io.IOException; import java.nio.file.Path; import java.util.Map; +import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import static org.elasticsearch.common.xcontent.ObjectPath.eval; @@ -48,7 +49,7 @@ public class FollowIndexIT extends ESCCRRestTestCase { assertBusy(() -> { ensureYellow(index1); verifyDocuments(index1, 5, "filtered_field:true"); - }); + }, 60, TimeUnit.SECONDS); String index2 = "logs-20190102"; try (RestClient leaderClient = buildLeaderClient()) { @@ -88,7 +89,7 @@ public class FollowIndexIT extends ESCCRRestTestCase { } }); } - }); + }, 60, TimeUnit.SECONDS); // Manually following index2 also does not work after the downgrade: Exception e = expectThrows(ResponseException.class, () -> followIndex("leader_cluster", index2)); diff --git a/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java b/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java index b555e5f4411..ed6612b18ce 100644 --- a/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java +++ b/x-pack/plugin/ccr/qa/src/main/java/org/elasticsearch/xpack/ccr/ESCCRRestTestCase.java @@ -215,14 +215,15 @@ public class ESCCRRestTestCase extends ESRestTestCase { } protected static void ensureYellow(final String index, final RestClient client) throws IOException { - final Request request = new Request("GET", "/_cluster/health/" + index); - request.addParameter("wait_for_status", "yellow"); - request.addParameter("wait_for_active_shards", "1"); - request.addParameter("wait_for_no_relocating_shards", "true"); - request.addParameter("wait_for_no_initializing_shards", "true"); - request.addParameter("timeout", "5s"); - request.addParameter("level", "shards"); - client.performRequest(request); + ensureHealth(client, index, request -> { + request.addParameter("wait_for_status", "yellow"); + request.addParameter("wait_for_active_shards", "1"); + request.addParameter("wait_for_no_relocating_shards", "true"); + // follower index can be yellow even when its primary shards are still initializing as we bootstrap them using snapshot/restore. + request.addParameter("wait_for_no_initializing_shards", "true"); + request.addParameter("timeout", "5s"); + request.addParameter("level", "shards"); + }); } protected int countCcrNodeTasks() throws IOException {