From: Kai Moritz Date: Sun, 12 Feb 2023 14:12:08 +0000 (+0100) Subject: counter: Fixed a bug in the logic of the assertions for the expected state X-Git-Tag: counter-tests-instances~2 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=5cd9820a79e83dc9217072edb609965f337bc197;p=demos%2Fkafka%2Fwordcount counter: Fixed a bug in the logic of the assertions for the expected state - Each combination of a user and a word is a uniq key. - Since the ordering is only guaranteed for messages, with the same key, no expectations can be made according the ordering of messages with different keys! --- diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java index d30c5c7..ae18246 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -28,47 +28,59 @@ class TestData static void assertExpectedResult(List receivedMessages) { - MultiValueMap received = new LinkedMultiValueMap<>(); - - receivedMessages.forEach(message -> received.add(message.getKey().getUsername(), message)); - - assertThat(received).hasSize(2); - assertThat(received.get("klaus")).containsExactly(klaus1, klaus2, klaus3, klaus4, klaus5); - assertThat(received.get("peter")).containsExactly(peter1, peter2, peter3, peter4, peter5, peter6); + assertThat(receivedMessages).hasSize(11); + assertThat(receivedMessages).containsSubsequence( + expectedMessages[0]); // Hallo + assertThat(receivedMessages).containsSubsequence( + expectedMessages[1], + expectedMessages[3]); // Müsch + assertThat(receivedMessages).containsSubsequence( + expectedMessages[2], + expectedMessages[6]); + assertThat(receivedMessages).containsSubsequence( + expectedMessages[4], + expectedMessages[8], + expectedMessages[10]); // s + assertThat(receivedMessages).containsSubsequence( + expectedMessages[5], + expectedMessages[7], + expectedMessages[9]); // Boäh } - static Message peter1 = Message.of( - Key.of("peter", "Hallo"), - "1"); - static Message peter2 = Message.of( - Key.of("peter", "Welt"), - "1"); - static Message peter3 = Message.of( - Key.of("peter", "Boäh"), - "1"); - static Message peter4 = Message.of( - Key.of("peter", "Welt"), - "2"); - static Message peter5 = Message.of( - Key.of("peter", "Boäh"), - "2"); - static Message peter6 = Message.of( - Key.of("peter", "Boäh"), - "3"); - - static Message klaus1 = Message.of( - Key.of("klaus", "Müsch"), - "1"); - static Message klaus2 = Message.of( - Key.of("klaus", "Müsch"), - "2"); - static Message klaus3 = Message.of( - Key.of("klaus", "s"), - "1"); - static Message klaus4 = Message.of( - Key.of("klaus", "s"), - "2"); - static Message klaus5 = Message.of( - Key.of("klaus", "s"), - "3"); + static Message[] expectedMessages = + { + Message.of( + Key.of("peter", "Hallo"), + "1"), + Message.of( + Key.of("klaus", "Müsch"), + "1"), + Message.of( + Key.of("peter", "Welt"), + "1"), + Message.of( + Key.of("klaus", "Müsch"), + "2"), + Message.of( + Key.of("klaus", "s"), + "1"), + Message.of( + Key.of("peter", "Boäh"), + "1"), + Message.of( + Key.of("peter", "Welt"), + "2"), + Message.of( + Key.of("peter", "Boäh"), + "2"), + Message.of( + Key.of("klaus", "s"), + "2"), + Message.of( + Key.of("peter", "Boäh"), + "3"), + Message.of( + Key.of("klaus", "s"), + "3"), + }; }