Skip to content

Migrate mixed cluster tests to new testing framework #131709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ private static ListMultimap<Class<?>, String> createLegacyRestTestBasePluginUsag
map.put(LegacyRestTestBasePlugin.class, ":distribution:docker");
map.put(LegacyRestTestBasePlugin.class, ":modules:reindex");
map.put(LegacyRestTestBasePlugin.class, ":qa:ccs-rolling-upgrade-remote-cluster");
map.put(LegacyRestTestBasePlugin.class, ":qa:mixed-cluster");
map.put(LegacyRestTestBasePlugin.class, ":qa:multi-cluster-search");
map.put(LegacyRestTestBasePlugin.class, ":qa:remote-clusters");
map.put(LegacyRestTestBasePlugin.class, ":qa:repository-multi-version");
Expand Down
85 changes: 22 additions & 63 deletions qa/mixed-cluster/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
*/


import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
import org.elasticsearch.gradle.util.GradleUtils
import org.elasticsearch.gradle.testclusters.TestClustersPlugin

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.bwc-test'
import static org.elasticsearch.gradle.internal.test.rest.RestTestUtil.registerTestTask

apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-yaml-rest-test'
apply plugin: 'elasticsearch.rest-resources'
apply plugin: 'elasticsearch.bwc-test'

dependencies {
restTestConfig project(path: ':modules:aggregations', configuration: 'restTests')
Expand Down Expand Up @@ -71,64 +67,27 @@ excludeList.add('aggregations/percentiles_hdr_metric/Negative values test')
// sync_id is removed in 9.0
excludeList.add("cat.shards/10_basic/Help")

def clusterPath = getPath()

buildParams.bwcVersions.withWireCompatible { bwcVersion, baseName ->
if (bwcVersion != VersionProperties.getElasticsearchVersion()) {
/* This project runs the core REST tests against a 4 node cluster where two of
the nodes has a different minor. */
def baseCluster = testClusters.register(baseName) {
versions = [bwcVersion.toString(), project.version]
numberOfNodes = 4
setting 'path.repo', "${layout.buildDirectory.asFile.get()}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
setting "xpack.license.self_generated.type", "trial"
/* There is a chance we have more master changes than "normal", so to avoid this test from failing,
we increase the threshold (as this purpose of this test isn't to test that specific indicator). */
if (bwcVersion.onOrAfter(Version.fromString("8.4.0"))) {
setting 'health.master_history.no_master_transitions_threshold', '10'
}
requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
requiresFeature 'sub_objects_auto', Version.fromString("8.16.0")
if (bwcVersion.before(Version.fromString("8.18.0"))) {
jvmArgs '-da:org.elasticsearch.index.mapper.DocumentMapper'
jvmArgs '-da:org.elasticsearch.index.mapper.MapperService'
}
registerTestTask(project, sourceSets.yamlRestTest, "v${bwcVersion}#yamlBwcTest", StandaloneRestIntegTestTask).configure {
usesBwcDistribution(bwcVersion)
systemProperty("tests.old_cluster_version", bwcVersion)
if (excludeList.isEmpty() == false) {
systemProperty 'tests.rest.blacklist', excludeList.join(',')
}
}

tasks.register("${baseName}#mixedClusterTest", StandaloneRestIntegTestTask) {
useCluster baseCluster
mustRunAfter("precommit")
def baseInfo = getClusterInfo(baseName).map { it.allHttpSocketURI.join(",") }
def baseInfoAfterOneNodeUpdate = getClusterInfo(baseName).map { it.allHttpSocketURI.join(",") }
def baseInfoAfterTwoNodesUpdate = getClusterInfo(baseName).map { it.allHttpSocketURI.join(",") }
def sharedRepoFolder = layout.buildDirectory.file("cluster/shared/repo/${baseName}").get().asFile
doFirst {
delete(sharedRepoFolder)
// Getting the endpoints causes a wait for the cluster
println "Test cluster endpoints are: ${-> baseInfo.get().join(",")}"
println "Upgrading one node to create a mixed cluster"
getRegistry().get().nextNodeToNextVersion(baseCluster)
registerTestTask(project, sourceSets.javaRestTest, "v${bwcVersion}#javaBwcTest", StandaloneRestIntegTestTask).configure {
usesBwcDistribution(bwcVersion)
systemProperty("tests.old_cluster_version", bwcVersion)
}

// Getting the endpoints causes a wait for the cluster
println "Upgrade complete, endpoints are: ${-> baseInfoAfterOneNodeUpdate.get()}"
println "Upgrading another node to create a mixed cluster"
getRegistry().get().nextNodeToNextVersion(baseCluster)
}
if (excludeList.isEmpty() == false) {
systemProperty 'tests.rest.blacklist', excludeList.join(',')
}
nonInputProperties.systemProperty('tests.rest.cluster', baseInfoAfterTwoNodesUpdate)
nonInputProperties.systemProperty('tests.clustername', baseName)
systemProperty 'tests.path.repo', "${layout.buildDirectory.file("cluster/shared/repo/${baseName}").get().asFile}"
systemProperty 'tests.bwc_nodes_version', bwcVersion.toString().replace('-SNAPSHOT', '')
systemProperty 'tests.new_nodes_version', project.version.toString().replace('-SNAPSHOT', '')
def bwcEnabled = project.bwc_tests_enabled
onlyIf("BWC tests disabled") { bwcEnabled }
}
tasks.register(bwcTaskName(bwcVersion)) {
dependsOn "v${bwcVersion}#yamlBwcTest", "v${bwcVersion}#javaBwcTest"
}

tasks.register(bwcTaskName(bwcVersion)) {
dependsOn "${baseName}#mixedClusterTest"
}
tasks.withType(Test).configureEach {
boolean bwcEnabled = project.bwc_tests_enabled
onlyIf("BWC tests enabled") { bwcEnabled }
nonInputProperties.systemProperty 'tests.bwc', 'true'
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.backwards;

import org.elasticsearch.Version;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.ClassRule;
import org.junit.rules.RuleChain;
import org.junit.rules.TemporaryFolder;

public abstract class AbstractMixedClusterTest extends ESRestTestCase {
protected static final String BWC_NODES_VERSION = System.getProperty("tests.old_cluster_version");

public static TemporaryFolder repo = new TemporaryFolder();

public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.withNode(n -> n.version(System.getProperty("tests.old_cluster_version")))
.withNode(n -> n.version(System.getProperty("tests.old_cluster_version")))
.withNode(n -> n.version(Version.CURRENT.toString()))
.withNode(n -> n.version(Version.CURRENT.toString()))
.setting("path.repo", () -> repo.getRoot().getAbsolutePath())
.setting("xpack.security.enabled", "false")
.setting("xpack.license.self_generated.type", "trial")
// There is a chance we have more master changes than "normal", so to avoid this test from failing, we increase the
// threshold (as this purpose of this test isn't to test that specific indicator).
.setting("health.master_history.no_master_transitions_threshold", () -> "10", s -> s.getVersion().onOrAfter("8.4.0"))
.apply(c -> {
if (Version.fromString(System.getProperty("tests.old_cluster_version")).before(Version.fromString("8.18.0"))) {
c.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper").jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
}
})
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.build();

@ClassRule
public static RuleChain ruleChain = RuleChain.outerRule(repo).around(cluster);

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@
import org.apache.http.util.EntityUtils;
import org.elasticsearch.client.Request;
import org.elasticsearch.client.Response;
import org.elasticsearch.test.rest.ESRestTestCase;

import static org.hamcrest.Matchers.equalTo;

public class HotThreadsIT extends ESRestTestCase {

private static final String BWC_NODES_VERSION = System.getProperty("tests.bwc_nodes_version");
public class HotThreadsIT extends AbstractMixedClusterTest {

public void testHotThreads() throws Exception {
final MixedClusterTestNodes nodes = MixedClusterTestNodes.buildNodes(client(), BWC_NODES_VERSION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.elasticsearch.core.RestApiVersion;
import org.elasticsearch.index.seqno.SeqNoStats;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.test.rest.ObjectPath;
import org.elasticsearch.xcontent.MediaType;
import org.elasticsearch.xcontent.XContentType;
Expand All @@ -38,8 +37,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.oneOf;

public class IndexingIT extends ESRestTestCase {
private static final String BWC_NODES_VERSION = System.getProperty("tests.bwc_nodes_version");
public class IndexingIT extends AbstractMixedClusterTest {

private int indexDocs(String index, final int idStart, final int numDocs) throws IOException {
for (int i = 0; i < numDocs; i++) {
Expand Down Expand Up @@ -234,7 +232,7 @@ public void testUpdateSnapshotStatus() throws Exception {
.field("type", "fs")
.startObject("settings")
.field("compress", randomBoolean())
.field("location", System.getProperty("tests.path.repo"))
.field("location", repo.getRoot().getAbsolutePath())
.endObject()
.endObject()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.support.XContentMapValues;
import org.elasticsearch.core.Strings;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.hamcrest.Matchers;

import java.io.IOException;
Expand All @@ -23,7 +22,7 @@
/**
* Test that index enough data to trigger the creation of Cuckoo filters.
*/
public class RareTermsIT extends ESRestTestCase {
public class RareTermsIT extends AbstractMixedClusterTest {

private static final String index = "idx";

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.backwards;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;

import org.apache.lucene.tests.util.TimeUnits;
import org.elasticsearch.Version;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.yaml.ClientYamlTestCandidate;
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;

@TimeoutSuite(millis = 60 * TimeUnits.MINUTE) // some of the windows test VMs are slow as hell
public class MixedClusterClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.withNode(n -> n.version(System.getProperty("tests.old_cluster_version")))
.withNode(n -> n.version(System.getProperty("tests.old_cluster_version")))
.withNode(n -> n.version(Version.CURRENT.toString()))
.withNode(n -> n.version(Version.CURRENT.toString()))
.setting("xpack.security.enabled", "false")
.setting("xpack.license.self_generated.type", "trial")
// There is a chance we have more master changes than "normal", so to avoid this test from failing, we increase the
// threshold (as this purpose of this test isn't to test that specific indicator).
.setting("health.master_history.no_master_transitions_threshold", () -> "10", s -> s.getVersion().onOrAfter("8.4.0"))
.apply(c -> {
if (Version.fromString(System.getProperty("tests.old_cluster_version")).before(Version.fromString("8.18.0"))) {
c.jvmArg("-da:org.elasticsearch.index.mapper.DocumentMapper").jvmArg("-da:org.elasticsearch.index.mapper.MapperService");
}
})
.feature(FeatureFlag.TIME_SERIES_MODE)
.feature(FeatureFlag.SUB_OBJECTS_AUTO_ENABLED)
.build();

public MixedClusterClientYamlTestSuiteIT(ClientYamlTestCandidate testCandidate) {
super(testCandidate);
}

@ParametersFactory
public static Iterable<Object[]> parameters() throws Exception {
return createParameters();
}

@Override
protected boolean randomizeContentType() {
return false;
}

@Override
protected String getTestRestCluster() {
return cluster.getHttpAddresses();
}
}