test: HandoverIT-POC - Clients are stopped after some time
[demos/kafka/chat] / src / test / java / de / juplo / kafka / chat / backend / TestClient.java
index fe39e44..524c297 100644 (file)
@@ -10,14 +10,16 @@ import reactor.core.publisher.Mono;
 import reactor.util.retry.Retry;
 
 import java.time.Duration;
+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++)
+    for (int i = 0; running; i++)
     {
       String message = "Message #" + i;
       for (ChatRoomInfoTo chatRoom : chatRooms)
@@ -31,6 +33,14 @@ public class TestClient
                 message,
                 chatRoom));
       }
+      try
+      {
+        Thread.sleep(ThreadLocalRandom.current().nextLong(700, 1000));
+      }
+      catch (Exception e)
+      {
+        throw new RuntimeException(e);
+      }
     }
   }
 
@@ -66,6 +76,8 @@ public class TestClient
   private final ChatRoomInfoTo[] chatRooms;
   private final User user;
 
+  volatile boolean running = true;
+
 
   TestClient(Integer port, ChatRoomInfoTo[] chatRooms, String username)
   {