* The backend-containers are explicitly started during the test.
* When a backend is started, it is waited for, that the started backend
reportes its status as `UP`, _and_, that alle writers are again able to
send messages, afterwards.
@Test
void test() throws InterruptedException
{
+ log.info("Starting backend-1...");
+ containers.startBackend(containers.backend1, new TestWriter[0]);
+ log.info("backend-1 started!");
+
ChatRoomInfoTo[] chatRooms = Flux
.range(0, NUM_CHATROOMS)
.flatMap(i -> createChatRoom("room-" + i))
{
setUpExtra();
haproxy.start();
- backend1.start();
- // backend2.start();
- // backend3.start();
+ }
+
+ void startBackend(
+ GenericContainer backend,
+ TestWriter[] testWriters)
+ {
+ backend.start();
+
+ int[] numSentMessages = Arrays
+ .stream(testWriters)
+ .mapToInt(testWriter -> testWriter.getNumSentMessages())
+ .toArray();
Awaitility
.await()
- .atMost(Duration.ofMinutes(10))
+ .atMost(Duration.ofSeconds(30))
.until(() -> WebClient
- .create("http://localhost:" + backend1.getMappedPort(8080))
+ .create("http://localhost:" + backend.getMappedPort(8080))
.get()
.uri("/actuator/health")
.exchangeToMono(response ->
.withSignal("HUP")
.exec();
-
Awaitility
.await()
- .atMost(Duration.ofMinutes(10))
+ .atMost(Duration.ofSeconds(30))
.until(() -> WebClient
.create("http://localhost:" + haproxy.getMappedPort(8400))
.get()
}
})
.block());
+
+ Awaitility
+ .await()
+ .atMost(Duration.ofSeconds(30))
+ .until(() ->
+ {
+ for (int i = 0; i < testWriters.length; i++)
+ {
+ TestWriter testWriter = testWriters[i];
+ int sentTotal = testWriter.getNumSentMessages();
+ if (sentTotal == numSentMessages[i])
+ {
+ log.info(
+ "No progress for {}: sent-before={}, sent-total={}",
+ testWriter,
+ numSentMessages[i],
+ sentTotal);
+ return false;
+ }
+ }
+
+ return true;
+ });
}
abstract String[] getBackendCommand();
import de.juplo.kafka.chat.backend.api.ChatRoomInfoTo;
import de.juplo.kafka.chat.backend.api.MessageTo;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
.delayElements(Duration.ofMillis(ThreadLocalRandom.current().nextLong(500, 1500)))
.map(i -> "Message #" + i)
.flatMap(message -> sendMessage(chatRoom, message)
- .retryWhen(Retry.fixedDelay(10, Duration.ofSeconds(1))))
+ .retryWhen(Retry.fixedDelay(30, Duration.ofSeconds(1))))
.doOnNext(message ->
{
+ numSentMessages++;
sentMessages.add(message);
log.info(
"{} sent a message to {}: {}",
final List<MessageTo> sentMessages = new LinkedList<>();
volatile boolean running = true;
+ @Getter
+ private volatile int numSentMessages = 0;
TestWriter(Integer port, ChatRoomInfoTo chatRoom, String username)