Skip to content

Commit 0642783

Browse files
moscheelasticsearchmachine
andauthored
[9.1] Migrate ILM REST tests to new test framework. (#136744) (#137090)
* Migrate ILM REST tests to new test framework. (#136744) I'll follow up consolidating the projects in another PR. This felt easier to review if migrating in place. Relates to ES-11813 (cherry picked from commit 440faee) # Conflicts: # x-pack/plugin/ilm/qa/multi-cluster/src/javaRestTest/java/org/elasticsearch/xpack/ilm/CCRIndexLifecycleIT.java # x-pack/plugin/ilm/qa/multi-node/build.gradle # x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent 5ac7210 commit 0642783

File tree

24 files changed

+239
-603
lines changed

24 files changed

+239
-603
lines changed

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/RestrictedBuildApiService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
6161
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:correctness");
6262
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:eql:qa:mixed-node");
6363
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:identity-provider:qa:idp-rest-tests");
64-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:multi-cluster");
65-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:multi-node");
66-
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ilm:qa:rest");
6764
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:basic-multi-node");
6865
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:disabled");
6966
map.put(LegacyRestTestBasePlugin.class, ":x-pack:plugin:ml:qa:ml-with-security");

test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,6 +2586,7 @@ public static Optional<Version> parseLegacyVersion(String version) {
25862586
protected static void waitForActiveLicense(final RestClient restClient) throws Exception {
25872587
assertBusy(() -> {
25882588
final Request request = new Request(HttpGet.METHOD_NAME, "/_xpack");
2589+
request.addParameter("categories", "license");
25892590
request.setOptions(RequestOptions.DEFAULT.toBuilder());
25902591

25912592
final Response response = restClient.performRequest(request);

x-pack/plugin/ilm/qa/multi-cluster/build.gradle

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,64 +5,20 @@
55
* 2.0.
66
*/
77

8-
import org.elasticsearch.gradle.internal.test.RestIntegTestTask
9-
import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE
10-
11-
apply plugin: 'elasticsearch.internal-testclusters'
12-
apply plugin: 'elasticsearch.standalone-rest-test'
8+
apply plugin: 'elasticsearch.internal-java-rest-test'
139

1410
dependencies {
15-
testImplementation project(':x-pack:plugin:core')
16-
testImplementation project(':x-pack:plugin:ilm')
17-
}
18-
19-
File repoDir = file("$buildDir/testclusters/repo")
20-
21-
tasks.register('leader-cluster', RestIntegTestTask) {
22-
mustRunAfter("precommit")
23-
systemProperty 'tests.target_cluster', 'leader'
24-
/* To support taking index snapshots, we have to set path.repo setting */
25-
nonInputProperties.systemProperty 'tests.path.repo', repoDir.absolutePath
26-
}
27-
28-
testClusters.matching { it.name == 'leader-cluster' }.configureEach {
29-
testDistribution = 'DEFAULT'
30-
setting 'path.repo', repoDir.absolutePath, IGNORE_VALUE
31-
setting 'xpack.ccr.enabled', 'true'
32-
setting 'xpack.security.enabled', 'false'
33-
setting 'xpack.watcher.enabled', 'false'
34-
setting 'xpack.ml.enabled', 'false'
35-
setting 'xpack.license.self_generated.type', 'trial'
36-
setting 'indices.lifecycle.poll_interval', '1000ms'
37-
}
38-
39-
tasks.register('follow-cluster', RestIntegTestTask) {
40-
dependsOn tasks.findByName('leader-cluster')
41-
useCluster testClusters.named('leader-cluster')
42-
systemProperty 'tests.target_cluster', 'follow'
43-
nonInputProperties.systemProperty 'tests.leader_host',
44-
"${-> testClusters."leader-cluster".getAllHttpSocketURI().get(0)}"
45-
nonInputProperties.systemProperty 'tests.leader_remote_cluster_seed',
46-
"${-> testClusters.'leader-cluster'.getAllTransportPortURI().get(0)}"
47-
/* To support taking index snapshots, we have to set path.repo setting */
48-
nonInputProperties.systemProperty 'tests.path.repo', repoDir.absolutePath
49-
}
50-
51-
testClusters.matching{ it.name == 'follow-cluster' }.configureEach {
52-
testDistribution = 'DEFAULT'
53-
setting 'path.repo', repoDir.absolutePath, IGNORE_VALUE
54-
setting 'xpack.ccr.enabled', 'true'
55-
setting 'xpack.security.enabled', 'false'
56-
setting 'xpack.watcher.enabled', 'false'
57-
setting 'xpack.ml.enabled', 'false'
58-
setting 'xpack.license.self_generated.type', 'trial'
59-
setting 'indices.lifecycle.poll_interval', '1000ms'
60-
setting 'cluster.remote.leader_cluster.seeds',
61-
{ "\"${testClusters.'leader-cluster'.getAllTransportPortURI().get(0)}\"" }, IGNORE_VALUE
11+
javaRestTestImplementation(testArtifact(project(xpackModule('core'))))
12+
javaRestTestImplementation(testArtifact(project(xpackModule('ccr')), 'javaRestTest'))
13+
javaRestTestImplementation project(xpackModule('ilm'))
14+
15+
clusterModules project(xpackModule('ilm'))
16+
clusterModules project(xpackModule('ccr'))
17+
clusterModules project(xpackModule('searchable-snapshots'))
18+
clusterModules project(':modules:data-streams')
6219
}
6320

64-
tasks.named("check").configure { dependsOn 'follow-cluster' }
65-
// Security is explicitly disabled for follow-cluster and leader-cluster, do not run these in FIPS mode
66-
tasks.withType(Test).configureEach {
67-
enabled = buildParams.inFipsJvm == false
21+
tasks.named("javaRestTest") {
22+
// Security is explicitly disabled for follow-cluster and leader-cluster, do not run these in FIPS mode
23+
buildParams.withFipsEnabledOnly(it)
6824
}
Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
package org.elasticsearch.xpack.ilm;
88

9+
import com.carrotsearch.randomizedtesting.annotations.Name;
10+
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
11+
912
import org.apache.http.entity.ContentType;
1013
import org.apache.http.entity.StringEntity;
1114
import org.apache.http.util.EntityUtils;
@@ -22,15 +25,20 @@
2225
import org.elasticsearch.common.xcontent.XContentHelper;
2326
import org.elasticsearch.core.TimeValue;
2427
import org.elasticsearch.rest.RestStatus;
28+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2529
import org.elasticsearch.xcontent.ObjectPath;
2630
import org.elasticsearch.xcontent.XContentBuilder;
2731
import org.elasticsearch.xcontent.XContentType;
2832
import org.elasticsearch.xcontent.json.JsonXContent;
33+
import org.elasticsearch.xpack.ccr.AbstractCCRRestTestCase;
2934
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
3035
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
3136
import org.elasticsearch.xpack.core.ilm.Phase;
3237
import org.elasticsearch.xpack.core.ilm.UnfollowAction;
3338
import org.elasticsearch.xpack.core.ilm.WaitUntilTimeSeriesEndTimePassesStep;
39+
import org.junit.ClassRule;
40+
import org.junit.rules.RuleChain;
41+
import org.junit.rules.TemporaryFolder;
3442

3543
import java.io.IOException;
3644
import java.io.InputStream;
@@ -50,7 +58,7 @@
5058
import static org.hamcrest.Matchers.notNullValue;
5159
import static org.hamcrest.Matchers.nullValue;
5260

53-
public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
61+
public class CCRIndexLifecycleIT extends AbstractCCRRestTestCase {
5462

5563
private static final Logger LOGGER = LogManager.getLogger(CCRIndexLifecycleIT.class);
5664
private static final String TSDB_INDEX_TEMPLATE = """
@@ -85,18 +93,69 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
8593
}
8694
}""";
8795

96+
public static TemporaryFolder repoDir = new TemporaryFolder();
97+
98+
public static ElasticsearchCluster leaderCluster = ElasticsearchCluster.local()
99+
.name("leader")
100+
.module("x-pack-ilm")
101+
.module("x-pack-ccr")
102+
.module("searchable-snapshots")
103+
.module("data-streams")
104+
.setting("path.repo", () -> repoDir.getRoot().getAbsolutePath())
105+
.setting("xpack.ccr.enabled", "true")
106+
.setting("xpack.security.enabled", "false")
107+
.setting("xpack.license.self_generated.type", "trial")
108+
.setting("indices.lifecycle.poll_interval", "1000ms")
109+
.build();
110+
111+
public static ElasticsearchCluster followerCluster = ElasticsearchCluster.local()
112+
.name("follower")
113+
.module("x-pack-ilm")
114+
.module("x-pack-ccr")
115+
.module("searchable-snapshots")
116+
.module("data-streams")
117+
.setting("path.repo", () -> repoDir.getRoot().getAbsolutePath())
118+
.setting("xpack.ccr.enabled", "true")
119+
.setting("xpack.security.enabled", "false")
120+
.setting("xpack.license.self_generated.type", "trial")
121+
.setting("indices.lifecycle.poll_interval", "1000ms")
122+
.setting("cluster.remote.leader_cluster.seeds", () -> "\"" + leaderCluster.getTransportEndpoints() + "\"")
123+
.build();
124+
125+
@ClassRule
126+
public static RuleChain ruleChain = RuleChain.outerRule(repoDir).around(leaderCluster).around(followerCluster);
127+
128+
public CCRIndexLifecycleIT(@Name("targetCluster") TargetCluster targetCluster) {
129+
super(targetCluster);
130+
}
131+
132+
@ParametersFactory
133+
public static Iterable<Object[]> parameters() throws Exception {
134+
return leaderFollower();
135+
}
136+
137+
@Override
138+
protected ElasticsearchCluster getFollowerCluster() {
139+
return followerCluster;
140+
}
141+
142+
@Override
143+
protected ElasticsearchCluster getLeaderCluster() {
144+
return leaderCluster;
145+
}
146+
88147
public void testBasicCCRAndILMIntegration() throws Exception {
89148
String indexName = "logs-1";
90149

91150
String policyName = "basic-test";
92-
if ("leader".equals(targetCluster)) {
151+
if (targetCluster == TargetCluster.LEADER) {
93152
putILMPolicy(policyName, "50GB", null, TimeValue.timeValueHours(7 * 24));
94153
Settings indexSettings = indexSettings(1, 0).put("index.lifecycle.name", policyName)
95154
.put("index.lifecycle.rollover_alias", "logs")
96155
.build();
97156
createIndex(indexName, indexSettings, "", "\"logs\": { }");
98157
ensureGreen(indexName);
99-
} else if ("follow".equals(targetCluster)) {
158+
} else if (targetCluster == TargetCluster.FOLLOWER) {
100159
// Policy with the same name must exist in follower cluster too:
101160
putILMPolicy(policyName, "50GB", null, TimeValue.timeValueHours(7 * 24));
102161
followIndex(indexName, indexName);
@@ -133,7 +192,7 @@ public void testBasicCCRAndILMIntegration() throws Exception {
133192
// ILM should have unfollowed the follower index, so the following_index setting should have been removed:
134193
// (this controls whether the follow engine is used)
135194
assertThat(getIndexSetting(client(), indexName, "index.xpack.ccr.following_index"), nullValue());
136-
});
195+
}, 30, TimeUnit.SECONDS);
137196
}
138197
} else {
139198
fail("unexpected target cluster [" + targetCluster + "]");
@@ -142,10 +201,10 @@ public void testBasicCCRAndILMIntegration() throws Exception {
142201

143202
public void testCCRUnfollowDuringSnapshot() throws Exception {
144203
String indexName = "unfollow-test-index";
145-
if ("leader".equals(targetCluster)) {
204+
if (targetCluster == TargetCluster.LEADER) {
146205
createIndex(adminClient(), indexName, indexSettings(2, 0).build());
147206
ensureGreen(indexName);
148-
} else if ("follow".equals(targetCluster)) {
207+
} else if (targetCluster == TargetCluster.FOLLOWER) {
149208
createNewSingletonPolicy("unfollow-only", "hot", UnfollowAction.INSTANCE, TimeValue.ZERO);
150209
followIndex(indexName, indexName);
151210
ensureGreen(indexName);
@@ -159,7 +218,7 @@ public void testCCRUnfollowDuringSnapshot() throws Exception {
159218
.field("type", "fs")
160219
.startObject("settings")
161220
.field("compress", randomBoolean())
162-
.field("location", System.getProperty("tests.path.repo"))
221+
.field("location", repoDir.getRoot().getAbsolutePath())
163222
.field("max_snapshot_bytes_per_sec", "256b")
164223
.endObject()
165224
.endObject()
@@ -212,7 +271,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
212271
String nextIndexName = "mymetrics-000002";
213272
String policyName = "rollover-test";
214273

215-
if ("leader".equals(targetCluster)) {
274+
if (targetCluster == TargetCluster.LEADER) {
216275
// Create a policy on the leader
217276
putILMPolicy(policyName, null, 1, null);
218277
Request templateRequest = new Request("PUT", "/_index_template/my_template");
@@ -223,7 +282,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
223282
"{\"index_patterns\": [\"mymetrics-*\"], \"template\":{\"settings\": " + Strings.toString(indexSettings) + "}}"
224283
);
225284
assertOK(client().performRequest(templateRequest));
226-
} else if ("follow".equals(targetCluster)) {
285+
} else if (targetCluster == TargetCluster.FOLLOWER) {
227286
// Policy with the same name must exist in follower cluster too:
228287
putILMPolicy(policyName, null, 1, null);
229288

@@ -327,7 +386,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
327386
final String policyName = "shrink-test-policy";
328387
final int numberOfAliases = randomIntBetween(0, 4);
329388

330-
if ("leader".equals(targetCluster)) {
389+
if (targetCluster == TargetCluster.LEADER) {
331390
// this policy won't exist on the leader, that's fine
332391
Settings indexSettings = indexSettings(3, 0).put("index.lifecycle.name", policyName).build();
333392
final StringBuilder aliases = new StringBuilder();
@@ -346,7 +405,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
346405
}
347406
createIndex(indexName, indexSettings, "", aliases.toString());
348407
ensureGreen(indexName);
349-
} else if ("follow".equals(targetCluster)) {
408+
} else if (targetCluster == TargetCluster.FOLLOWER) {
350409
// Create a policy with just a Shrink action on the follower
351410
putShrinkOnlyPolicy(client(), policyName);
352411

@@ -388,12 +447,12 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
388447
final String indexName = "shrink-test";
389448
final String policyName = "shrink-test-policy";
390449

391-
if ("leader".equals(targetCluster)) {
450+
if (targetCluster == TargetCluster.LEADER) {
392451
// this policy won't exist on the leader, that's fine
393452
Settings indexSettings = indexSettings(3, 0).put("index.lifecycle.name", policyName).build();
394453
createIndex(indexName, indexSettings, "", "");
395454
ensureGreen(indexName);
396-
} else if ("follow".equals(targetCluster)) {
455+
} else if (targetCluster == TargetCluster.FOLLOWER) {
397456
// Create a policy with just a Shrink action on the follower
398457
putShrinkOnlyPolicy(client(), policyName);
399458

@@ -430,14 +489,14 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
430489
public void testCannotShrinkLeaderIndex() throws Exception {
431490
String indexName = "shrink-leader-test";
432491
String policyName = "shrink-leader-test-policy";
433-
if ("leader".equals(targetCluster)) {
492+
if (targetCluster == TargetCluster.LEADER) {
434493
// Set up the policy and index, but don't attach the policy yet,
435494
// otherwise it'll proceed through shrink before we can set up the
436495
// follower
437496
putShrinkOnlyPolicy(client(), policyName);
438497
createIndex(indexName, indexSettings(2, 0).build(), "", "");
439498
ensureGreen(indexName);
440-
} else if ("follow".equals(targetCluster)) {
499+
} else if (targetCluster == TargetCluster.FOLLOWER) {
441500

442501
try (RestClient leaderClient = buildLeaderClient()) {
443502
// Policy with the same name must exist in follower cluster too:
@@ -502,16 +561,15 @@ public void testILMUnfollowFailsToRemoveRetentionLeases() throws Exception {
502561
final String followerIndex = "follower";
503562
final String policyName = "unfollow_only_policy";
504563

505-
if ("leader".equals(targetCluster)) {
564+
if (targetCluster == TargetCluster.LEADER) {
506565
Settings indexSettings = indexSettings(1, 0).put("index.lifecycle.name", policyName) // this policy won't exist on the leader,
507566
// that's fine
508567
.build();
509568
createIndex(leaderIndex, indexSettings, "", "");
510569
ensureGreen(leaderIndex);
511-
} else if ("follow".equals(targetCluster)) {
570+
} else if (targetCluster == TargetCluster.FOLLOWER) {
512571
try (RestClient leaderClient = buildLeaderClient()) {
513-
String leaderRemoteClusterSeed = System.getProperty("tests.leader_remote_cluster_seed");
514-
configureRemoteClusters("other_remote", leaderRemoteClusterSeed);
572+
configureRemoteClusters("other_remote", leaderCluster.getTransportEndpoints());
515573
assertBusy(() -> {
516574
Map<?, ?> localConnection = (Map<?, ?>) toMap(client().performRequest(new Request("GET", "/_remote/info"))).get(
517575
"other_remote"
@@ -576,12 +634,12 @@ public void testTsdbLeaderIndexRolloverAndSyncAfterWaitUntilEndTime() throws Exc
576634
String dataStream = "tsdb-index-cpu";
577635
String policyName = "tsdb-policy";
578636

579-
if ("leader".equals(targetCluster)) {
637+
if (targetCluster == TargetCluster.LEADER) {
580638
putILMPolicy(policyName, null, 1, null);
581639
Request templateRequest = new Request("PUT", "/_index_template/tsdb_template");
582640
templateRequest.setJsonEntity(Strings.format(TSDB_INDEX_TEMPLATE, indexPattern, policyName));
583641
assertOK(client().performRequest(templateRequest));
584-
} else if ("follow".equals(targetCluster)) {
642+
} else if (targetCluster == TargetCluster.FOLLOWER) {
585643
// Use unfollow-only policy for follower cluster instead of regular ILM policy
586644
// Follower clusters should not have their own rollover actions as they are meant
587645
// to follow the rollover behavior of the leader index, not initiate their own rollovers

0 commit comments

Comments
 (0)