test: HandoverIT-POC - Running multiple clients in parallel
authorKai Moritz <kai@juplo.de>
Wed, 28 Feb 2024 08:59:20 +0000 (09:59 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 22 Mar 2024 10:15:56 +0000 (11:15 +0100)
src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java
src/test/java/de/juplo/kafka/chat/backend/TestClient.java

index 900a7c3..a280347 100644 (file)
@@ -13,6 +13,10 @@ import org.testcontainers.junit.jupiter.Testcontainers;
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.stream.IntStream;
+
 
 @Testcontainers
 @Slf4j
@@ -20,9 +24,11 @@ public abstract class AbstractHandoverIT
 {
   static final ParameterizedTypeReference<ServerSentEvent<String>> SSE_TYPE = new ParameterizedTypeReference<>() {};
   static final int NUM_CHATROOMS = 23;
+  static final int NUM_CLIENTS = 17;
 
 
   private final AbstractHandoverITContainers containers;
+  private final ExecutorService executorService = Executors.newFixedThreadPool(NUM_CLIENTS);
 
 
   AbstractHandoverIT(AbstractHandoverITContainers containers)
@@ -40,11 +46,17 @@ public abstract class AbstractHandoverIT
         .toStream()
         .toArray(size -> new ChatRoomInfoTo[size]);
 
-    TestClient testClient = new TestClient(
-        containers.haproxy.getMappedPort(8400),
-        chatRooms,
-        "nerd");
-    testClient.run();
+    TestClient[] testClients = Flux
+        .fromStream(IntStream.range(0, NUM_CLIENTS).mapToObj(i -> Integer.toString(i)))
+        .map(i -> new TestClient(
+            containers.haproxy.getMappedPort(8400),
+            chatRooms,
+            i))
+        .doOnNext(testClient -> executorService.execute(testClient))
+        .toStream()
+        .toArray(size -> new TestClient[size]);
+
+    Thread.sleep(2000);
 
     Flux
         .fromArray(chatRooms)
index 0461970..964a06b 100644 (file)
@@ -14,8 +14,9 @@ import java.util.concurrent.ThreadLocalRandom;
 
 
 @Slf4j
-public class TestClient
+public class TestClient implements Runnable
 {
+  @Override
   public void run()
   {
     for (int i = 0; i < 100; i++)