浏览代码

Reduce packaging test log output and introduce ready request interval (#48324)

Mark Vieira 6 年之前
父节点
当前提交
209a1b7ce9
共有 1 个文件被更改,包括 29 次插入17 次删除
  1. 29 17
      qa/os/src/test/java/org/elasticsearch/packaging/util/ServerUtils.java

+ 29 - 17
qa/os/src/test/java/org/elasticsearch/packaging/util/ServerUtils.java

@@ -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;