From e59d8080ffe2750774c881766e691012964c9099 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sat, 8 Jun 2024 18:30:28 +0200 Subject: [PATCH] top10: 1.2.1 - Fixed race-condition in `Top10ApplicationIT` --- .../kafka/wordcount/top10/Top10ApplicationIT.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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); } } -- 2.20.1