import reactor.util.retry.Retry;
import java.time.Duration;
-import java.util.stream.IntStream;
+import java.util.concurrent.ThreadLocalRandom;
@Slf4j
-public class TestClient
+public class TestClient implements Runnable
{
+ @Override
public void run()
{
- IntStream
- .rangeClosed(1,100)
- .mapToObj(i ->sendMessage(chatRoom, "Message #" + i))
- .map(result -> result
- .map(MessageTo::toString)
+ for (int i = 0; i < 100; i++)
+ {
+ String message = "Message #" + i;
+ for (ChatRoomInfoTo chatRoom : chatRooms)
+ {
+ sendMessage(chatRoom, message)
.retryWhen(Retry.fixedDelay(10, Duration.ofSeconds(1)))
- .block())
- .forEach(result -> log.info("{}", result));
+ .map(MessageTo::toString)
+ .subscribe(result -> log.info(
+ "{} sent message \"{}\" to {}",
+ user,
+ message,
+ chatRoom));
+ }
+ try
+ {
+ Thread.sleep(ThreadLocalRandom.current().nextLong(700, 1000));
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
}
private Mono<MessageTo> sendMessage(
private final WebClient webClient;
- private final ChatRoomInfoTo chatRoom;
+ private final ChatRoomInfoTo[] chatRooms;
private final User user;
- TestClient(Integer port, ChatRoomInfoTo chatRoom, String username)
+ TestClient(Integer port, ChatRoomInfoTo[] chatRooms, String username)
{
webClient = WebClient.create("http://localhost:" + port);
- this.chatRoom = chatRoom;
+ this.chatRooms = chatRooms;
user = new User(username);
}
}