From: Kai Moritz Date: Sun, 2 Jun 2024 09:45:30 +0000 (+0200) Subject: top10: 1.2.1 - Added expectations for the number of received messages X-Git-Tag: top10-1.2.1~11 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=fa19058953b388f893255d2bcc9351ac9eb3328b;p=demos%2Fkafka%2Fwordcount top10: 1.2.1 - Added expectations for the number of received messages --- diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java index 008cdde..a4f79ac 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/TestData.java @@ -73,6 +73,18 @@ class TestData assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(KLAUS)); } + static void assertExpectedNumberOfMessagesForUsers(MultiValueMap receivedMessages) + { + assertThat(countMessagesForUser(PETER, receivedMessages)); + assertThat(countMessagesForUser(KLAUS, receivedMessages)); + } + + static int countMessagesForUser(User user, MultiValueMap messagesForUsers) + { + return messagesForUsers.get(user).size(); + } + + static void assertExpectedLastMessagesForUsers(MultiValueMap receivedMessages) { assertRankingEqualsRankingFromLastMessage(PETER, getLastMessageFor(PETER, receivedMessages)); 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 d27a9d1..1097310 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/Top10ApplicationIT.java @@ -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() diff --git a/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java index 200b6f4..0c9759c 100644 --- a/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/top10/Top10StreamProcessorTopologyTest.java @@ -98,6 +98,7 @@ public class Top10StreamProcessorTopologyTest TestData.assertExpectedMessages(receivedMessages); + TestData.assertExpectedNumberOfMessagesForUsers(receivedMessages); TestData.assertExpectedLastMessagesForUsers(receivedMessages); KeyValueStore store = testDriver.getKeyValueStore(STORE_NAME);