From 8925a2c6c2bf998b492e74bee5a8afd326fe8411 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 11 Mar 2019 09:46:42 +0100 Subject: [PATCH] Further tweak AutoFollowIT#testAutoFollowManyIndices: * reduce the number of leader indices to be auto followed * also check the number of follower indices being created * also check the whether leader indices are marked as auto followed Relates to #36761 --- .../elasticsearch/xpack/ccr/AutoFollowIT.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java index 485352d8492..4fdb1fa00ab 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/AutoFollowIT.java @@ -35,7 +35,9 @@ import java.util.List; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; public class AutoFollowIT extends CcrIntegTestCase { @@ -131,7 +133,7 @@ public class AutoFollowIT extends CcrIntegTestCase { .build(); putAutoFollowPatterns("my-pattern", new String[] {"logs-*"}); - long numIndices = randomIntBetween(4, 16); + long numIndices = randomIntBetween(4, 8); for (int i = 0; i < numIndices; i++) { createLeaderIndex("logs-" + i, leaderIndexSettings); } @@ -140,8 +142,12 @@ public class AutoFollowIT extends CcrIntegTestCase { AutoFollowStats[] autoFollowStats = new AutoFollowStats[1]; try { assertBusy(() -> { - metaData[0] = followerClient().admin().cluster().prepareState().get().getState().metaData(); + metaData[0] = getFollowerCluster().clusterService().state().metaData(); autoFollowStats[0] = getAutoFollowStats(); + + assertThat(metaData[0].indices().size(), equalTo((int) expectedVal1)); + AutoFollowMetadata autoFollowMetadata = metaData[0].custom(AutoFollowMetadata.TYPE); + assertThat(autoFollowMetadata.getFollowedLeaderIndexUUIDs().get("my-pattern"), hasSize((int) expectedVal1)); assertThat(autoFollowStats[0].getNumberOfSuccessfulFollowIndices(), equalTo(expectedVal1)); }); } catch (AssertionError ae) { @@ -155,8 +161,12 @@ public class AutoFollowIT extends CcrIntegTestCase { deleteAutoFollowPatternSetting(); try { assertBusy(() -> { - metaData[0] = followerClient().admin().cluster().prepareState().get().getState().metaData(); + metaData[0] = getFollowerCluster().clusterService().state().metaData(); autoFollowStats[0] = getAutoFollowStats(); + + assertThat(metaData[0].indices().size(), equalTo((int )expectedVal1)); + AutoFollowMetadata autoFollowMetadata = metaData[0].custom(AutoFollowMetadata.TYPE); + assertThat(autoFollowMetadata.getFollowedLeaderIndexUUIDs().get("my-pattern"), nullValue()); assertThat(autoFollowStats[0].getAutoFollowedClusters().size(), equalTo(0)); }); } catch (AssertionError ae) { @@ -176,8 +186,14 @@ public class AutoFollowIT extends CcrIntegTestCase { try { assertBusy(() -> { - metaData[0] = followerClient().admin().cluster().prepareState().get().getState().metaData(); + metaData[0] = getFollowerCluster().clusterService().state().metaData(); autoFollowStats[0] = getAutoFollowStats(); + + assertThat(metaData[0].indices().size(), equalTo((int) expectedVal2)); + AutoFollowMetadata autoFollowMetadata = metaData[0].custom(AutoFollowMetadata.TYPE); + // expectedVal2 + 1, because logs-does-not-count is also marked as auto followed. + // (This is because indices created before a pattern exists are not auto followed and are just marked as such.) + assertThat(autoFollowMetadata.getFollowedLeaderIndexUUIDs().get("my-pattern"), hasSize((int) expectedVal2 + 1)); long count = Arrays.stream(metaData[0].getConcreteAllIndices()).filter(s -> s.startsWith("copy-")).count(); assertThat(count, equalTo(expectedVal2)); // Ensure that there are no auto follow errors: