top10: 1.2.1 - Added expectations for the number of received messages
authorKai Moritz <kai@juplo.de>
Sun, 2 Jun 2024 09:45:30 +0000 (11:45 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 8 Jun 2024 11:15:05 +0000 (13:15 +0200)
src/test/java/de/juplo/kafka/wordcount/top10/TestData.java
src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java
src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java

index 008cdde..a4f79ac 100644 (file)
@@ -73,6 +73,18 @@ class TestData
                assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(KLAUS));
        }
 
+       static void assertExpectedNumberOfMessagesForUsers(MultiValueMap<User, Ranking> receivedMessages)
+       {
+               assertThat(countMessagesForUser(PETER, receivedMessages));
+               assertThat(countMessagesForUser(KLAUS, receivedMessages));
+       }
+
+       static int countMessagesForUser(User user, MultiValueMap<User, Ranking> messagesForUsers)
+       {
+               return messagesForUsers.get(user).size();
+       }
+
+
        static void assertExpectedLastMessagesForUsers(MultiValueMap<User, Ranking> receivedMessages)
        {
                assertRankingEqualsRankingFromLastMessage(PETER, getLastMessageFor(PETER, receivedMessages));
index d27a9d1..1097310 100644 (file)
@@ -107,6 +107,15 @@ public class Top10ApplicationIT
                                .untilAsserted(() -> TestData.assertExpectedMessages(consumer.getReceivedMessages()));
        }
 
+       @DisplayName("Await the expected number of messages")
+       @Test
+       public void testAwaitExpectedNumberOfMessagesForUsers()
+       {
+               await("Expected number of messages")
+                               .atMost(Duration.ofSeconds(5))
+                               .untilAsserted(() -> TestData.assertExpectedNumberOfMessagesForUsers(consumer.getReceivedMessages()));
+       }
+
        @DisplayName("Await the expected final output messages")
        @Test
        public void testAwaitExpectedLastMessagesForUsers()
index 200b6f4..0c9759c 100644 (file)
@@ -98,6 +98,7 @@ public class Top10StreamProcessorTopologyTest
 
     TestData.assertExpectedMessages(receivedMessages);
 
+    TestData.assertExpectedNumberOfMessagesForUsers(receivedMessages);
     TestData.assertExpectedLastMessagesForUsers(receivedMessages);
 
     KeyValueStore<User, Ranking> store = testDriver.getKeyValueStore(STORE_NAME);