From cf2acfc33946b968d6fac8ec411a2f270cb04f61 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 28 Feb 2024 09:59:20 +0100 Subject: [PATCH] test: HandoverIT-POC - Running multiple clients in parallel --- .../chat/backend/AbstractHandoverIT.java | 22 ++++++++++++++----- .../juplo/kafka/chat/backend/TestClient.java | 3 ++- 2 files changed, 19 insertions(+), 6 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 900a7c39..a2803479 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -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> 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) 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 0461970f..964a06ba 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/TestClient.java +++ b/src/test/java/de/juplo/kafka/chat/backend/TestClient.java @@ -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++) -- 2.20.1