diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy index 242ed45eee86e..2ac0e22a82bc5 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy @@ -70,31 +70,44 @@ public class RestIntegTestTask extends DefaultTask { runner.parallelism = '1' runner.include('**/*IT.class') runner.systemProperty('tests.rest.load_packaged', 'false') - // we pass all nodes to the rest cluster to allow the clients to round-robin between them - // this is more realistic than just talking to a single node - runner.systemProperty('tests.rest.cluster', "${-> nodes.collect{it.httpUri()}.join(",")}") - runner.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}") - // TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin - // that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass - // both as separate sysprops - runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}") - - // dump errors and warnings from cluster log on failure - TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() { - @Override - void afterExecute(Task task, TaskState state) { - if (state.failure != null) { - for (NodeInfo nodeInfo : nodes) { - printLogExcerpt(nodeInfo) + + if (System.getProperty("tests.rest.cluster") == null) { + if (System.getProperty("tests.cluster") != null) { + throw new IllegalArgumentException("tests.rest.cluster and tests.cluster must both be null or non-null") + } + // we pass all nodes to the rest cluster to allow the clients to round-robin between them + // this is more realistic than just talking to a single node + runner.systemProperty('tests.rest.cluster', "${-> nodes.collect{it.httpUri()}.join(",")}") + runner.systemProperty('tests.config.dir', "${-> nodes[0].pathConf}") + // TODO: our "client" qa tests currently use the rest-test plugin. instead they should have their own plugin + // that sets up the test cluster and passes this transport uri instead of http uri. Until then, we pass + // both as separate sysprops + runner.systemProperty('tests.cluster', "${-> nodes[0].transportUri()}") + + // dump errors and warnings from cluster log on failure + TaskExecutionAdapter logDumpListener = new TaskExecutionAdapter() { + @Override + void afterExecute(Task task, TaskState state) { + if (state.failure != null) { + for (NodeInfo nodeInfo : nodes) { + printLogExcerpt(nodeInfo) + } } } } - } - runner.doFirst { - project.gradle.addListener(logDumpListener) - } - runner.doLast { - project.gradle.removeListener(logDumpListener) + runner.doFirst { + project.gradle.addListener(logDumpListener) + } + runner.doLast { + project.gradle.removeListener(logDumpListener) + } + } else { + if (System.getProperty("tests.cluster") == null) { + throw new IllegalArgumentException("tests.rest.cluster and tests.cluster must both be null or non-null") + } + // an external cluster was specified and all responsibility for cluster configuration is taken by the user + runner.systemProperty('tests.rest.cluster', System.getProperty("tests.rest.cluster")) + runner.systemProperty('test.cluster', System.getProperty("tests.cluster")) } // copy the rest spec/tests into the test resources @@ -109,7 +122,10 @@ public class RestIntegTestTask extends DefaultTask { clusterInit.enabled = false return // no need to add cluster formation tasks if the task won't run! } - nodes = ClusterFormationTasks.setup(project, "${name}Cluster", runner, clusterConfig) + // only create the cluster if needed as otherwise an external cluster to use was specified + if (System.getProperty("tests.rest.cluster") == null) { + nodes = ClusterFormationTasks.setup(project, "${name}Cluster", runner, clusterConfig) + } super.dependsOn(runner.finalizedBy) } }