Skip to content

Commit 0698dd0

Browse files
authored
Enabling testing against an external cluster (#30885)
Today when executing REST tests we take full responsibility for cluster configuration. Yet, there are use cases for brining your own cluster to the REST tests. This commit is a small first step towards that effort by skipping creating the cluster if the tests.rest.cluster and test.cluster system properties are set. In this case, the user takes full responsibility for configuring the cluster as expected by the REST tests. This step is by no means meant to be perfect or complete, only a baby step.
1 parent 35ffb8c commit 0698dd0

File tree

1 file changed

+39
-23
lines changed

1 file changed

+39
-23
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,44 @@ public class RestIntegTestTask extends DefaultTask {
7070
runner.parallelism = '1'
7171
runner.include('**/*IT.class')
7272
runner.systemProperty('tests.rest.load_packaged', 'false')
73-
// we pass all nodes to the rest cluster to allow the clients to round-robin between them
74-
// this is more realistic than just talking to a single node
75-
runner.systemProperty('tests.rest.cluster', "${-> nodes.collect{it.httpUri()}.join(",")}")
76-
runner.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
77-
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
78-
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
79-
// both as separate sysprops
80-
runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
81-
82-
// dump errors and warnings from cluster log on failure
83-
TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() {
84-
@Override
85-
void afterExecute(Task task, TaskState state) {
86-
if (state.failure != null) {
87-
for (NodeInfo nodeInfo : nodes) {
88-
printLogExcerpt(nodeInfo)
73+
74+
if (System.getProperty("tests.rest.cluster") == null) {
75+
if (System.getProperty("tests.cluster") != null) {
76+
throw new IllegalArgumentException("tests.rest.cluster and tests.cluster must both be null or non-null")
77+
}
78+
// we pass all nodes to the rest cluster to allow the clients to round-robin between them
79+
// this is more realistic than just talking to a single node
80+
runner.systemProperty('tests.rest.cluster', "${-> nodes.collect{it.httpUri()}.join(",")}")
81+
runner.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}")
82+
// TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin
83+
// that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass
84+
// both as separate sysprops
85+
runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}")
86+
87+
// dump errors and warnings from cluster log on failure
88+
TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() {
89+
@Override
90+
void afterExecute(Task task, TaskState state) {
91+
if (state.failure != null) {
92+
for (NodeInfo nodeInfo : nodes) {
93+
printLogExcerpt(nodeInfo)
94+
}
8995
}
9096
}
9197
}
92-
}
93-
runner.doFirst {
94-
project.gradle.addListener(logDumpListener)
95-
}
96-
runner.doLast {
97-
project.gradle.removeListener(logDumpListener)
98+
runner.doFirst {
99+
project.gradle.addListener(logDumpListener)
100+
}
101+
runner.doLast {
102+
project.gradle.removeListener(logDumpListener)
103+
}
104+
} else {
105+
if (System.getProperty("tests.cluster") == null) {
106+
throw new IllegalArgumentException("tests.rest.cluster and tests.cluster must both be null or non-null")
107+
}
108+
// an external cluster was specified and all responsibility for cluster configuration is taken by the user
109+
runner.systemProperty('tests.rest.cluster', System.getProperty("tests.rest.cluster"))
110+
runner.systemProperty('test.cluster', System.getProperty("tests.cluster"))
98111
}
99112

100113
// copy the rest spec/tests into the test resources
@@ -109,7 +122,10 @@ public class RestIntegTestTask extends DefaultTask {
109122
clusterInit.enabled = false
110123
return // no need to add cluster formation tasks if the task won't run!
111124
}
112-
nodes = ClusterFormationTasks.setup(project, "${name}Cluster", runner, clusterConfig)
125+
// only create the cluster if needed as otherwise an external cluster to use was specified
126+
if (System.getProperty("tests.rest.cluster") == null) {
127+
nodes = ClusterFormationTasks.setup(project, "${name}Cluster", runner, clusterConfig)
128+
}
113129
super.dependsOn(runner.finalizedBy)
114130
}
115131
}

0 commit comments

Comments
 (0)