top10: 1.2.1 - Fixed race-condition in `Top10ApplicationIT`
authorKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 16:30:28 +0000 (18:30 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 17:36:10 +0000 (19:36 +0200)
src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java

index ea8fe18..a1bc1f0 100644 (file)
@@ -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<TestUser, TestRanking> getReceivedMessages()
+               synchronized void enforceAssertion(
+                               java.util.function.Consumer<MultiValueMap<TestUser, TestRanking>> assertion)
                {
-                       return received;
+                       assertion.accept(received);
                }
        }