Shekharrajak commented on code in PR #19564:
URL: https://github.com/apache/druid/pull/19564#discussion_r3366823915


##########
embedded-tests/src/test/java/org/apache/druid/testing/embedded/consul/ConsulClusterResource.java:
##########
@@ -106,6 +123,96 @@ protected GenericContainer<?> createContainer()
     }
   }
 
+  private void waitForConsulApi()
+  {
+    final long deadline = System.nanoTime() + READINESS_TIMEOUT.toNanos();
+    final HttpClient httpClient;
+    Exception lastException = null;
+
+    try {
+      httpClient = createHttpClient();
+    }
+    catch (Exception e) {
+      throw new RuntimeException("Failed to create Consul readiness client", 
e);
+    }
+
+    while (System.nanoTime() < deadline) {
+      try {
+        final HttpRequest request = 
HttpRequest.newBuilder(getHttpUri("/v1/status/leader"))
+                                               .timeout(Duration.ofSeconds(5))
+                                               .GET()
+                                               .build();
+        final HttpResponse<String> response = httpClient.send(request, 
HttpResponse.BodyHandlers.ofString());
+        if (response.statusCode() == 200 && response.body() != null && 
!response.body().trim().isEmpty()) {
+          log.info("Consul API is ready at [%s].", 
getHttpUri("/v1/status/leader"));
+          return;
+        }
+        lastException = new RuntimeException(
+            StringUtils.format(
+                "Consul leader endpoint returned status[%d] body[%s]",
+                response.statusCode(),
+                response.body()
+            )
+        );
+      }
+      catch (Exception e) {
+        lastException = e;
+      }
+
+      try {
+        Thread.sleep(READINESS_RETRY_DELAY.toMillis());
+      }
+      catch (InterruptedException e) {
+        Thread.currentThread().interrupt();
+        throw new RuntimeException("Interrupted while waiting for Consul API 
readiness", e);
+      }
+    }
+
+    throw new RuntimeException(

Review Comment:
   out side the while loop .
   
   we kept retrying until READINESS_TIMEOUT expired
     and Consul never became ready



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to