From: Kai Moritz Date: Tue, 27 Feb 2024 10:48:26 +0000 (+0100) Subject: WIP:test: HandoverIT-POC - splitted up code into smaller classes -- ALIGN X-Git-Tag: rebase--2024-02-27--11-55~2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=e288b997e7b05e9944f0066e5a33cb04236c6977;p=demos%2Fkafka%2Fchat WIP:test: HandoverIT-POC - splitted up code into smaller classes -- ALIGN --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java index 267a9519..1eaf59a4 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -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) diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestClient.java b/src/test/java/de/juplo/kafka/chat/backend/TestClient.java index 60a3e813..dc2ba389 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestClient.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestClient.java @@ -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 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); } }