Skip to content

Commit 4494db3

Browse files
committed
[Test] Replace 0.0.0 version with "detached" property on
ElasticsearchDistibution for tests Introduce a new property to indicate if the version is a custom build not tied to any release. This was previously handled by specifying version as 0.0.0, but caused problems when comparing versions (e.g., to decide on configuration).
1 parent 2f49a5e commit 4494db3

File tree

23 files changed

+207
-64
lines changed

23 files changed

+207
-64
lines changed

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginFuncTest.groovy

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
5151
def "resolves expanded bwc versions from source"() {
5252
given:
5353
internalBuild()
54-
bwcMajor1ProjectSetup()
54+
bwcProjectSetup("major1")
5555
buildFile << """
5656
apply plugin: 'elasticsearch.internal-distribution-download'
5757
@@ -81,7 +81,7 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
8181
def "fails on resolving bwc versions with no bundled jdk"() {
8282
given:
8383
internalBuild()
84-
bwcMajor1ProjectSetup()
84+
bwcProjectSetup("major1")
8585
buildFile << """
8686
apply plugin: 'elasticsearch.internal-distribution-download'
8787
@@ -105,12 +105,47 @@ class InternalDistributionDownloadPluginFuncTest extends AbstractGradleFuncTest
105105
"without a bundled JDK is not supported.")
106106
}
107107

108-
private void bwcMajor1ProjectSetup() {
108+
def "resolves detached version from source"() {
109+
given:
110+
internalBuild()
111+
bwcProjectSetup("main")
112+
buildFile << """
113+
apply plugin: 'elasticsearch.internal-distribution-download'
114+
115+
System.setProperty("tests.bwc.main.version", "9.2.0")
116+
117+
elasticsearch_distributions {
118+
test_distro {
119+
version = "9.2.0"
120+
type = "archive"
121+
platform = "linux"
122+
architecture = Architecture.current();
123+
detachedVersion = true
124+
}
125+
}
126+
127+
tasks.register("setupDistro", Sync) {
128+
from(elasticsearch_distributions.test_distro)
129+
into("build/distro")
130+
}
131+
"""
132+
133+
when:
134+
def result = gradleRunner("setupDistro").build()
135+
136+
then:
137+
result.task(":distribution:bwc:main:buildBwcExpandedTask").outcome == TaskOutcome.SUCCESS
138+
result.task(":setupDistro").outcome == TaskOutcome.SUCCESS
139+
assertExtractedDistroIsCreated("distribution/bwc/main/build/install/elastic-distro",
140+
'bwc-marker.txt')
141+
}
142+
143+
private void bwcProjectSetup(String bwcProjectName) {
109144
settingsFile << """
110-
include ':distribution:bwc:major1'
145+
include ':distribution:bwc:$bwcProjectName'
111146
"""
112-
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", "major1")
113-
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=major1"
147+
def bwcSubProjectFolder = testProjectDir.newFolder("distribution", "bwc", bwcProjectName)
148+
new File(bwcSubProjectFolder, 'bwc-marker.txt') << "bwc=$bwcProjectName"
114149
new File(bwcSubProjectFolder, 'build.gradle') << """
115150
apply plugin:'base'
116151

build-tools-internal/src/main/groovy/elasticsearch.bc-upgrade-test.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ import org.elasticsearch.gradle.Version
1111
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
1212

1313
tasks.register("bcUpgradeTest", StandaloneRestIntegTestTask) {
14-
// We use a phony version here as the real version is provided via `tests.bwc.main.version` system property
15-
usesBwcDistribution(Version.fromString("0.0.0"))
16-
systemProperty("tests.old_cluster_version", "0.0.0")
17-
onlyIf("tests.bwc.main.version system property exists") { System.getProperty("tests.bwc.main.version") != null }
14+
doFirst {
15+
if (System.getProperty("tests.bwc.refspec.main") == null) {
16+
throw new GradleException("You must set the `tests.bwc.refspec.main` system property to run bcUpgradeTest")
17+
}
18+
if (System.getProperty("tests.bwc.main.version") == null) {
19+
throw new GradleException("You must set the `tests.bwc.main.version` system property to run bcUpgradeTest")
20+
}
21+
}
22+
if (System.getProperty("tests.bwc.refspec.main") != null && System.getProperty("tests.bwc.main.version") != null) {
23+
usesBwcDistributionFromRef(System.getProperty("tests.bwc.refspec.main"), Version.fromString(System.getProperty("tests.bwc.main.version")))
24+
systemProperty("tests.old_cluster_version", System.getProperty("tests.bwc.main.version"))
25+
}
1826
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void apply(Project project) {
7474
*/
7575
private void registerInternalDistributionResolutions(List<DistributionResolution> resolutions, Provider<BwcVersions> bwcVersions) {
7676
resolutions.add(new DistributionResolution("local-build", (project, distribution) -> {
77-
if (isCurrentVersion(distribution)) {
77+
if (isCurrentVersion(distribution) && distribution.isDetachedVersion() == false) {
7878
// non-external project, so depend on local build
7979
return new ProjectBasedDistributionDependency(
8080
config -> projectDependency(project.getDependencies(), distributionProjectPath(distribution), config)
@@ -86,7 +86,7 @@ private void registerInternalDistributionResolutions(List<DistributionResolution
8686
resolutions.add(new DistributionResolution("bwc", (project, distribution) -> {
8787
BwcVersions.UnreleasedVersionInfo unreleasedInfo = bwcVersions.get()
8888
.unreleasedInfo(Version.fromString(distribution.getVersion()));
89-
if (unreleasedInfo != null) {
89+
if (unreleasedInfo != null && distribution.isDetachedVersion() == false) {
9090
if (distribution.getBundledJdk() == false) {
9191
throw new GradleException(
9292
"Configuring a snapshot bwc distribution ('"
@@ -103,16 +103,15 @@ private void registerInternalDistributionResolutions(List<DistributionResolution
103103
return null;
104104
}));
105105

106-
// Distribution resolution for "override" versions. This allows for building from source for any version, including the current
106+
// Distribution resolution for "detached" versions. This allows for building from source for any version, including the current
107107
// version of existing released versions from a commit form the main branch. This is done by passing certain system properties, ex:
108108
//
109109
// -Dtests.bwc.refspec.main=deadbeef -Dtests.bwc.main.version=9.0.0
110110
//
111111
// The 'test.bwc.main.version' property should map to the version returned by the commit referenced in 'tests.bwc.refspec.main'.
112-
resolutions.add(new DistributionResolution("override", (project, distribution) -> {
113-
String versionProperty = System.getProperty("tests.bwc.main.version");
114-
// We use this phony version as a placeholder for the real version
115-
if (distribution.getVersion().equals("0.0.0")) {
112+
resolutions.add(new DistributionResolution("detached", (project, distribution) -> {
113+
if (distribution.isDetachedVersion()) {
114+
String versionProperty = System.getProperty("tests.bwc.main.version");
116115
BwcVersions.UnreleasedVersionInfo unreleasedVersionInfo = new BwcVersions.UnreleasedVersionInfo(
117116
Version.fromString(versionProperty),
118117
"main",

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/rest/RestTestBasePlugin.java

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,15 @@ public void apply(Project project) {
100100
ElasticsearchDistribution defaultDistro = createDistribution(
101101
project,
102102
DEFAULT_REST_INTEG_TEST_DISTRO,
103-
VersionProperties.getElasticsearch()
103+
VersionProperties.getElasticsearch(),
104+
false
104105
);
105106
ElasticsearchDistribution integTestDistro = createDistribution(
106107
project,
107108
INTEG_TEST_REST_INTEG_TEST_DISTRO,
108109
VersionProperties.getElasticsearch(),
109-
ElasticsearchDistributionTypes.INTEG_TEST_ZIP
110+
ElasticsearchDistributionTypes.INTEG_TEST_ZIP,
111+
false
110112
);
111113

112114
// Create configures for module and plugin dependencies
@@ -232,9 +234,9 @@ public Void call(Object... args) {
232234
}
233235

234236
Version version = (Version) args[0];
235-
boolean isReleased = bwcVersions.unreleasedInfo(version) == null && version.toString().equals("0.0.0") == false;
237+
boolean isReleased = bwcVersions.unreleasedInfo(version) == null;
236238
String versionString = version.toString();
237-
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString);
239+
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + versionString, versionString, false);
238240

239241
task.dependsOn(bwcDistro);
240242
registerDistributionInputs(task, bwcDistro);
@@ -244,13 +246,38 @@ public Void call(Object... args) {
244246
providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath())
245247
);
246248

247-
if (version.getMajor() > 0 && version.before(bwcVersions.getMinimumWireCompatibleVersion())) {
249+
if (version.before(bwcVersions.getMinimumWireCompatibleVersion())) {
248250
// If we are upgrade testing older versions we also need to upgrade to 7.last
249251
this.call(bwcVersions.getMinimumWireCompatibleVersion());
250252
}
251253
return null;
252254
}
253255
});
256+
257+
task.getExtensions().getExtraProperties().set("usesBwcDistributionFromRef", new Closure<Void>(task) {
258+
@Override
259+
public Void call(Object... args) {
260+
if (args.length != 2 || args[0] instanceof String == false || args[1] instanceof Version == false) {
261+
throw new IllegalArgumentException("Expected arguments (String refSpec, org.elasticsearch.gradle.Version version)");
262+
}
263+
264+
String refSpec = (String) args[0];
265+
Version version = (Version) args[1];
266+
boolean isDetachedVersion = true;
267+
String versionString = version.toString();
268+
269+
ElasticsearchDistribution bwcDistro = createDistribution(project, "bwc_" + refSpec, versionString, isDetachedVersion);
270+
271+
task.dependsOn(bwcDistro);
272+
registerDistributionInputs(task, bwcDistro);
273+
274+
nonInputSystemProperties.systemProperty(
275+
BWC_SNAPSHOT_DISTRIBUTION_SYSPROP_PREFIX + versionString,
276+
providerFactory.provider(() -> bwcDistro.getExtracted().getSingleFile().getPath())
277+
);
278+
return null;
279+
}
280+
});
254281
});
255282
}
256283

@@ -262,16 +289,23 @@ private void copyDependencies(Project project, DependencySet dependencies, Confi
262289
.forEach(dependencies::add);
263290
}
264291

265-
private ElasticsearchDistribution createDistribution(Project project, String name, String version) {
266-
return createDistribution(project, name, version, null);
292+
private ElasticsearchDistribution createDistribution(Project project, String name, String version, boolean detachedVersion) {
293+
return createDistribution(project, name, version, null, detachedVersion);
267294
}
268295

269-
private ElasticsearchDistribution createDistribution(Project project, String name, String version, ElasticsearchDistributionType type) {
296+
private ElasticsearchDistribution createDistribution(
297+
Project project,
298+
String name,
299+
String version,
300+
ElasticsearchDistributionType type,
301+
boolean detachedVersion
302+
) {
270303
NamedDomainObjectContainer<ElasticsearchDistribution> distributions = DistributionDownloadPlugin.getContainer(project);
271304
ElasticsearchDistribution maybeDistro = distributions.findByName(name);
272305
if (maybeDistro == null) {
273306
return distributions.create(name, distro -> {
274307
distro.setVersion(version);
308+
distro.setDetachedVersion(detachedVersion);
275309
distro.setArchitecture(Architecture.current());
276310
if (type != null) {
277311
distro.setType(type);

build-tools/src/main/java/org/elasticsearch/gradle/ElasticsearchDistribution.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public String toString() {
4949

5050
private final Property<Architecture> architecture;
5151
private final Property<String> version;
52+
private final Property<Boolean> detachedVersion;
5253
private final Property<ElasticsearchDistributionType> type;
5354
private final Property<Platform> platform;
5455
private final Property<Boolean> bundledJdk;
@@ -69,6 +70,7 @@ public String toString() {
6970
this.configuration = fileConfiguration;
7071
this.architecture = objectFactory.property(Architecture.class);
7172
this.version = objectFactory.property(String.class).convention(VersionProperties.getElasticsearch());
73+
this.detachedVersion = objectFactory.property(Boolean.class).convention(false);
7274
this.type = objectFactory.property(ElasticsearchDistributionType.class);
7375
this.type.convention(ElasticsearchDistributionTypes.ARCHIVE);
7476
this.platform = objectFactory.property(Platform.class);
@@ -91,6 +93,19 @@ public void setVersion(String version) {
9193
this.version.set(version);
9294
}
9395

96+
/**
97+
* Informs if the version is not tied to any Elasticsearch release and is a custom build.
98+
* This is true when the distribution is not from HEAD but also not any known released version.
99+
* In that case the detached source build needs to be prepared by `usedBwcDistributionFromRef(ref, version)`.
100+
*/
101+
public boolean isDetachedVersion() {
102+
return detachedVersion.get();
103+
}
104+
105+
public void setDetachedVersion(boolean detachedVersion) {
106+
this.detachedVersion.set(detachedVersion);
107+
}
108+
94109
public Platform getPlatform() {
95110
return platform.getOrNull();
96111
}

build-tools/src/main/java/org/elasticsearch/gradle/Version.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public static Version fromString(final String s, final Mode mode) {
7979
String revision = matcher.group(3);
8080
String qualifier = matcher.group(4);
8181

82+
if (major.equals("0") && minor.equals("0") && revision.equals("0")) {
83+
throw new IllegalArgumentException("Version 0.0.0 is not allowed");
84+
}
85+
8286
return new Version(Integer.parseInt(major), Integer.parseInt(minor), revision == null ? 0 : Integer.parseInt(revision), qualifier);
8387
}
8488

build-tools/src/test/groovy/org/elasticsearch/gradle/VersionSpec.groovy

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ class VersionSpec extends Specification {
7676
then:
7777
e = thrown(IllegalArgumentException)
7878
assert e.message == "Invalid version format: 'foo.bar.baz'. Should be major.minor.revision[-(alpha|beta|rc)Number|-SNAPSHOT]"
79+
80+
when:
81+
Version.fromString("0.0.0")
82+
then:
83+
e = thrown(IllegalArgumentException)
84+
assert e.message == "Version 0.0.0 is not allowed"
7985
}
8086

8187
def "handles qualifier"() {

qa/full-cluster-restart/build.gradle

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ buildParams.bwcVersions.withIndexCompatible { bwcVersion, baseName ->
2323
}
2424

2525
tasks.register("luceneBwcTest", StandaloneRestIntegTestTask) {
26-
// We use a phony version here as the real version is provided via `tests.bwc.main.version` system property
27-
usesBwcDistribution(Version.fromString("0.0.0"))
28-
systemProperty("tests.old_cluster_version", "0.0.0")
29-
onlyIf("tests.bwc.main.version system property exists") { System.getProperty("tests.bwc.main.version") != null }
26+
doFirst {
27+
if (System.getProperty("tests.bwc.refspec.main") == null) {
28+
throw new GradleException("You must set the `tests.bwc.refspec.main` system property to run luceneBwcTest")
29+
}
30+
if (System.getProperty("tests.bwc.main.version") == null) {
31+
throw new GradleException("You must set the `tests.bwc.main.version` system property to run luceneBwcTest")
32+
}
33+
}
34+
if (System.getProperty("tests.bwc.refspec.main") != null && System.getProperty("tests.bwc.main.version") != null) {
35+
usesBwcDistributionFromRef(System.getProperty("tests.bwc.refspec.main"), Version.fromString(System.getProperty("tests.bwc.main.version")))
36+
systemProperty("tests.old_cluster_version", System.getProperty("tests.bwc.main.version"))
37+
}
3038
}
3139

3240
tasks.named("bcUpgradeTest").configure {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ public abstract class AbstractRollingUpgradeTestCase extends ParameterizedRollin
3030
private static final ElasticsearchCluster cluster = buildCluster();
3131

3232
private static ElasticsearchCluster buildCluster() {
33-
// Note we need to use OLD_CLUSTER_VERSION directly here, as it may contain special values (e.g. 0.0.0) the ElasticsearchCluster
34-
// builder uses to lookup a particular distribution
3533
var cluster = ElasticsearchCluster.local()
3634
.distribution(DistributionType.DEFAULT)
37-
.version(OLD_CLUSTER_VERSION)
35+
.version(getOldClusterVersion())
36+
.detachedVersion(isOldClusterDetachedVersion())
3837
.nodes(NODE_NUM)
3938
.setting("path.repo", new Supplier<>() {
4039
@Override

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public abstract class AbstractRollingUpgradeWithSecurityTestCase extends Paramet
3535
private static final ElasticsearchCluster cluster = buildCluster();
3636

3737
private static ElasticsearchCluster buildCluster() {
38-
// Note we need to use OLD_CLUSTER_VERSION directly here, as it may contain special values (e.g. 0.0.0) the ElasticsearchCluster
39-
// builder uses to lookup a particular distribution
4038
var cluster = ElasticsearchCluster.local()
4139
.distribution(DistributionType.DEFAULT)
42-
.version(OLD_CLUSTER_VERSION)
40+
.version(getOldClusterVersion())
41+
.detachedVersion(isOldClusterDetachedVersion())
4342
.nodes(NODE_NUM)
4443
.user(USER, PASS)
4544
.setting("xpack.security.autoconfiguration.enabled", "false")

0 commit comments

Comments
 (0)