|
@@ -44,6 +44,7 @@ public class ServerUtils {
|
|
|
private static final long timeoutLength = TimeUnit.SECONDS.toMillis(
|
|
|
System.getProperty("tests.inVM") == null ? 30 : 10
|
|
|
);
|
|
|
+ private static final long requestInterval = TimeUnit.SECONDS.toMillis(5);
|
|
|
|
|
|
public static void waitForElasticsearch(Installation installation) throws IOException {
|
|
|
waitForElasticsearch("green", null, installation);
|
|
@@ -55,27 +56,37 @@ public class ServerUtils {
|
|
|
|
|
|
// we loop here rather than letting httpclient handle retries so we can measure the entire waiting time
|
|
|
final long startTime = System.currentTimeMillis();
|
|
|
+ long lastRequest = 0;
|
|
|
long timeElapsed = 0;
|
|
|
boolean started = false;
|
|
|
+ Throwable thrownException = null;
|
|
|
while (started == false && timeElapsed < waitTime) {
|
|
|
- try {
|
|
|
-
|
|
|
- final HttpResponse response = Request.Get("http://localhost:9200/_cluster/health")
|
|
|
- .connectTimeout((int) timeoutLength)
|
|
|
- .socketTimeout((int) timeoutLength)
|
|
|
- .execute()
|
|
|
- .returnResponse();
|
|
|
-
|
|
|
- if (response.getStatusLine().getStatusCode() >= 300) {
|
|
|
- final String statusLine = response.getStatusLine().toString();
|
|
|
- final String body = EntityUtils.toString(response.getEntity());
|
|
|
- throw new RuntimeException("Connecting to elasticsearch cluster health API failed:\n" + statusLine+ "\n" + body);
|
|
|
+ if (System.currentTimeMillis() - lastRequest > requestInterval) {
|
|
|
+ try {
|
|
|
+
|
|
|
+ final HttpResponse response = Request.Get("http://localhost:9200/_cluster/health")
|
|
|
+ .connectTimeout((int) timeoutLength)
|
|
|
+ .socketTimeout((int) timeoutLength)
|
|
|
+ .execute()
|
|
|
+ .returnResponse();
|
|
|
+
|
|
|
+ if (response.getStatusLine().getStatusCode() >= 300) {
|
|
|
+ final String statusLine = response.getStatusLine().toString();
|
|
|
+ final String body = EntityUtils.toString(response.getEntity());
|
|
|
+ throw new RuntimeException("Connecting to elasticsearch cluster health API failed:\n" + statusLine + "\n" + body);
|
|
|
+ }
|
|
|
+
|
|
|
+ started = true;
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ if (thrownException == null) {
|
|
|
+ thrownException = e;
|
|
|
+ } else {
|
|
|
+ thrownException.addSuppressed(e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- started = true;
|
|
|
-
|
|
|
- } catch (IOException e) {
|
|
|
- logger.info("Got exception when waiting for cluster health", e);
|
|
|
+ lastRequest = System.currentTimeMillis();
|
|
|
}
|
|
|
|
|
|
timeElapsed = System.currentTimeMillis() - startTime;
|
|
@@ -85,7 +96,8 @@ public class ServerUtils {
|
|
|
if (installation != null) {
|
|
|
FileUtils.logAllLogs(installation.logs, logger);
|
|
|
}
|
|
|
- throw new RuntimeException("Elasticsearch did not start");
|
|
|
+
|
|
|
+ throw new RuntimeException("Elasticsearch did not start", thrownException);
|
|
|
}
|
|
|
|
|
|
final String url;
|