WIP:wait
authorKai Moritz <kai@juplo.de>
Sat, 24 Feb 2024 17:57:12 +0000 (18:57 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 24 Feb 2024 17:57:12 +0000 (18:57 +0100)
src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java

index 2637b9e..df530b5 100644 (file)
@@ -4,8 +4,10 @@ import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
 import de.juplo.kafka.chat.backend.api.MessageTo;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
+import lombok.Setter;
 import lombok.ToString;
 import lombok.extern.slf4j.Slf4j;
+import org.awaitility.Awaitility;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -104,6 +106,28 @@ class KafkaHandoverIT extends AbstractHandoverIT
   {
     Integer port = HAPROXY.getMappedPort(8400);
     webClient = WebClient.create("http://localhost:" + port);
+
+    Awaitility
+        .await()
+        .until(() -> webClient
+            .get()
+            .uri("/actuator/health")
+            .exchangeToMono(response ->
+            {
+              if (response.statusCode().equals(HttpStatus.OK))
+              {
+                return response.bodyToMono(StatusTo.class);
+              }
+              else
+              {
+                return response.createError();
+              }
+            })
+            .map(StatusTo::getStatus)
+            .map(status -> status.equalsIgnoreCase("UP"))
+            .block());
+
+    log.info("Some backend was UP");
   }
 
   WebClient webClient;
@@ -254,4 +278,11 @@ class KafkaHandoverIT extends AbstractHandoverIT
       return ++serial;
     }
   }
+
+  @Getter
+  @Setter
+  static class StatusTo
+  {
+    String status;
+  }
 }