From: Kai Moritz Date: Sat, 8 Jun 2024 16:30:28 +0000 (+0200) Subject: top10: 1.2.1 - Fixed race-condition in `Top10ApplicationIT` X-Git-Tag: top10-1.2.1~2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=e59d8080ffe2750774c881766e691012964c9099;p=demos%2Fkafka%2Fwordcount top10: 1.2.1 - Fixed race-condition in `Top10ApplicationIT` --- diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java index ea8fe18..a1bc1f0 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java @@ -102,7 +102,8 @@ public class Top10ApplicationIT { await("Expected messages") .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> TestData.assertExpectedMessages(consumer.getReceivedMessages())); + .untilAsserted(() -> consumer.enforceAssertion( + receivedMessages -> TestData.assertExpectedMessages(receivedMessages))); } @DisplayName("Await the expected number of messages") @@ -111,7 +112,8 @@ public class Top10ApplicationIT { await("Expected number of messages") .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> TestData.assertExpectedNumberOfMessagesForUsers(consumer.getReceivedMessages())); + .untilAsserted(() -> consumer.enforceAssertion( + receivedMessages -> TestData.assertExpectedNumberOfMessagesForUsers(receivedMessages))); } @DisplayName("Await the expected final output messages") @@ -120,7 +122,8 @@ public class Top10ApplicationIT { await("Expected final output messages") .atMost(Duration.ofSeconds(5)) - .untilAsserted(() -> TestData.assertExpectedLastMessagesForUsers(consumer.getReceivedMessages())); + .untilAsserted(() -> consumer.enforceAssertion( + receivedMessages -> TestData.assertExpectedLastMessagesForUsers(receivedMessages))); } @@ -137,9 +140,10 @@ public class Top10ApplicationIT received.add(user, ranking); } - synchronized MultiValueMap getReceivedMessages() + synchronized void enforceAssertion( + java.util.function.Consumer> assertion) { - return received; + assertion.accept(received); } }