From 33639a3c8ae1ce028d3a273d8d28e9c2472e2a2b Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Sun, 2 Jun 2024 11:10:21 +0200 Subject: [PATCH] top10: 1.2.1 - Added expectations for the final state in the last message --- .../java/de/juplo/kafka/wordcount/top10/TestData.java | 6 ++++++ .../juplo/kafka/wordcount/top10/Top10ApplicationIT.java | 9 +++++++++ .../top10/Top10StreamProcessorTopologyTest.java | 2 ++ 3 files changed, 17 insertions(+) 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 eb30298..008cdde 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,12 @@ class TestData assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(KLAUS)); } + static void assertExpectedLastMessagesForUsers(MultiValueMap receivedMessages) + { + assertRankingEqualsRankingFromLastMessage(PETER, getLastMessageFor(PETER, receivedMessages)); + assertRankingEqualsRankingFromLastMessage(KLAUS, getLastMessageFor(KLAUS, receivedMessages)); + } + static void assertRankingEqualsRankingFromLastMessage(User user, Ranking ranking) { assertThat(ranking).isEqualTo(getLastMessageFor(user)); 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 d55048d..d27a9d1 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 final output messages") + @Test + public void testAwaitExpectedLastMessagesForUsers() + { + await("Expected final output messages") + .atMost(Duration.ofSeconds(5)) + .untilAsserted(() -> TestData.assertExpectedLastMessagesForUsers(consumer.getReceivedMessages())); + } + static class Consumer { 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 1becd65..200b6f4 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,8 @@ public class Top10StreamProcessorTopologyTest TestData.assertExpectedMessages(receivedMessages); + TestData.assertExpectedLastMessagesForUsers(receivedMessages); + KeyValueStore store = testDriver.getKeyValueStore(STORE_NAME); TestData.assertExpectedState(store); } -- 2.20.1