From abf2e3be18f2744022ae9e4a1165808028859437 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 3 Mar 2024 10:20:11 +0100 Subject: [PATCH] test: HandoverIT-POC - fix for the blocking wait for `TestListener` * Droped the waiting for `TestListener` alltogehter. * The waiting can be droped, because waiting for the `TestWriter`-instances ensures, that all messages are send (and therefore very likely received) --- .../chat/backend/AbstractHandoverIT.java | 15 +++++-------- .../kafka/chat/backend/TestListener.java | 22 +++---------------- 2 files changed, 9 insertions(+), 28 deletions(-) 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 bbb2fbb5..dff9b563 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -57,9 +57,11 @@ public abstract class AbstractHandoverIT } TestListener testListener = new TestListener(port, chatRooms); - CompletableFuture testListenerFuture = testListener + testListener .run() - .toFuture(); + .subscribe(message -> log.info( + "Received message: {}", + message)); log.info("Sleeping for 3 seconds..."); Thread.sleep(3000); @@ -71,13 +73,8 @@ public abstract class AbstractHandoverIT log.info("Joined TestWriter {}", testWriters[i].user); } - - log.info("Sleeping for 3 seconds..."); - Thread.sleep(3000); - log.info("Joining TestListener..."); - testListener.running = false; - testListenerFuture.join(); - log.info("Joined TestListener"); + // Yield the work, so that the last messages can be received + Thread.sleep(500); } Mono createChatRoom(String name) diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestListener.java b/src/test/java/de/juplo/kafka/chat/backend/TestListener.java index 35f65acd..78d4c82f 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestListener.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestListener.java @@ -12,7 +12,6 @@ import org.springframework.http.codec.ServerSentEvent; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.core.scheduler.Schedulers; import java.util.*; @@ -23,7 +22,7 @@ public class TestListener static final ParameterizedTypeReference> SSE_TYPE = new ParameterizedTypeReference<>() {}; - public Mono run() + public Flux run() { return Flux .fromArray(chatRooms) @@ -44,21 +43,8 @@ public class TestListener return Mono.error(e); } }) - .doOnNext(message -> - { - list.add(message); - log.info( - "Received a message from chat-room {}: {}", - chatRoom.getName(), - message); - }); - }) - .limitRate(10) - .takeUntil(message -> !running) - .doOnComplete(() -> log.info("TestListener is done")) - .parallel(chatRooms.length) - .runOn(Schedulers.parallel()) - .then(); + .doOnNext(message -> list.add(message)); + }); } Flux> receiveMessages(ChatRoomInfoTo chatRoom) @@ -80,8 +66,6 @@ public class TestListener final Map> receivedMessages = new HashMap<>(); - volatile boolean running = true; - TestListener(Integer port, ChatRoomInfoTo[] chatRooms) { -- 2.20.1