- ChatRoomInfoTo chatRoom = createChatRoom("bar").block();
- User user = new User("nerd");
- IntStream
- .rangeClosed(1,100)
- .mapToObj(i ->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)
- .doOnNext(message -> log.info("message: {}", message))
- .then()
- .block();
+ ChatRoomInfoTo[] chatRooms = Flux
+ .range(0, NUM_CHATROOMS)
+ .flatMap(i -> createChatRoom("room-" + i))
+ .toStream()
+ .toArray(size -> new ChatRoomInfoTo[size]);
+
+ int port = containers.haproxy.getMappedPort(8400);
+
+ CompletableFuture<Void>[] testWriterFutures = new CompletableFuture[NUM_CLIENTS];
+ TestWriter[] testWriters = new TestWriter[NUM_CLIENTS];
+ for (int i = 0; i < NUM_CLIENTS; i++)
+ {
+ TestWriter testWriter = new TestWriter(
+ port,
+ chatRooms[i % NUM_CHATROOMS],
+ "user-" + i);
+ testWriters[i] = testWriter;
+ testWriterFutures[i] = testWriter
+ .run()
+ .toFuture();
+ }
+
+ TestListener testListener = new TestListener(port, chatRooms);
+ CompletableFuture<Void> testListenerFuture = testListener
+ .run()
+ .toFuture();
+
+ log.info("Sleeping for 3 seconds...");
+ Thread.sleep(3000);
+
+ for (int i = 0; i < NUM_CLIENTS; i++)
+ {
+ testWriters[i].running = false;
+ testWriterFutures[i].join();
+ 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");