WIP:test: HandoverIT-POC - splitted up code into smaller classes -- ALIGN
authorKai Moritz <kai@juplo.de>
Tue, 27 Feb 2024 10:48:26 +0000 (11:48 +0100)
committerKai Moritz <kai@juplo.de>
Tue, 27 Feb 2024 10:54:03 +0000 (11:54 +0100)
src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java
src/test/java/de/juplo/kafka/chat/backend/TestClient.java

index 267a951..1eaf59a 100644 (file)
@@ -1,6 +1,7 @@
 package de.juplo.kafka.chat.backend;
 
 import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
+import de.juplo.kafka.chat.backend.api.MessageTo;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -12,6 +13,10 @@ import org.springframework.web.reactive.function.client.WebClient;
 import org.testcontainers.junit.jupiter.Testcontainers;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
+
+import java.time.Duration;
+import java.util.stream.IntStream;
 
 
 @Testcontainers
@@ -34,6 +39,17 @@ public abstract class HandoverIT
   void test() throws InterruptedException
   {
     ChatRoomInfoTo chatRoom = createChatRoom("bar").block();
+    TestClient testClient = new TestClient(
+        containers.haproxy.getMappedPort(8400),
+        "nerd");
+    IntStream
+        .rangeClosed(1,100)
+        .mapToObj(i ->testClient.sendMessage(chatRoom, user, "Message #" + i))
+        .map(result -> result
+            .map(MessageTo::toString)
+            .retryWhen(Retry.fixedDelay(10, Duration.ofSeconds(1)))
+            .block())
+        .forEach(result -> log.info("{}", result));
 
     receiveMessages(chatRoom)
         .take(100)
index 60a3e81..dc2ba38 100644 (file)
@@ -3,12 +3,9 @@ package de.juplo.kafka.chat.backend;
 import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
 import de.juplo.kafka.chat.backend.api.MessageTo;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.core.ParameterizedTypeReference;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
-import org.springframework.http.codec.ServerSentEvent;
 import org.springframework.web.reactive.function.client.WebClient;
-import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 
@@ -17,7 +14,6 @@ public class TestClient
 {
   Mono<MessageTo> sendMessage(
       ChatRoomInfoTo chatRoom,
-      User user,
       String message)
   {
     return webClient
@@ -45,10 +41,12 @@ public class TestClient
 
 
   private final WebClient webClient;
+  private final User user;
 
 
-  TestClient(Integer port)
+  TestClient(Integer port, String username)
   {
     webClient = WebClient.create("http://localhost:" + port);
+    user = new User(username);
   }
 }