|
18 | 18 | import org.elasticsearch.action.search.ShardSearchFailure; |
19 | 19 | import org.elasticsearch.action.search.TransportSearchAction; |
20 | 20 | import org.elasticsearch.action.support.PlainActionFuture; |
21 | | -import org.elasticsearch.client.internal.Client; |
22 | | -import org.elasticsearch.common.Strings; |
23 | | -import org.elasticsearch.common.settings.Setting; |
24 | | -import org.elasticsearch.common.settings.Settings; |
25 | 21 | import org.elasticsearch.common.util.CollectionUtils; |
26 | 22 | import org.elasticsearch.core.TimeValue; |
27 | 23 | import org.elasticsearch.index.query.MatchAllQueryBuilder; |
|
31 | 27 | import org.elasticsearch.search.builder.SearchSourceBuilder; |
32 | 28 | import org.elasticsearch.search.query.SlowRunningQueryBuilder; |
33 | 29 | import org.elasticsearch.search.query.ThrowingQueryBuilder; |
34 | | -import org.elasticsearch.test.AbstractMultiClustersTestCase; |
35 | | -import org.elasticsearch.test.InternalTestCluster; |
36 | 30 | import org.elasticsearch.transport.RemoteClusterAware; |
37 | 31 | import org.elasticsearch.transport.RemoteTransportException; |
38 | 32 |
|
39 | 33 | import java.util.Collection; |
40 | | -import java.util.HashMap; |
41 | 34 | import java.util.List; |
42 | 35 | import java.util.Map; |
43 | 36 | import java.util.Objects; |
44 | 37 | import java.util.concurrent.ExecutionException; |
45 | 38 | import java.util.concurrent.TimeUnit; |
46 | 39 |
|
47 | | -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; |
48 | 40 | import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertResponse; |
49 | 41 | import static org.hamcrest.Matchers.anyOf; |
50 | 42 | import static org.hamcrest.Matchers.containsString; |
|
53 | 45 | import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
54 | 46 | import static org.hamcrest.Matchers.instanceOf; |
55 | 47 |
|
56 | | -public class CrossClusterSearchIT extends AbstractMultiClustersTestCase { |
57 | | - |
58 | | - private static final String REMOTE_CLUSTER = "cluster_a"; |
59 | | - private static long EARLIEST_TIMESTAMP = 1691348810000L; |
60 | | - private static long LATEST_TIMESTAMP = 1691348820000L; |
61 | | - |
62 | | - @Override |
63 | | - protected List<String> remoteClusterAlias() { |
64 | | - return List.of(REMOTE_CLUSTER); |
65 | | - } |
| 48 | +public class CrossClusterSearchIT extends AbstractCrossClusterSearchTestCase { |
66 | 49 |
|
67 | 50 | @Override |
68 | | - protected Map<String, Boolean> skipUnavailableForRemoteClusters() { |
69 | | - return Map.of(REMOTE_CLUSTER, randomBoolean()); |
| 51 | + protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { |
| 52 | + return CollectionUtils.appendToCopy(super.nodePlugins(clusterAlias), TestQueryBuilderPlugin.class); |
70 | 53 | } |
71 | 54 |
|
72 | 55 | @Override |
73 | 56 | protected boolean reuseClusters() { |
74 | 57 | return false; |
75 | 58 | } |
76 | 59 |
|
77 | | - @Override |
78 | | - protected Collection<Class<? extends Plugin>> nodePlugins(String clusterAlias) { |
79 | | - return CollectionUtils.appendToCopy(super.nodePlugins(clusterAlias), CrossClusterSearchIT.TestQueryBuilderPlugin.class); |
80 | | - } |
81 | | - |
82 | 60 | public static class TestQueryBuilderPlugin extends Plugin implements SearchPlugin { |
83 | 61 | public TestQueryBuilderPlugin() {} |
84 | 62 |
|
@@ -827,73 +805,4 @@ private static void assertOneFailedShard(Cluster cluster, int totalShards) { |
827 | 805 | assertThat(remoteShardSearchFailure.reason(), containsString("index corrupted")); |
828 | 806 | } |
829 | 807 |
|
830 | | - private Map<String, Object> setupTwoClusters(String[] localIndices, String[] remoteIndices) { |
831 | | - int numShardsLocal = randomIntBetween(2, 10); |
832 | | - Settings localSettings = indexSettings(numShardsLocal, randomIntBetween(0, 1)).build(); |
833 | | - for (String localIndex : localIndices) { |
834 | | - assertAcked( |
835 | | - client(LOCAL_CLUSTER).admin() |
836 | | - .indices() |
837 | | - .prepareCreate(localIndex) |
838 | | - .setSettings(localSettings) |
839 | | - .setMapping("@timestamp", "type=date", "f", "type=text") |
840 | | - ); |
841 | | - indexDocs(client(LOCAL_CLUSTER), localIndex); |
842 | | - } |
843 | | - |
844 | | - int numShardsRemote = randomIntBetween(2, 10); |
845 | | - final InternalTestCluster remoteCluster = cluster(REMOTE_CLUSTER); |
846 | | - remoteCluster.ensureAtLeastNumDataNodes(randomIntBetween(1, 3)); |
847 | | - for (String remoteIndex : remoteIndices) { |
848 | | - assertAcked( |
849 | | - client(REMOTE_CLUSTER).admin() |
850 | | - .indices() |
851 | | - .prepareCreate(remoteIndex) |
852 | | - .setSettings(indexSettings(numShardsRemote, randomIntBetween(0, 1))) |
853 | | - .setMapping("@timestamp", "type=date", "f", "type=text") |
854 | | - ); |
855 | | - assertFalse( |
856 | | - client(REMOTE_CLUSTER).admin() |
857 | | - .cluster() |
858 | | - .prepareHealth(TEST_REQUEST_TIMEOUT, remoteIndex) |
859 | | - .setWaitForYellowStatus() |
860 | | - .setTimeout(TimeValue.timeValueSeconds(10)) |
861 | | - .get() |
862 | | - .isTimedOut() |
863 | | - ); |
864 | | - indexDocs(client(REMOTE_CLUSTER), remoteIndex); |
865 | | - } |
866 | | - |
867 | | - String skipUnavailableKey = Strings.format("cluster.remote.%s.skip_unavailable", REMOTE_CLUSTER); |
868 | | - Setting<?> skipUnavailableSetting = cluster(REMOTE_CLUSTER).clusterService().getClusterSettings().get(skipUnavailableKey); |
869 | | - boolean skipUnavailable = (boolean) cluster(RemoteClusterAware.LOCAL_CLUSTER_GROUP_KEY).clusterService() |
870 | | - .getClusterSettings() |
871 | | - .get(skipUnavailableSetting); |
872 | | - |
873 | | - Map<String, Object> clusterInfo = new HashMap<>(); |
874 | | - clusterInfo.put("local.num_shards", numShardsLocal); |
875 | | - clusterInfo.put("remote.num_shards", numShardsRemote); |
876 | | - clusterInfo.put("remote.skip_unavailable", skipUnavailable); |
877 | | - return clusterInfo; |
878 | | - } |
879 | | - |
880 | | - private Map<String, Object> setupTwoClusters() { |
881 | | - var clusterInfo = setupTwoClusters(new String[] { "demo" }, new String[] { "prod" }); |
882 | | - clusterInfo.put("local.index", "demo"); |
883 | | - clusterInfo.put("remote.index", "prod"); |
884 | | - return clusterInfo; |
885 | | - } |
886 | | - |
887 | | - private int indexDocs(Client client, String index) { |
888 | | - int numDocs = between(500, 1200); |
889 | | - for (int i = 0; i < numDocs; i++) { |
890 | | - long ts = EARLIEST_TIMESTAMP + i; |
891 | | - if (i == numDocs - 1) { |
892 | | - ts = LATEST_TIMESTAMP; |
893 | | - } |
894 | | - client.prepareIndex(index).setSource("f", "v", "@timestamp", ts).get(); |
895 | | - } |
896 | | - client.admin().indices().prepareRefresh(index).get(); |
897 | | - return numDocs; |
898 | | - } |
899 | 808 | } |
0 commit comments