From 97107e99e8e30c0ba14e6903b5da5c3630a44e32 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Sun, 16 Dec 2018 13:57:51 +0100 Subject: [PATCH] Moved test to its rightful place. --- .../xpack/ccr/LocalIndexFollowingIT.java | 40 ++--------------- .../xpack/ccr/action/FollowStatsIT.java | 43 ++++++++++++++++++- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java index bbdf1a06354..f8de29c616b 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/LocalIndexFollowingIT.java @@ -11,13 +11,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.xpack.CcrSingleNodeTestCase; -import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; import org.elasticsearch.xpack.core.ccr.action.PauseFollowAction; import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; import org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction; import java.io.IOException; -import java.util.Comparator; import java.util.Map; import static java.util.Collections.singletonMap; @@ -71,39 +69,6 @@ public class LocalIndexFollowingIT extends CcrSingleNodeTestCase { ensureEmptyWriteBuffers(); } - public void testFollowStatsApiFollowerIndexFiltering() throws Exception { - final String leaderIndexSettings = getIndexSettings(1, 0, - singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); - assertAcked(client().admin().indices().prepareCreate("leader1").setSource(leaderIndexSettings, XContentType.JSON)); - ensureGreen("leader1"); - assertAcked(client().admin().indices().prepareCreate("leader2").setSource(leaderIndexSettings, XContentType.JSON)); - ensureGreen("leader2"); - - PutFollowAction.Request followRequest = getPutFollowRequest("leader1", "follower1"); - client().execute(PutFollowAction.INSTANCE, followRequest).get(); - - followRequest = getPutFollowRequest("leader2", "follower2"); - client().execute(PutFollowAction.INSTANCE, followRequest).get(); - - FollowStatsAction.StatsRequest statsRequest = new FollowStatsAction.StatsRequest(); - statsRequest.setIndices(new String[] {"follower1"}); - FollowStatsAction.StatsResponses response = client().execute(FollowStatsAction.INSTANCE, statsRequest).actionGet(); - assertThat(response.getStatsResponses().size(), equalTo(1)); - assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower1")); - - statsRequest = new FollowStatsAction.StatsRequest(); - statsRequest.setIndices(new String[] {"follower2"}); - response = client().execute(FollowStatsAction.INSTANCE, statsRequest).actionGet(); - assertThat(response.getStatsResponses().size(), equalTo(1)); - assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower2")); - - response = client().execute(FollowStatsAction.INSTANCE, new FollowStatsAction.StatsRequest()).actionGet(); - assertThat(response.getStatsResponses().size(), equalTo(2)); - response.getStatsResponses().sort(Comparator.comparing(o -> o.status().followerIndex())); - assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower1")); - assertThat(response.getStatsResponses().get(1).status().followerIndex(), equalTo("follower2")); - } - public void testDoNotCreateFollowerIfLeaderDoesNotHaveSoftDeletes() throws Exception { final String leaderIndexSettings = getIndexSettings(2, 0, singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "false")); @@ -119,8 +84,9 @@ public class LocalIndexFollowingIT extends CcrSingleNodeTestCase { assertThat(client().admin().indices().prepareExists("follower-index").get().isExists(), equalTo(false)); } - private String getIndexSettings(final int numberOfShards, final int numberOfReplicas, - final Map additionalIndexSettings) throws IOException { + public static String getIndexSettings(final int numberOfShards, + final int numberOfReplicas, + final Map additionalIndexSettings) throws IOException { final String settings; try (XContentBuilder builder = jsonBuilder()) { builder.startObject(); diff --git a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowStatsIT.java b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowStatsIT.java index 1c9521d99d4..bd650d9677a 100644 --- a/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowStatsIT.java +++ b/x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/action/FollowStatsIT.java @@ -9,21 +9,27 @@ package org.elasticsearch.xpack.ccr.action; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest; import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.IndexSettings; import org.elasticsearch.persistent.PersistentTasksCustomMetaData; -import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.xpack.CcrSingleNodeTestCase; import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; +import org.elasticsearch.xpack.core.ccr.action.PutFollowAction; +import java.util.Comparator; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; +import static java.util.Collections.singletonMap; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.elasticsearch.xpack.ccr.LocalIndexFollowingIT.getIndexSettings; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.collection.IsEmptyCollection.empty; /* * Test scope is important to ensure that other tests added to this suite do not interfere with the expectation in * testStatsWhenNoPersistentTasksMetaDataExists that the cluster state does not contain any persistent tasks metadata. */ -@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST) public class FollowStatsIT extends CcrSingleNodeTestCase { /** @@ -65,4 +71,37 @@ public class FollowStatsIT extends CcrSingleNodeTestCase { assertTrue(onResponse.get()); } + public void testFollowStatsApiFollowerIndexFiltering() throws Exception { + final String leaderIndexSettings = getIndexSettings(1, 0, + singletonMap(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), "true")); + assertAcked(client().admin().indices().prepareCreate("leader1").setSource(leaderIndexSettings, XContentType.JSON)); + ensureGreen("leader1"); + assertAcked(client().admin().indices().prepareCreate("leader2").setSource(leaderIndexSettings, XContentType.JSON)); + ensureGreen("leader2"); + + PutFollowAction.Request followRequest = getPutFollowRequest("leader1", "follower1"); + client().execute(PutFollowAction.INSTANCE, followRequest).get(); + + followRequest = getPutFollowRequest("leader2", "follower2"); + client().execute(PutFollowAction.INSTANCE, followRequest).get(); + + FollowStatsAction.StatsRequest statsRequest = new FollowStatsAction.StatsRequest(); + statsRequest.setIndices(new String[] {"follower1"}); + FollowStatsAction.StatsResponses response = client().execute(FollowStatsAction.INSTANCE, statsRequest).actionGet(); + assertThat(response.getStatsResponses().size(), equalTo(1)); + assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower1")); + + statsRequest = new FollowStatsAction.StatsRequest(); + statsRequest.setIndices(new String[] {"follower2"}); + response = client().execute(FollowStatsAction.INSTANCE, statsRequest).actionGet(); + assertThat(response.getStatsResponses().size(), equalTo(1)); + assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower2")); + + response = client().execute(FollowStatsAction.INSTANCE, new FollowStatsAction.StatsRequest()).actionGet(); + assertThat(response.getStatsResponses().size(), equalTo(2)); + response.getStatsResponses().sort(Comparator.comparing(o -> o.status().followerIndex())); + assertThat(response.getStatsResponses().get(0).status().followerIndex(), equalTo("follower1")); + assertThat(response.getStatsResponses().get(1).status().followerIndex(), equalTo("follower2")); + } + }