top10: 1.2.1 - Added expectations for the final state in the last message
authorKai Moritz <kai@juplo.de>
Sun, 2 Jun 2024 09:10:21 +0000 (11:10 +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 eb30298..008cdde 100644 (file)
@@ -73,6 +73,12 @@ class TestData
                assertRankingEqualsRankingFromLastMessage(KLAUS, store.get(KLAUS));
        }
 
+       static void assertExpectedLastMessagesForUsers(MultiValueMap<User, Ranking> receivedMessages)
+       {
+               assertRankingEqualsRankingFromLastMessage(PETER, getLastMessageFor(PETER, receivedMessages));
+               assertRankingEqualsRankingFromLastMessage(KLAUS, getLastMessageFor(KLAUS, receivedMessages));
+       }
+
        static void assertRankingEqualsRankingFromLastMessage(User user, Ranking ranking)
        {
                assertThat(ranking).isEqualTo(getLastMessageFor(user));
index d55048d..d27a9d1 100644 (file)
@@ -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
        {
index 1becd65..200b6f4 100644 (file)
@@ -98,6 +98,8 @@ public class Top10StreamProcessorTopologyTest
 
     TestData.assertExpectedMessages(receivedMessages);
 
+    TestData.assertExpectedLastMessagesForUsers(receivedMessages);
+
     KeyValueStore<User, Ranking> store = testDriver.getKeyValueStore(STORE_NAME);
     TestData.assertExpectedState(store);
   }