From: Kai Moritz Date: Fri, 1 Mar 2024 13:05:11 +0000 (+0100) Subject: test: HandoverIT-POC - Each `TestWriter` writes only to one chat-room X-Git-Tag: rebase--2024-03-03--11-38~15 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=857a6ef855d663c32dc38e2e645b4d7c4d817466;p=demos%2Fkafka%2Fchat test: HandoverIT-POC - Each `TestWriter` writes only to one chat-room --- 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 0fd10d6e..41d9e49a 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -52,7 +52,7 @@ public abstract class AbstractHandoverIT .range(0, NUM_CLIENTS) .map(i -> new TestWriter( port, - chatRooms, + chatRooms[i % NUM_CHATROOMS], "user-" + Integer.toString(i))) .doOnNext(testClient -> executorService.execute(testClient)) .toStream() diff --git a/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java b/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java index 076376e8..929d84f9 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestWriter.java @@ -24,7 +24,7 @@ public class TestWriter implements Runnable for (int i = 0; running; i++) { String message = "Message #" + i; - for (ChatRoomInfoTo chatRoom : chatRooms) + try { sendMessage(chatRoom, message) .retryWhen(Retry.fixedDelay(10, Duration.ofSeconds(1))) @@ -39,9 +39,7 @@ public class TestWriter implements Runnable user, chatRoom, result)); - } - try - { + Thread.sleep(ThreadLocalRandom.current().nextLong(700, 1000)); } catch (Exception e) @@ -80,16 +78,16 @@ public class TestWriter implements Runnable private final WebClient webClient; - private final ChatRoomInfoTo[] chatRooms; + private final ChatRoomInfoTo chatRoom; private final User user; volatile boolean running = true; - TestWriter(Integer port, ChatRoomInfoTo[] chatRooms, String username) + TestWriter(Integer port, ChatRoomInfoTo chatRoom, String username) { webClient = WebClient.create("http://localhost:" + port); - this.chatRooms = chatRooms; + this.chatRoom = chatRoom; user = new User(username); } }