Skip to content

Commit 7ea2e32

Browse files
committed
Add forwards compatibility testing (#123436)
1 parent 96a87cc commit 7ea2e32

File tree

8 files changed

+70
-8
lines changed

8 files changed

+70
-8
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import org.elasticsearch.gradle.VersionProperties
11+
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
12+
13+
def fwcVersions = buildParams.bwcVersions.released.findAll { it.major == VersionProperties.elasticsearchVersion.major && it.minor == VersionProperties.elasticsearchVersion.minor }
14+
def previousMinorSnapshot = buildParams.bwcVersions.unreleased.find { it.major == VersionProperties.elasticsearchVersion.major && it.minor == VersionProperties.elasticsearchVersion.minor - 1 }
15+
16+
fwcVersions.each { fwcVersion ->
17+
tasks.register("v${fwcVersion}#fwcTest", StandaloneRestIntegTestTask) {
18+
usesBwcDistribution(previousMinorSnapshot)
19+
usesBwcDistribution(fwcVersion)
20+
systemProperty("tests.old_cluster_version", previousMinorSnapshot)
21+
systemProperty("tests.new_cluster_version", fwcVersion)
22+
nonInputProperties.systemProperty 'tests.fwc', 'true'
23+
}
24+
}
25+
26+
gradle.taskGraph.whenReady { graph ->
27+
if (graph.allTasks.any { it.name.endsWith('#fwcTest') } && Boolean.parseBoolean(System.getProperty("tests.bwc.snapshot", "true"))) {
28+
throw new GradleException("Running forward compatibility tests requires passing `-Dtests.bwc.snapshot=false`.")
29+
}
30+
31+
if (graph.allTasks.any { it.name.endsWith('#fwcTest') } && graph.allTasks.any { it.name.endsWith('#bwcTest') }) {
32+
throw new GradleException("Backward compatibility and forward compatibility tests cannot be executed in the same build.")
33+
}
34+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ public void execute(Task task) {
145145
loggedExec.args("-DisCI");
146146
}
147147

148-
loggedExec.args("-Dbuild.snapshot=true", "-Dscan.tag.NESTED");
148+
loggedExec.args("-Dscan.tag.NESTED");
149+
150+
if (System.getProperty("tests.bwc.snapshot", "true").equals("false")) {
151+
loggedExec.args("-Dbuild.snapshot=false", "-Dlicense.key=x-pack/plugin/core/snapshot.key");
152+
} else {
153+
loggedExec.args("-Dbuild.snapshot=true");
154+
}
155+
149156
final LogLevel logLevel = project.getGradle().getStartParameter().getLogLevel();
150157
List<LogLevel> nonDefaultLogLevels = Arrays.asList(LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG);
151158
if (nonDefaultLogLevels.contains(logLevel)) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ static void createBuildBwcTask(
355355
String bwcTaskName = buildBwcTaskName(projectName);
356356
bwcSetupExtension.bwcTask(bwcTaskName, c -> {
357357
boolean useNativeExpanded = projectArtifact.expandedDistDir != null;
358+
boolean isReleaseBuild = System.getProperty("tests.bwc.snapshot", "true").equals("false");
358359
File expectedOutputFile = useNativeExpanded
359-
? new File(projectArtifact.expandedDistDir, "elasticsearch-" + bwcVersion.get() + "-SNAPSHOT")
360+
? new File(projectArtifact.expandedDistDir, "elasticsearch-" + bwcVersion.get() + (isReleaseBuild ? "" : "-SNAPSHOT"))
360361
: projectArtifact.distFile;
361362
c.getInputs().file(new File(project.getBuildDir(), "refspec")).withPathSensitivity(PathSensitivity.RELATIVE);
362363
if (useNativeExpanded) {

qa/rolling-upgrade/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
1212
apply plugin: 'elasticsearch.internal-java-rest-test'
1313
apply plugin: 'elasticsearch.internal-test-artifact-base'
1414
apply plugin: 'elasticsearch.bwc-test'
15+
apply plugin: 'elasticsearch.fwc-test'
1516

1617
testArtifacts {
1718
registerTestArtifactFromSourceSet(sourceSets.javaRestTest)

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/FeatureUpgradeIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.elasticsearch.client.Request;
1616
import org.elasticsearch.client.ResponseException;
1717
import org.elasticsearch.test.XContentTestUtils;
18+
import org.junit.BeforeClass;
1819

1920
import java.util.Collections;
2021
import java.util.List;
@@ -30,6 +31,11 @@ public FeatureUpgradeIT(@Name("upgradedNodes") int upgradedNodes) {
3031
super(upgradedNodes);
3132
}
3233

34+
@BeforeClass
35+
public static void ensureNotForwardCompatTest() {
36+
assumeFalse("Only supported by bwc tests", Boolean.parseBoolean(System.getProperty("tests.fwc", "false")));
37+
}
38+
3339
public void testGetFeatureUpgradeStatus() throws Exception {
3440

3541
final String systemIndexWarning = "this request accesses system indices: [.tasks], but in a future major version, direct "

qa/rolling-upgrade/src/javaRestTest/java/org/elasticsearch/upgrades/ParameterizedRollingUpgradeTestCase.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ public void upgradeNode() throws Exception {
103103
for (int n = 0; n < requestedUpgradedNodes; n++) {
104104
if (upgradedNodes.add(n)) {
105105
try {
106-
logger.info("Upgrading node {} to version {}", n, Version.CURRENT);
107-
getUpgradeCluster().upgradeNodeToVersion(n, Version.CURRENT);
106+
Version upgradeVersion = System.getProperty("tests.new_cluster_version") == null
107+
? Version.CURRENT
108+
: Version.fromString(System.getProperty("tests.new_cluster_version"));
109+
110+
logger.info("Upgrading node {} to version {}", n, upgradeVersion);
111+
getUpgradeCluster().upgradeNodeToVersion(n, upgradeVersion);
108112
} catch (Exception e) {
109113
upgradeFailed = true;
110114
throw e;

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,21 @@
1111

1212
import org.elasticsearch.test.cluster.SystemPropertyProvider;
1313

14+
import java.util.Collections;
15+
import java.util.HashMap;
1416
import java.util.Map;
1517

16-
import static java.util.Map.entry;
17-
1818
public class DefaultSystemPropertyProvider implements SystemPropertyProvider {
1919
@Override
2020
public Map<String, String> get(LocalClusterSpec.LocalNodeSpec nodeSpec) {
21-
return Map.ofEntries(entry("ingest.geoip.downloader.enabled.default", "false"), entry("tests.testfeatures.enabled", "true"));
21+
Map<String, String> properties = new HashMap<>();
22+
properties.put("ingest.geoip.downloader.enabled.default", "false");
23+
24+
// enable test features unless we are running forwards compatibility tests
25+
if (Boolean.parseBoolean(System.getProperty("tests.fwc", "false")) == false) {
26+
properties.put("tests.testfeatures.enabled", "true");
27+
}
28+
29+
return Collections.unmodifiableMap(properties);
2230
}
2331
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public DistributionDescriptor resolve(Version version, DistributionType type) {
3939

4040
// Snapshot distributions are never release builds and always use the default distribution
4141
Version realVersion = Version.fromString(System.getProperty("tests.bwc.main.version", version.toString()));
42-
return new DefaultDistributionDescriptor(realVersion, true, distributionDir, DistributionType.DEFAULT);
42+
boolean isSnapshot = System.getProperty("tests.bwc.snapshot", "true").equals("false") == false;
43+
return new DefaultDistributionDescriptor(realVersion, isSnapshot, distributionDir, DistributionType.DEFAULT);
4344
}
4445

4546
return delegate.resolve(version, type);

0 commit comments

Comments
 (0)