Skip to content

Commit d0edfc8

Browse files
committed
Bwc testclusters all (elastic#46265)
Convert all bwc projects to testclusters
1 parent a032f9b commit d0edfc8

File tree

17 files changed

+567
-916
lines changed

17 files changed

+567
-916
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,17 @@ public File getAuditLog() {
732732

733733
@Override
734734
public synchronized void stop(boolean tailLogs) {
735+
logToProcessStdout("Stopping node");
736+
try {
737+
if (Files.exists(httpPortsFile)) {
738+
Files.delete(httpPortsFile);
739+
}
740+
if (Files.exists(transportPortFile)) {
741+
Files.delete(transportPortFile);
742+
}
743+
} catch (IOException e) {
744+
throw new UncheckedIOException(e);
745+
}
735746
if (esProcess == null && tailLogs) {
736747
// This is a special case. If start() throws an exception the plugin will still call stop
737748
// Another exception here would eat the orriginal.
@@ -894,6 +905,8 @@ private void waitForProcessToExit(ProcessHandle processHandle) {
894905

895906
private void createWorkingDir(Path distroExtractDir) throws IOException {
896907
syncWithLinks(distroExtractDir, distroDir);
908+
// Start configuration from scratch in case of a restart
909+
project.delete(configFile.getParent());
897910
Files.createDirectories(configFile.getParent());
898911
Files.createDirectories(confPathRepo);
899912
Files.createDirectories(confPathData);

buildSrc/src/minimumRuntime/java/org/elasticsearch/gradle/VersionProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ public static String getElasticsearch() {
1515
return elasticsearch;
1616
}
1717

18+
public static Version getElasticsearchVersion() {
19+
return Version.fromString(elasticsearch);
20+
}
21+
1822
public static String getLucene() {
1923
return lucene;
2024
}

qa/full-cluster-restart/build.gradle

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
import org.elasticsearch.gradle.Version
2222
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
2323

24-
apply plugin: 'elasticsearch.standalone-test'
2524
apply plugin: 'elasticsearch.testclusters'
25+
apply plugin: 'elasticsearch.standalone-test'
2626

27-
// This is a top level task which we will add dependencies to below.
28-
// It is a single task that can be used to backcompat tests against all versions.
29-
task bwcTest {
27+
tasks.register("bwcTest") {
3028
description = 'Runs backwards compatibility tests.'
3129
group = 'verification'
3230
}
@@ -81,9 +79,6 @@ for (Version bwcVersion : bwcVersions.indexCompatible) {
8179
}
8280
}
8381

84-
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
85-
86-
// basic integ tests includes testing bwc against the most recent version
8782
task bwcTestSnapshots {
8883
if (project.bwc_tests_enabled) {
8984
for (final def version : bwcVersions.unreleasedIndexCompatible) {
@@ -106,3 +101,5 @@ task testJar(type: Jar) {
106101
artifacts {
107102
testArtifacts testJar
108103
}
104+
105+
test.enabled = false

qa/mixed-cluster/build.gradle

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,89 @@
1717
* under the License.
1818
*/
1919

20-
import org.elasticsearch.gradle.test.RestIntegTestTask
2120
import org.elasticsearch.gradle.Version
21+
import org.elasticsearch.gradle.VersionProperties
22+
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
2223

24+
apply plugin: 'elasticsearch.testclusters'
2325
apply plugin: 'elasticsearch.standalone-test'
2426

25-
// This is a top level task which we will add dependencies to below.
26-
// It is a single task that can be used to backcompat tests against all versions.
27-
task bwcTest {
27+
tasks.register("bwcTest") {
2828
description = 'Runs backwards compatibility tests.'
2929
group = 'verification'
3030
}
3131

32-
for (Version version : bwcVersions.wireCompatible) {
33-
String baseName = "v${version}"
32+
configurations {
33+
restSpec
34+
}
3435

35-
Task mixedClusterTest = tasks.create(name: "${baseName}#mixedClusterTest", type: RestIntegTestTask) {
36-
mustRunAfter(precommit)
37-
includePackaged = true
36+
dependencies {
37+
restSpec project(':rest-api-spec')
38+
}
39+
40+
processTestResources {
41+
from ({ zipTree(configurations.restSpec.singleFile) })
42+
dependsOn configurations.restSpec
43+
}
44+
45+
for (Version bwcVersion : bwcVersions.wireCompatible) {
46+
if (bwcVersion == VersionProperties.getElasticsearchVersion()) {
47+
// Not really a mixed cluster
48+
continue ;
3849
}
3950

51+
String baseName = "v${bwcVersion}"
52+
4053
/* This project runs the core REST tests against a 4 node cluster where two of
4154
the nodes has a different minor. */
42-
Object extension = extensions.findByName("${baseName}#mixedClusterTestCluster")
43-
configure(extension) {
44-
numNodes = 4
45-
numBwcNodes = 2
46-
bwcVersion = version
47-
}
55+
testClusters {
56+
"${baseName}" {
57+
versions = [ bwcVersion.toString(), project.version ]
58+
numberOfNodes = 4
4859

49-
Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {
50-
dependsOn = [mixedClusterTest]
60+
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
61+
javaHome = project.file(project.ext.runtimeJavaHome)
62+
}
5163
}
5264

53-
if (project.bwc_tests_enabled) {
54-
bwcTest.dependsOn(versionBwcTest)
65+
tasks.register("${baseName}#mixedClusterTest", RestTestRunnerTask) {
66+
useCluster testClusters."${baseName}"
67+
mustRunAfter(precommit)
68+
doFirst {
69+
project.delete("${buildDir}/cluster/shared/repo/${baseName}")
70+
// Getting the endpoints causes a wait for the cluster
71+
println "Test cluster endpoints are: ${-> testClusters."${baseName}".allHttpSocketURI.join(",") }"
72+
println "Upgrading one node to create a mixed cluster"
73+
testClusters."${baseName}".nextNodeToNextVersion()
74+
// Getting the endpoints causes a wait for the cluster
75+
println "Upgrade complete, endpoints are: ${-> testClusters."${baseName}".allHttpSocketURI.join(",") }"
76+
println "Upgrading another node to create a mixed cluster"
77+
testClusters."${baseName}".nextNodeToNextVersion()
78+
79+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
80+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
81+
}
82+
systemProperty 'tests.path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
83+
onlyIf { project.bwc_tests_enabled }
5584
}
5685

57-
tasks.getByName("${baseName}#mixedClusterTestRunner").configure {
58-
/* To support taking index snapshots, we have to set path.repo setting */
59-
systemProperty 'tests.path.repo', new File(buildDir, "cluster/shared/repo")
86+
tasks.register("${baseName}#bwcTest") {
87+
dependsOn "${baseName}#mixedClusterTest"
6088
}
61-
}
6289

63-
test.enabled = false // no unit tests for rolling upgrades, only the rest integration test
90+
tasks.bwcTest.dependsOn "${baseName}#bwcTest"
91+
}
6492

65-
// basic integ tests includes testing bwc against the most recent version
6693
task bwcTestSnapshots {
6794
if (project.bwc_tests_enabled) {
68-
for (final def version : bwcVersions.unreleasedWireCompatible) {
69-
dependsOn "v${version}#bwcTest"
95+
for (Version bwcVersion : bwcVersions.unreleasedWireCompatible) {
96+
if (bwcVersion != VersionProperties.getElasticsearchVersion()) {
97+
dependsOn "v${bwcVersion}#bwcTest"
98+
}
7099
}
71100
}
72101
}
73102

74103
check.dependsOn(bwcTestSnapshots)
104+
105+
test.enabled = false

qa/rolling-upgrade/build.gradle

Lines changed: 68 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
import org.elasticsearch.gradle.test.RestIntegTestTask
2120
import org.elasticsearch.gradle.Version
21+
import org.elasticsearch.gradle.testclusters.RestTestRunnerTask
2222

23+
apply plugin: 'elasticsearch.testclusters'
2324
apply plugin: 'elasticsearch.standalone-test'
2425

2526
// This is a top level task which we will add dependencies to below.
@@ -29,117 +30,105 @@ task bwcTest {
2930
group = 'verification'
3031
}
3132

32-
for (Version version : bwcVersions.wireCompatible) {
33+
configurations {
34+
restSpec
35+
}
36+
37+
dependencies {
38+
restSpec project(':rest-api-spec')
39+
}
40+
41+
processTestResources {
42+
from ({ zipTree(configurations.restSpec.singleFile) }) {
43+
include 'rest-api-spec/api/**'
44+
}
45+
dependsOn configurations.restSpec
46+
}
47+
48+
for (Version bwcVersion : bwcVersions.wireCompatible) {
3349
/*
3450
* The goal here is to:
3551
* <ul>
3652
* <li>start three nodes on the old version
3753
* <li>run tests with systemProperty 'tests.rest.suite', 'old_cluster'
38-
* <li>shut down one node
39-
* <li>start a node with the new version
54+
* <li>upgrade one node
4055
* <li>run tests with systemProperty 'tests.rest.suite', 'mixed_cluster'
41-
* <li>shut down one node on the old version
42-
* <li>start a node with the new version
56+
* <li>upgrade one more node
4357
* <li>run tests with systemProperty 'tests.rest.suite', 'mixed_cluster' again
44-
* <li>shut down the last node with the old version
45-
* <li>start a node with the new version
58+
* <li>updgrade the last node
4659
* <li>run tests with systemProperty 'tests.rest.suite', 'upgraded_cluster'
47-
* <li>shut down the entire cluster
4860
* </ul>
49-
*
50-
* Be careful: gradle dry run spits out tasks in the wrong order but,
51-
* strangely, running the tasks works properly.
5261
*/
53-
String baseName = "v${version}"
62+
String baseName = "v${bwcVersion}"
5463

55-
Task oldClusterTest = tasks.create(name: "${baseName}#oldClusterTest", type: RestIntegTestTask) {
56-
mustRunAfter(precommit)
57-
}
64+
testClusters {
65+
"${baseName}" {
66+
versions = [ bwcVersion.toString(), project.version ]
67+
numberOfNodes = 3
5868

59-
configure(extensions.findByName("${baseName}#oldClusterTestCluster")) {
60-
bwcVersion = version
61-
numBwcNodes = 3
62-
numNodes = 3
63-
clusterName = 'rolling-upgrade'
64-
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
65-
if (version.onOrAfter('5.3.0')) {
69+
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
70+
setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}"
6671
setting 'http.content_type.required', 'true'
72+
javaHome = project.file(project.ext.runtimeJavaHome)
6773
}
6874
}
6975

70-
Task oldClusterTestRunner = tasks.getByName("${baseName}#oldClusterTestRunner")
71-
oldClusterTestRunner.configure {
76+
tasks.register("${baseName}#oldClusterTest", RestTestRunnerTask) {
77+
dependsOn processTestResources
78+
useCluster testClusters."${baseName}"
79+
mustRunAfter(precommit)
80+
doFirst {
81+
project.delete("${buildDir}/cluster/shared/repo/${baseName}")
82+
}
7283
systemProperty 'tests.rest.suite', 'old_cluster'
73-
systemProperty 'tests.upgrade_from_version', version.toString().replace('-SNAPSHOT', '')
84+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
85+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
7486
}
7587

76-
Closure configureUpgradeCluster = {String name, Task lastRunner, int stopNode, Closure getOtherUnicastHostAddresses ->
77-
configure(extensions.findByName("${baseName}#${name}")) {
78-
dependsOn lastRunner, "${baseName}#oldClusterTestCluster#node${stopNode}.stop"
79-
clusterName = 'rolling-upgrade'
80-
otherUnicastHostAddresses = { getOtherUnicastHostAddresses() }
81-
autoSetInitialMasterNodes = false
82-
/* Override the data directory so the new node always gets the node we
83-
* just stopped's data directory. */
84-
dataDir = { nodeNumber -> oldClusterTest.nodes[stopNode].dataDir }
85-
setting 'repositories.url.allowed_urls', 'http://snapshot.test*'
86-
setting 'node.name', "upgraded-node-${stopNode}"
88+
tasks.register("${baseName}#oneThirdUpgradedTest", RestTestRunnerTask) {
89+
dependsOn "${baseName}#oldClusterTest"
90+
useCluster testClusters."${baseName}"
91+
doFirst {
92+
testClusters."${baseName}".nextNodeToNextVersion()
8793
}
88-
}
89-
90-
Task oneThirdUpgradedTest = tasks.create(name: "${baseName}#oneThirdUpgradedTest", type: RestIntegTestTask)
91-
92-
configureUpgradeCluster("oneThirdUpgradedTestCluster", oldClusterTestRunner, 0,
93-
// Use all running nodes as seed nodes so there is no race between pinging and the tests
94-
{ [oldClusterTest.nodes.get(1).transportUri(), oldClusterTest.nodes.get(2).transportUri()] })
95-
96-
Task oneThirdUpgradedTestRunner = tasks.getByName("${baseName}#oneThirdUpgradedTestRunner")
97-
oneThirdUpgradedTestRunner.configure {
9894
systemProperty 'tests.rest.suite', 'mixed_cluster'
9995
systemProperty 'tests.upgrade_from_version', version.toString()
10096
systemProperty 'tests.first_round', 'true'
101-
finalizedBy "${baseName}#oldClusterTestCluster#node1.stop"
97+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
98+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
10299
}
103100

104-
Task twoThirdsUpgradedTest = tasks.create(name: "${baseName}#twoThirdsUpgradedTest", type: RestIntegTestTask)
105-
106-
configureUpgradeCluster("twoThirdsUpgradedTestCluster", oneThirdUpgradedTestRunner, 1,
107-
// Use all running nodes as seed nodes so there is no race between pinging and the tests
108-
{ [oldClusterTest.nodes.get(2).transportUri(), oneThirdUpgradedTest.nodes.get(0).transportUri()] })
109-
110-
Task twoThirdsUpgradedTestRunner = tasks.getByName("${baseName}#twoThirdsUpgradedTestRunner")
111-
twoThirdsUpgradedTestRunner.configure {
101+
tasks.register("${baseName}#twoThirdsUpgradedTest", RestTestRunnerTask) {
102+
dependsOn "${baseName}#oneThirdUpgradedTest"
103+
useCluster testClusters."${baseName}"
104+
doFirst {
105+
testClusters."${baseName}".nextNodeToNextVersion()
106+
}
112107
systemProperty 'tests.rest.suite', 'mixed_cluster'
113108
systemProperty 'tests.upgrade_from_version', version.toString()
114109
systemProperty 'tests.first_round', 'false'
115-
finalizedBy "${baseName}#oldClusterTestCluster#node2.stop"
110+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
111+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
116112
}
117113

118-
Task upgradedClusterTest = tasks.create(name: "${baseName}#upgradedClusterTest", type: RestIntegTestTask)
119-
120-
configureUpgradeCluster("upgradedClusterTestCluster", twoThirdsUpgradedTestRunner, 2,
121-
// Use all running nodes as seed nodes so there is no race between pinging and the tests
122-
{ [oneThirdUpgradedTest.nodes.get(0).transportUri(), twoThirdsUpgradedTest.nodes.get(0).transportUri()] })
123-
124-
Task upgradedClusterTestRunner = tasks.getByName("${baseName}#upgradedClusterTestRunner")
125-
upgradedClusterTestRunner.configure {
114+
tasks.register("${baseName}#upgradedClusterTest", RestTestRunnerTask) {
115+
dependsOn "${baseName}#twoThirdsUpgradedTest"
116+
doFirst {
117+
testClusters."${baseName}".nextNodeToNextVersion()
118+
}
119+
useCluster testClusters."${baseName}"
126120
systemProperty 'tests.rest.suite', 'upgraded_cluster'
127-
systemProperty 'tests.upgrade_from_version', version.toString()
128-
/*
129-
* Force stopping all the upgraded nodes after the test runner
130-
* so they are alive during the test.
131-
*/
132-
finalizedBy "${baseName}#oneThirdUpgradedTestCluster#stop"
133-
finalizedBy "${baseName}#twoThirdsUpgradedTestCluster#stop"
134-
}
135121

136-
Task versionBwcTest = tasks.create(name: "${baseName}#bwcTest") {
137-
enabled = project.bwc_tests_enabled
138-
dependsOn = [upgradedClusterTest]
122+
nonInputProperties.systemProperty('tests.rest.cluster', "${-> testClusters."${baseName}".allHttpSocketURI.join(",") }")
123+
nonInputProperties.systemProperty('tests.clustername', "${-> testClusters."${baseName}".getName() }")
139124
}
140125

141126
if (project.bwc_tests_enabled) {
142-
bwcTest.dependsOn(versionBwcTest)
127+
bwcTest.dependsOn(
128+
tasks.register("${baseName}#bwcTest") {
129+
dependsOn tasks.named("${baseName}#upgradedClusterTest")
130+
}
131+
)
143132
}
144133
}
145134

@@ -155,3 +144,5 @@ task bwcTestSnapshots {
155144
}
156145

157146
check.dependsOn(bwcTestSnapshots)
147+
148+
test.enabled = false

0 commit comments

Comments
 (0)