Skip to content

Commit ef1c742

Browse files
authored
Convert ccs-common-rest QA project to new test clusters framework (#92516) (#92531)
1 parent 3e8d5c6 commit ef1c742

File tree

8 files changed

+121
-64
lines changed

8 files changed

+121
-64
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
import org.gradle.api.tasks.PathSensitivity;
4141
import org.gradle.api.tasks.util.PatternFilterable;
4242

43+
import java.util.Collection;
44+
import java.util.HashSet;
4345
import java.util.List;
4446
import java.util.Map;
4547
import java.util.Optional;
@@ -199,6 +201,7 @@ private Configuration createPluginConfiguration(Project project, String name, bo
199201
}
200202
c.withDependencies(dependencies -> {
201203
// Add dependencies of any modules
204+
Collection<Dependency> additionalDependencies = new HashSet<>();
202205
for (Dependency dependency : dependencies) {
203206
if (dependency instanceof ProjectDependency projectDependency) {
204207
List<String> extendedPlugins = projectDependency.getDependencyProject()
@@ -208,11 +211,13 @@ private Configuration createPluginConfiguration(Project project, String name, bo
208211

209212
for (String extendedPlugin : extendedPlugins) {
210213
findModulePath(project, extendedPlugin).ifPresent(
211-
modulePath -> dependencies.add(project.getDependencies().project(Map.of("path", modulePath)))
214+
modulePath -> additionalDependencies.add(project.getDependencies().project(Map.of("path", modulePath)))
212215
);
213216
}
214217
}
215218
}
219+
220+
dependencies.addAll(additionalDependencies);
216221
});
217222
});
218223
}

qa/ccs-common-rest/build.gradle

Lines changed: 6 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
/*
2-
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3-
* or more contributor license agreements. Licensed under the Elastic License
4-
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5-
* in compliance with, at your election, the Elastic License 2.0 or the Server
6-
* Side Public License, v 1.
7-
*/
8-
9-
10-
import org.elasticsearch.gradle.Version
11-
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
12-
import org.elasticsearch.gradle.testclusters.DefaultTestClustersTask
13-
14-
15-
apply plugin: 'elasticsearch.internal-testclusters'
16-
apply plugin: 'elasticsearch.standalone-rest-test'
17-
apply plugin: 'elasticsearch.rest-resources'
1+
apply plugin: 'elasticsearch.internal-yaml-rest-test'
182

193
// This subproject copies a subset of the rest-api-spec rest tests and runs them in a slightly
204
// modified way on two clusters connected via CCS. All operations except searches and a few other
@@ -35,42 +19,13 @@ restResources {
3519
}
3620
}
3721

38-
def remoteCluster = testClusters.register("ccs-remote") {
39-
numberOfNodes = 2
40-
setting 'node.roles', '[data,ingest,master]'
41-
}
42-
43-
def localCluster = testClusters.register("ccs-local") {
44-
setting 'node.roles', '[data,ingest,master,remote_cluster_client]'
45-
setting 'cluster.remote.connections_per_cluster', '1'
46-
setting 'cluster.remote.remote_cluster.seeds',
47-
{ "\"${remoteCluster.get().getAllTransportPortURI().get(0)}\"" }
48-
}
49-
50-
testClusters.configureEach {
51-
setting 'xpack.security.enabled', 'false'
52-
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
22+
dependencies {
23+
clusterModules project(':x-pack:plugin:async-search')
24+
clusterModules project(':modules:mapper-extras')
25+
clusterModules project(':modules:aggregations')
5326
}
5427

55-
// the following task is needed to make sure the remote cluster is running before the local cluster
56-
// gets configured with the remotes cluster seed
57-
tasks.register('startRemoteCluster', DefaultTestClustersTask) {
58-
useCluster remoteCluster
59-
doLast {
60-
clusters.each { c ->
61-
print "Remote cluster transport uri for ccs configuration is: "
62-
println c.getAllTransportPortURI().get(0)
63-
}
64-
}
65-
}
66-
67-
tasks.register("ccs-remote", RestIntegTestTask) {
68-
mustRunAfter("precommit")
69-
dependsOn startRemoteCluster
70-
71-
useCluster remoteCluster
72-
useCluster localCluster
73-
28+
tasks.named("yamlRestTest") {
7429
systemProperty 'tests.rest.blacklist',
7530
[
7631
'search/150_rewrite_on_coordinator/Ensure that we fetch the document only once', // terms lookup query with index
@@ -86,13 +41,5 @@ tasks.register("ccs-remote", RestIntegTestTask) {
8641
'search.aggregation/70_adjacency_matrix/Terms lookup', // terms lookup by "index" doesn't seem to work correctly
8742
'async_search/20-with-poin-in-time/Async search with point in time' // [indices] cannot be used with point in time
8843
].join(',')
89-
90-
91-
doFirst {
92-
println "Remote cluster endpoints are: ${-> remoteCluster.get().allHttpSocketURI.join(",")}"
93-
println "Local cluster endpoints are: ${-> localCluster.get().allHttpSocketURI.join(",")}"
94-
nonInputProperties.systemProperty('tests.rest.cluster', remoteCluster.map(c -> c.allHttpSocketURI.join(",")))
95-
nonInputProperties.systemProperty('tests.rest.search_cluster', localCluster.map(c -> c.allHttpSocketURI.join(",")))
96-
}
9744
}
9845

qa/ccs-common-rest/src/test/java/org/elasticsearch/test/rest/yaml/CcsCommonYamlTestSuiteIT.java renamed to qa/ccs-common-rest/src/yamlRestTest/java/org/elasticsearch/test/rest/yaml/CcsCommonYamlTestSuiteIT.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
import org.elasticsearch.client.RestClient;
2424
import org.elasticsearch.core.IOUtils;
2525
import org.elasticsearch.core.Tuple;
26+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
27+
import org.elasticsearch.test.cluster.FeatureFlag;
28+
import org.elasticsearch.test.cluster.local.LocalClusterConfigProvider;
2629
import org.elasticsearch.test.rest.ObjectPath;
2730
import org.elasticsearch.test.rest.yaml.section.ClientYamlTestSection;
2831
import org.elasticsearch.test.rest.yaml.section.DoSection;
@@ -32,6 +35,9 @@
3235
import org.elasticsearch.test.rest.yaml.section.MatchAssertion;
3336
import org.junit.AfterClass;
3437
import org.junit.Before;
38+
import org.junit.ClassRule;
39+
import org.junit.rules.RuleChain;
40+
import org.junit.rules.TestRule;
3541

3642
import java.io.IOException;
3743
import java.util.ArrayList;
@@ -58,9 +64,34 @@ public class CcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
5864
private static RestClient adminSearchClient;
5965
private static List<HttpHost> clusterHosts;
6066
private static ClientYamlTestClient searchYamlTestClient;
61-
6267
// the remote cluster is the one we write index operations etc... to
6368
private static final String REMOTE_CLUSTER_NAME = "remote_cluster";
69+
70+
private static LocalClusterConfigProvider commonClusterConfig = cluster -> cluster.module("x-pack-async-search")
71+
.module("aggregations")
72+
.module("mapper-extras")
73+
.setting("xpack.security.enabled", "false")
74+
.feature(FeatureFlag.TIME_SERIES_MODE);
75+
76+
private static ElasticsearchCluster remoteCluster = ElasticsearchCluster.local()
77+
.name(REMOTE_CLUSTER_NAME)
78+
.nodes(2)
79+
.setting("node.roles", "[data,ingest,master]")
80+
.apply(commonClusterConfig)
81+
.build();
82+
83+
private static ElasticsearchCluster localCluster = ElasticsearchCluster.local()
84+
.name("local_cluster")
85+
.setting("node.roles", "[data,ingest,master,remote_cluster_client]")
86+
.setting("cluster.remote.remote_cluster.seeds", () -> "\"" + remoteCluster.getTransportEndpoint(0) + "\"")
87+
.setting("cluster.remote.connections_per_cluster", "1")
88+
.apply(commonClusterConfig)
89+
.build();
90+
91+
@ClassRule
92+
// Use a RuleChain to ensure that remote cluster is started before local cluster
93+
public static TestRule clusterRule = RuleChain.outerRule(remoteCluster).around(localCluster);
94+
6495
// the CCS api calls that we run against the "search" cluster in this test setup
6596
private static final Set<String> CCS_APIS = Set.of(
6697
"search",
@@ -75,6 +106,11 @@ public class CcsCommonYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
75106
"async_search.delete"
76107
);
77108

109+
@Override
110+
protected String getTestRestCluster() {
111+
return remoteCluster.getHttpAddresses();
112+
}
113+
78114
/**
79115
* initialize the search client and an additional administration client and check for an established connection
80116
*/
@@ -84,9 +120,7 @@ public void initSearchClient() throws IOException {
84120
assert adminSearchClient == null;
85121
assert clusterHosts == null;
86122

87-
final String cluster = System.getProperty("tests.rest.search_cluster");
88-
assertNotNull("[tests.rest.search_cluster] is not configured", cluster);
89-
String[] stringUrls = cluster.split(",");
123+
String[] stringUrls = localCluster.getHttpAddresses().split(",");
90124
List<HttpHost> hosts = new ArrayList<>(stringUrls.length);
91125
for (String stringUrl : stringUrls) {
92126
int portSeparator = stringUrl.lastIndexOf(':');

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/ClusterHandle.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,28 @@ public interface ClusterHandle extends Closeable {
4242
* @return cluster node HTTP transport addresses
4343
*/
4444
String getHttpAddresses();
45+
46+
/**
47+
* Returns the HTTP transport endpoint for the node at the given index. If this method is called on an unstarted cluster, the cluster
48+
* will be started. This method is thread-safe and subsequent calls will wait for cluster start and availability.
49+
*
50+
* @return cluster node HTTP transport addresses
51+
*/
52+
String getHttpAddress(int index);
53+
54+
/**
55+
* Returns a comma-separated list of TCP transport endpoints for cluster. If this method is called on an unstarted cluster, the cluster
56+
* will be started. This method is thread-safe and subsequent calls will wait for cluster start and availability.
57+
*
58+
* @return cluster node TCP transport endpoints
59+
*/
60+
String getTransportEndpoints();
61+
62+
/**
63+
* Returns the TCP transport endpoint for the node at the given index. If this method is called on an unstarted cluster, the cluster
64+
* will be started. This method is thread-safe and subsequent calls will wait for cluster start and availability.
65+
*
66+
* @return cluster node TCP transport endpoints
67+
*/
68+
String getTransportEndpoint(int index);
4569
}

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/AbstractLocalSpecBuilder.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ public T setting(String setting, String value) {
5252
return cast(this);
5353
}
5454

55+
@Override
56+
public T setting(String setting, Supplier<String> value) {
57+
this.settingsProviders.add(s -> Map.of(setting, value.get()));
58+
return cast(this);
59+
}
60+
5561
Map<String, String> getSettings() {
5662
return inherit(() -> parent.getSettings(), settings);
5763
}

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalClusterHandle.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ public String getHttpAddresses() {
103103
return execute(() -> nodes.parallelStream().map(Node::getHttpAddress).collect(Collectors.joining(",")));
104104
}
105105

106+
@Override
107+
public String getHttpAddress(int index) {
108+
return getHttpAddresses().split(",")[index];
109+
}
110+
111+
@Override
112+
public String getTransportEndpoints() {
113+
start();
114+
return execute(() -> nodes.parallelStream().map(Node::getTransportEndpoint).collect(Collectors.joining(",")));
115+
}
116+
117+
@Override
118+
public String getTransportEndpoint(int index) {
119+
return getTransportEndpoints().split(",")[index];
120+
}
121+
106122
private void waitUntilReady() {
107123
writeUnicastHostsFile();
108124
try {

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalElasticsearchCluster.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ public String getHttpAddresses() {
7373
return handle.getHttpAddresses();
7474
}
7575

76+
@Override
77+
public String getHttpAddress(int index) {
78+
checkHandle();
79+
return handle.getHttpAddress(index);
80+
}
81+
82+
@Override
83+
public String getTransportEndpoints() {
84+
checkHandle();
85+
return handle.getTransportEndpoints();
86+
}
87+
88+
@Override
89+
public String getTransportEndpoint(int index) {
90+
checkHandle();
91+
return handle.getTransportEndpoint(index);
92+
}
93+
7694
private void checkHandle() {
7795
if (handle == null) {
7896
throw new IllegalStateException("Cluster handle has not been initialized. Did you forget the @ClassRule annotation?");

test/test-clusters/src/main/java/org/elasticsearch/test/cluster/local/LocalSpecBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.elasticsearch.test.cluster.SettingsProvider;
1414
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
1515

16+
import java.util.function.Supplier;
17+
1618
interface LocalSpecBuilder<T extends LocalSpecBuilder<?>> {
1719
/**
1820
* Register a {@link SettingsProvider}.
@@ -24,6 +26,11 @@ interface LocalSpecBuilder<T extends LocalSpecBuilder<?>> {
2426
*/
2527
T setting(String setting, String value);
2628

29+
/**
30+
* Add a new node setting computed by the given supplier.
31+
*/
32+
T setting(String setting, Supplier<String> value);
33+
2734
/**
2835
* Register a {@link EnvironmentProvider}.
2936
*/

0 commit comments

Comments
 (0)