Skip to content

Commit ef08ab2

Browse files
moschefzowl
authored andcommitted
Migrate ILM REST tests to new test framework. (elastic#136744)
I'll follow up consolidating the projects in another PR. This felt easier to review if migrating in place. Relates to ES-11813
1 parent ed5c7cd commit ef08ab2

File tree

24 files changed

+239
-607
lines changed

24 files changed

+239
-607
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
@@ -2594,6 +2594,7 @@ public static Optional<Version> parseLegacyVersion(String version) {
25942594
protected static void waitForActiveLicense(final RestClient restClient) throws Exception {
25952595
assertBusy(() -> {
25962596
final Request request = new Request(HttpGet.METHOD_NAME, "/_xpack");
2597+
request.addParameter("categories", "license");
25972598
request.setOptions(RequestOptions.DEFAULT.toBuilder());
25982599

25992600
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;
@@ -23,16 +26,21 @@
2326
import org.elasticsearch.common.xcontent.XContentHelper;
2427
import org.elasticsearch.core.TimeValue;
2528
import org.elasticsearch.rest.RestStatus;
29+
import org.elasticsearch.test.cluster.ElasticsearchCluster;
2630
import org.elasticsearch.xcontent.ObjectPath;
2731
import org.elasticsearch.xcontent.XContentBuilder;
2832
import org.elasticsearch.xcontent.XContentType;
2933
import org.elasticsearch.xcontent.json.JsonXContent;
34+
import org.elasticsearch.xpack.ccr.AbstractCCRRestTestCase;
3035
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
3136
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
3237
import org.elasticsearch.xpack.core.ilm.Phase;
3338
import org.elasticsearch.xpack.core.ilm.UnfollowAction;
3439
import org.elasticsearch.xpack.core.ilm.WaitUntilTimeSeriesEndTimePassesStep;
3540
import org.elasticsearch.xpack.ilm.action.RestPutLifecycleAction;
41+
import org.junit.ClassRule;
42+
import org.junit.rules.RuleChain;
43+
import org.junit.rules.TemporaryFolder;
3644

3745
import java.io.IOException;
3846
import java.io.InputStream;
@@ -52,7 +60,7 @@
5260
import static org.hamcrest.Matchers.notNullValue;
5361
import static org.hamcrest.Matchers.nullValue;
5462

55-
public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
63+
public class CCRIndexLifecycleIT extends AbstractCCRRestTestCase {
5664

5765
private static final Logger LOGGER = LogManager.getLogger(CCRIndexLifecycleIT.class);
5866
private static final String TEST_PHASE = "hot";
@@ -88,18 +96,69 @@ public class CCRIndexLifecycleIT extends ESCCRRestTestCase {
8896
}
8997
}""";
9098

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

94153
String policyName = "basic-test";
95-
if ("leader".equals(targetCluster)) {
154+
if (targetCluster == TargetCluster.LEADER) {
96155
putILMPolicy(policyName, "50GB", null, TimeValue.timeValueHours(7 * 24));
97156
Settings indexSettings = indexSettings(1, 0).put("index.lifecycle.name", policyName)
98157
.put("index.lifecycle.rollover_alias", "logs")
99158
.build();
100159
createIndex(indexName, indexSettings, "", "\"logs\": { }");
101160
ensureGreen(indexName);
102-
} else if ("follow".equals(targetCluster)) {
161+
} else if (targetCluster == TargetCluster.FOLLOWER) {
103162
// Policy with the same name must exist in follower cluster too:
104163
putILMPolicy(policyName, "50GB", null, TimeValue.timeValueHours(7 * 24));
105164
followIndex(indexName, indexName);
@@ -136,7 +195,7 @@ public void testBasicCCRAndILMIntegration() throws Exception {
136195
// ILM should have unfollowed the follower index, so the following_index setting should have been removed:
137196
// (this controls whether the follow engine is used)
138197
assertThat(getIndexSetting(client(), indexName, "index.xpack.ccr.following_index"), nullValue());
139-
});
198+
}, 30, TimeUnit.SECONDS);
140199
}
141200
} else {
142201
fail("unexpected target cluster [" + targetCluster + "]");
@@ -145,10 +204,10 @@ public void testBasicCCRAndILMIntegration() throws Exception {
145204

146205
public void testCCRUnfollowDuringSnapshot() throws Exception {
147206
String indexName = "unfollow-test-index";
148-
if ("leader".equals(targetCluster)) {
207+
if (targetCluster == TargetCluster.LEADER) {
149208
createIndex(adminClient(), indexName, indexSettings(2, 0).build());
150209
ensureGreen(indexName);
151-
} else if ("follow".equals(targetCluster)) {
210+
} else if (targetCluster == TargetCluster.FOLLOWER) {
152211
createNewSingletonPolicy("unfollow-only", "hot", UnfollowAction.INSTANCE, TimeValue.ZERO);
153212
followIndex(indexName, indexName);
154213
ensureGreen(indexName);
@@ -162,7 +221,7 @@ public void testCCRUnfollowDuringSnapshot() throws Exception {
162221
.field("type", "fs")
163222
.startObject("settings")
164223
.field("compress", randomBoolean())
165-
.field("location", System.getProperty("tests.path.repo"))
224+
.field("location", repoDir.getRoot().getAbsolutePath())
166225
.field("max_snapshot_bytes_per_sec", "256b")
167226
.endObject()
168227
.endObject()
@@ -215,7 +274,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
215274
String nextIndexName = "mymetrics-000002";
216275
String policyName = "rollover-test";
217276

218-
if ("leader".equals(targetCluster)) {
277+
if (targetCluster == TargetCluster.LEADER) {
219278
// Create a policy on the leader
220279
putILMPolicy(policyName, null, 1, null);
221280
Request templateRequest = new Request("PUT", "/_index_template/my_template");
@@ -226,7 +285,7 @@ public void testCcrAndIlmWithRollover() throws Exception {
226285
"{\"index_patterns\": [\"mymetrics-*\"], \"template\":{\"settings\": " + Strings.toString(indexSettings) + "}}"
227286
);
228287
assertOK(client().performRequest(templateRequest));
229-
} else if ("follow".equals(targetCluster)) {
288+
} else if (targetCluster == TargetCluster.FOLLOWER) {
230289
// Policy with the same name must exist in follower cluster too:
231290
putILMPolicy(policyName, null, 1, null);
232291

@@ -330,7 +389,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
330389
final String policyName = "shrink-test-policy";
331390
final int numberOfAliases = randomIntBetween(0, 4);
332391

333-
if ("leader".equals(targetCluster)) {
392+
if (targetCluster == TargetCluster.LEADER) {
334393
// this policy won't exist on the leader, that's fine
335394
Settings indexSettings = indexSettings(3, 0).put("index.lifecycle.name", policyName).build();
336395
final StringBuilder aliases = new StringBuilder();
@@ -349,7 +408,7 @@ public void testAliasReplicatedOnShrink() throws Exception {
349408
}
350409
createIndex(indexName, indexSettings, "", aliases.toString());
351410
ensureGreen(indexName);
352-
} else if ("follow".equals(targetCluster)) {
411+
} else if (targetCluster == TargetCluster.FOLLOWER) {
353412
// Create a policy with just a Shrink action on the follower
354413
putShrinkOnlyPolicy(client(), policyName);
355414

@@ -391,12 +450,12 @@ public void testUnfollowInjectedBeforeShrink() throws Exception {
391450
final String indexName = "shrink-test";
392451
final String policyName = "shrink-test-policy";
393452

394-
if ("leader".equals(targetCluster)) {
453+
if (targetCluster == TargetCluster.LEADER) {
395454
// this policy won't exist on the leader, that's fine
396455
Settings indexSettings = indexSettings(3, 0).put("index.lifecycle.name", policyName).build();
397456
createIndex(indexName, indexSettings, "", "");
398457
ensureGreen(indexName);
399-
} else if ("follow".equals(targetCluster)) {
458+
} else if (targetCluster == TargetCluster.FOLLOWER) {
400459
// Create a policy with just a Shrink action on the follower
401460
putShrinkOnlyPolicy(client(), policyName);
402461

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

445504
try (RestClient leaderClient = buildLeaderClient()) {
446505
// Policy with the same name must exist in follower cluster too:
@@ -505,16 +564,15 @@ public void testILMUnfollowFailsToRemoveRetentionLeases() throws Exception {
505564
final String followerIndex = "follower";
506565
final String policyName = "unfollow_only_policy";
507566

508-
if ("leader".equals(targetCluster)) {
567+
if (targetCluster == TargetCluster.LEADER) {
509568
Settings indexSettings = indexSettings(1, 0).put("index.lifecycle.name", policyName) // this policy won't exist on the leader,
510569
// that's fine
511570
.build();
512571
createIndex(leaderIndex, indexSettings, "", "");
513572
ensureGreen(leaderIndex);
514-
} else if ("follow".equals(targetCluster)) {
573+
} else if (targetCluster == TargetCluster.FOLLOWER) {
515574
try (RestClient leaderClient = buildLeaderClient()) {
516-
String leaderRemoteClusterSeed = System.getProperty("tests.leader_remote_cluster_seed");
517-
configureRemoteClusters("other_remote", leaderRemoteClusterSeed);
575+
configureRemoteClusters("other_remote", leaderCluster.getTransportEndpoints());
518576
assertBusy(() -> {
519577
Map<?, ?> localConnection = (Map<?, ?>) toMap(client().performRequest(new Request("GET", "/_remote/info"))).get(
520578
"other_remote"
@@ -579,12 +637,12 @@ public void testTsdbLeaderIndexRolloverAndSyncAfterWaitUntilEndTime() throws Exc
579637
String dataStream = "tsdb-index-cpu";
580638
String policyName = "tsdb-policy";
581639

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

0 commit comments

Comments
 (0)