Skip to content

Commit

Permalink
Wait for index following is active for auto followed index (#39175)
Browse files Browse the repository at this point in the history
before executing pause follow api:

#39126 (comment)

Closes #39126
  • Loading branch information
martijnvg committed Feb 25, 2019
1 parent a2bc416 commit 9bf0538
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.elasticsearch.client.RestClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ObjectPath;

import java.io.IOException;
import java.util.Map;
Expand All @@ -19,7 +20,6 @@

public class XPackUsageIT extends ESCCRRestTestCase {

@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39126")
public void testXPackCcrUsage() throws Exception {
if ("follow".equals(targetCluster) == false) {
logger.info("skipping test, waiting for target cluster [follow]" );
Expand All @@ -42,6 +42,9 @@ public void testXPackCcrUsage() throws Exception {
assertThat(ccrUsage.get("follower_indices_count"), equalTo(previousFollowerIndicesCount + 2));
assertThat(ccrUsage.get("auto_follow_patterns_count"), equalTo(previousAutoFollowPatternsCount + 1));
assertThat((Integer) ccrUsage.get("last_follow_time_in_millis"), greaterThanOrEqualTo(0));
// We need to wait until index following is active for auto followed indices:
// (otherwise pause follow may fail, if there are no shard follow tasks, in case this test gets executed too quickly)
assertIndexFollowingActive("messages-20200101");
});

deleteAutoFollowPattern("my_pattern");
Expand Down Expand Up @@ -83,4 +86,13 @@ private void createLeaderIndex(String indexName) throws IOException {
return (Map<?, ?>) response.get("ccr");
}

private void assertIndexFollowingActive(String expectedFollowerIndex) throws IOException {
Request statsRequest = new Request("GET", "/" + expectedFollowerIndex + "/_ccr/info");
Map<?, ?> response = toMap(client().performRequest(statsRequest));
String actualFollowerIndex = ObjectPath.eval("follower_indices.0.follower_index", response);
assertThat(actualFollowerIndex, equalTo(expectedFollowerIndex));
String followStatus = ObjectPath.eval("follower_indices.0.status", response);
assertThat(followStatus, equalTo("active"));
}

}

0 comments on commit 9bf0538

Please sign in to comment.