Skip to content
Merged
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
14 changes: 14 additions & 0 deletions build-tools-internal/src/main/groovy/elasticsearch.bwc-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.internal.ElasticsearchTestBasePlugin
import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.internal.test.rest.InternalJavaRestTestPlugin
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask

ext.bwcTaskName = { Version version ->
return "v${version}#bwcTest"
Expand Down Expand Up @@ -36,5 +38,17 @@ plugins.withType(ElasticsearchTestBasePlugin) {
}
}

plugins.withType(InternalJavaRestTestPlugin) {
tasks.named("javaRestTest") {
enabled = false
}

tasks.withType(StandaloneRestIntegTestTask).configureEach {
testClassesDirs = sourceSets.javaRestTest.output.classesDirs
classpath = sourceSets.javaRestTest.runtimeClasspath
usesDefaultDistribution()
}
}

tasks.matching { it.name.equals("check") }.configureEach {dependsOn(bwcTestSnapshots) }
tasks.matching { it.name.equals("test") }.configureEach {enabled = false}
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,11 @@ public List<Version> getAllIndexCompatible() {
.collect(Collectors.toList());
}

public void withIndexCompatiple(BiConsumer<Version, String> versionAction) {
public void withIndexCompatible(BiConsumer<Version, String> versionAction) {
getIndexCompatible().forEach(v -> versionAction.accept(v, "v" + v.toString()));
}

public void withIndexCompatiple(Predicate<Version> filter, BiConsumer<Version, String> versionAction) {
public void withIndexCompatible(Predicate<Version> filter, BiConsumer<Version, String> versionAction) {
getIndexCompatible().stream().filter(filter).forEach(v -> versionAction.accept(v, "v" + v.toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void execute(Task t) {
test.getJvmArgumentProviders().add(nonInputProperties);
test.getExtensions().add("nonInputProperties", nonInputProperties);

test.setWorkingDir(project.file(project.getBuildDir() + "/testrun/" + test.getName()));
test.setWorkingDir(project.file(project.getBuildDir() + "/testrun/" + test.getName().replace("#", "_")));
test.setMaxParallelForks(Integer.parseInt(System.getProperty("tests.jvms", BuildParams.getDefaultParallel().toString())));

test.exclude("**/*$*.class");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import org.elasticsearch.gradle.Architecture;
import org.elasticsearch.gradle.DistributionDownloadPlugin;
import org.elasticsearch.gradle.ElasticsearchDistribution;
import org.elasticsearch.gradle.ElasticsearchDistributionType;
import org.elasticsearch.gradle.Jdk;
import org.elasticsearch.gradle.JdkDownloadPlugin;
import org.elasticsearch.gradle.OS;
import org.elasticsearch.gradle.Version;
import org.elasticsearch.gradle.VersionProperties;
import org.elasticsearch.gradle.distribution.ElasticsearchDistributionTypes;
import org.elasticsearch.gradle.internal.ElasticsearchJavaPlugin;
Expand Down Expand Up @@ -54,15 +59,20 @@
public class RestTestBasePlugin implements Plugin<Project> {

private static final String TESTS_RUNTIME_JAVA_SYSPROP = "tests.runtime.java";
private static final String TESTS_LEGACY_JAVA_SYSPROP = "tests.legacy.java";
private static final String DEFAULT_DISTRIBUTION_SYSPROP = "tests.default.distribution";
private static final String INTEG_TEST_DISTRIBUTION_SYSPROP = "tests.integ-test.distribution";
private static final String BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX = "tests.snapshot.distribution.";
private static final String BWC_RELEASED_DISTRIBUTION_SYSPROP_PREFIX = "tests.release.distribution.";
private static final String TESTS_CLUSTER_MODULES_PATH_SYSPROP = "tests.cluster.modules.path";
private static final String TESTS_CLUSTER_PLUGINS_PATH_SYSPROP = "tests.cluster.plugins.path";
private static final String DEFAULT_REST_INTEG_TEST_DISTRO = "default_distro";
private static final String INTEG_TEST_REST_INTEG_TEST_DISTRO = "integ_test_distro";
private static final String MODULES_CONFIGURATION = "clusterModules";
private static final String PLUGINS_CONFIGURATION = "clusterPlugins";
private static final String EXTRACTED_PLUGINS_CONFIGURATION = "extractedPlugins";
private static final String LEGACY_JAVA_VENDOR = "adoptium";
private static final String LEGACY_JAVA_VERSION = "8u302+b08";

private final ProviderFactory providerFactory;

Expand All @@ -75,18 +85,20 @@ public RestTestBasePlugin(ProviderFactory providerFactory) {
public void apply(Project project) {
project.getPluginManager().apply(ElasticsearchJavaPlugin.class);
project.getPluginManager().apply(InternalDistributionDownloadPlugin.class);
project.getPluginManager().apply(JdkDownloadPlugin.class);

// Register integ-test and default distributions
NamedDomainObjectContainer<ElasticsearchDistribution> distributions = DistributionDownloadPlugin.getContainer(project);
ElasticsearchDistribution defaultDistro = distributions.create(DEFAULT_REST_INTEG_TEST_DISTRO, distro -> {
distro.setVersion(VersionProperties.getElasticsearch());
distro.setArchitecture(Architecture.current());
});
ElasticsearchDistribution integTestDistro = distributions.create(INTEG_TEST_REST_INTEG_TEST_DISTRO, distro -> {
distro.setVersion(VersionProperties.getElasticsearch());
distro.setArchitecture(Architecture.current());
distro.setType(ElasticsearchDistributionTypes.INTEG_TEST_ZIP);
});
ElasticsearchDistribution defaultDistro = createDistribution(
project,
DEFAULT_REST_INTEG_TEST_DISTRO,
VersionProperties.getElasticsearch()
);
ElasticsearchDistribution integTestDistro = createDistribution(
project,
INTEG_TEST_REST_INTEG_TEST_DISTRO,
VersionProperties.getElasticsearch(),
ElasticsearchDistributionTypes.INTEG_TEST_ZIP
);

// Create configures for module and plugin dependencies
Configuration modulesConfiguration = createPluginConfiguration(project, MODULES_CONFIGURATION, true);
Expand All @@ -105,6 +117,14 @@ public void apply(Project project) {

});

// Register legacy JDK for running pre-7.0 clusters
Jdk legacyJdk = JdkDownloadPlugin.getContainer(project).create("legacy_jdk", jdk -> {
jdk.setVendor(LEGACY_JAVA_VENDOR);
jdk.setVersion(LEGACY_JAVA_VERSION);
jdk.setPlatform(OS.current().name().toLowerCase());
jdk.setArchitecture(Architecture.current().name().toLowerCase());
});

project.getTasks().withType(StandaloneRestIntegTestTask.class).configureEach(task -> {
SystemPropertyCommandLineArgumentProvider nonInputSystemProperties = task.getExtensions()
.getByType(SystemPropertyCommandLineArgumentProvider.class);
Expand Down Expand Up @@ -149,13 +169,67 @@ public Void call(Object... args) {
return null;
}
});

// Add `usesBwcDistribution(version)` extension method to test tasks to indicate they require a BWC distribution
task.getExtensions().getExtraProperties().set("usesBwcDistribution", new Closure<Void>(task) {
@Override
public Void call(Object... args) {
if (args.length != 1 && args[0] instanceof Version == false) {
throw new IllegalArgumentException("Expected exactly one argument of type org.elasticsearch.gradle.Version");
}

Version version = (Version) args[0];
boolean isReleased = BuildParams.getBwcVersions().unreleasedInfo(version) == null;
String versionString = version.toString();
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString);

task.dependsOn(bwcDistro);
registerDistributionInputs(task, bwcDistro);

nonInputSystemProperties.systemProperty(
(isReleased ? BWC_RELEASED_DISTRIBUTION_SYSPROP_PREFIX : BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX) + versionString,
providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath())
);

// If we're testing a version pre-7.0 we also need a compatible JDK
if (version.before("7.0.0")) {
task.dependsOn(legacyJdk);
nonInputSystemProperties.systemProperty(
TESTS_LEGACY_JAVA_SYSPROP,
providerFactory.provider(() -> legacyJdk.getJavaHomePath().toString())
);
}

return null;
}
});
});

project.getTasks()
.named(JavaBasePlugin.CHECK_TASK_NAME)
.configure(check -> check.dependsOn(project.getTasks().withType(StandaloneRestIntegTestTask.class)));
}

private ElasticsearchDistribution createDistribution(Project project, String name, String version) {
return createDistribution(project, name, version, null);
}

private ElasticsearchDistribution createDistribution(Project project, String name, String version, ElasticsearchDistributionType type) {
NamedDomainObjectContainer<ElasticsearchDistribution> distributions = DistributionDownloadPlugin.getContainer(project);
ElasticsearchDistribution maybeDistro = distributions.findByName(name);
if (maybeDistro == null) {
return distributions.create(name, distro -> {
distro.setVersion(version);
distro.setArchitecture(Architecture.current());
if (type != null) {
distro.setType(type);
}
});
} else {
return maybeDistro;
}
}

private FileTree getDistributionFiles(ElasticsearchDistribution distribution, Action<PatternFilterable> patternFilter) {
return distribution.getExtracted().getAsFileTree().matching(patternFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
*/
package org.elasticsearch.gradle;

import java.io.Serializable;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* Encapsulates comparison and printing logic for an x.y.z version.
*/
public final class Version implements Comparable<Version> {
public final class Version implements Comparable<Version>, Serializable {
private final int major;
private final int minor;
private final int revision;
Expand Down
52 changes: 9 additions & 43 deletions qa/full-cluster-restart/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,20 @@
* Side Public License, v 1.
*/


import org.elasticsearch.gradle.internal.info.BuildParams
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask

apply plugin: 'elasticsearch.internal-testclusters'
apply plugin: 'elasticsearch.standalone-rest-test'
apply plugin: 'elasticsearch.internal-test-artifact'
apply plugin: 'elasticsearch.internal-java-rest-test'
apply plugin: 'elasticsearch.internal-test-artifact-base'
apply plugin: 'elasticsearch.bwc-test'

BuildParams.bwcVersions.withIndexCompatiple { bwcVersion, baseName ->
def baseCluster = testClusters.register(baseName) {
versions = [bwcVersion.toString(), project.version]
numberOfNodes = 2
// some tests rely on the translog not being flushed
setting 'indices.memory.shard_inactive_time', '60m'
setting 'http.content_type.required', 'true'
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
setting 'xpack.security.enabled', 'false'
}

tasks.register("${baseName}#oldClusterTest", StandaloneRestIntegTestTask) {
useCluster baseCluster
mustRunAfter("precommit")
doFirst {
delete("${buildDir}/cluster/shared/repo/${baseName}")
}

systemProperty 'tests.is_old_cluster', 'true'
}

tasks.register("${baseName}#upgradedClusterTest", StandaloneRestIntegTestTask) {
useCluster baseCluster
dependsOn "${baseName}#oldClusterTest"
doFirst {
baseCluster.get().goToNextVersion()
}
systemProperty 'tests.is_old_cluster', 'false'
}

String oldVersion = bwcVersion.toString().minus("-SNAPSHOT")
tasks.matching { it.name.startsWith(baseName) && it.name.endsWith("ClusterTest") }.configureEach {
it.systemProperty 'tests.old_cluster_version', oldVersion
it.systemProperty 'tests.path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
it.nonInputProperties.systemProperty('tests.rest.cluster', baseCluster.map(c -> c.allHttpSocketURI.join(",")))
it.nonInputProperties.systemProperty('tests.clustername', baseName)
}
testArtifacts {
registerTestArtifactFromSourceSet(sourceSets.javaRestTest)
}

tasks.register(bwcTaskName(bwcVersion)) {
dependsOn tasks.named("${baseName}#upgradedClusterTest")
BuildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName ->
tasks.register(bwcTaskName(bwcVersion), StandaloneRestIntegTestTask) {
usesBwcDistribution(bwcVersion)
systemProperty("tests.old_cluster_version", bwcVersion)
}
}
Loading