diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java index 9862f28ef6d..a47099ce5a5 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/RunTask.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.gradle.testclusters; +import org.gradle.api.GradleException; import org.gradle.api.logging.Logger; import org.gradle.api.logging.Logging; import org.gradle.api.tasks.Input; @@ -34,6 +35,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.BooleanSupplier; import java.util.function.Function; import java.util.stream.Collectors; @@ -131,11 +133,13 @@ public class RunTask extends DefaultTestClustersTask { @TaskAction public void runAndWait() throws IOException { List toRead = new ArrayList<>(); + List aliveChecks = new ArrayList<>(); try { for (ElasticsearchCluster cluster : getClusters()) { for (ElasticsearchNode node : cluster.getNodes()) { BufferedReader reader = Files.newBufferedReader(node.getEsStdoutFile()); toRead.add(reader); + aliveChecks.add(node::isProcessAlive); } } @@ -148,6 +152,10 @@ public class RunTask extends DefaultTestClustersTask { } } + if (aliveChecks.stream().allMatch(BooleanSupplier::getAsBoolean) == false) { + throw new GradleException("Elasticsearch cluster died"); + } + if (readData == false) { // no data was ready to be consumed and rather than continuously spinning, pause // for some time to avoid excessive CPU usage. Ideally we would use the JDK