From 44f1ad5dcd50851ef5d93b1be759481d5a38f63a Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Wed, 5 Jun 2024 21:00:15 +0200 Subject: [PATCH] counter: 1.2.15 - Refined `TestData` (explicit key in input-data) --- .../counter/CounterApplicationIT.java | 2 +- .../CounterStreamProcessorTopologyTest.java | 2 +- .../kafka/wordcount/counter/TestData.java | 95 ++++++++++++------- 3 files changed, 62 insertions(+), 37 deletions(-) diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java index 31bf6a6..2f1e0c3 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterApplicationIT.java @@ -69,7 +69,7 @@ public class CounterApplicationIT { TestData .getInputMessages() - .forEach(word -> kafkaTemplate.send(TOPIC_IN, word.getUser(), word)); + .forEach(kv -> kafkaTemplate.send(TOPIC_IN, kv.key, kv.value)); await("Expected messages") .atMost(Duration.ofSeconds(10)) diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java index 955d7a0..a1b4c7f 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java @@ -64,7 +64,7 @@ public class CounterStreamProcessorTopologyTest { TestData .getInputMessages() - .forEach(word -> in.pipeInput(word.getUser(), word)); + .forEach(kv -> in.pipeInput(kv.key, kv.value)); MultiValueMap receivedMessages = new LinkedMultiValueMap<>(); out 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 40ef09e..777537b 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/TestData.java @@ -14,22 +14,47 @@ import static org.assertj.core.api.Assertions.assertThat; class TestData { - private static final TestInputWord[] INPUT_MESSAGES = new TestInputWord[] + static final String PETER = "peter"; + static final String KLAUS = "klaus"; + + private static final KeyValue[] INPUT_MESSAGES = new KeyValue[] { - TestInputWord.of("peter","Hallo"), - TestInputWord.of("klaus","Müsch"), - TestInputWord.of("peter","Welt"), - TestInputWord.of("klaus","Müsch"), - TestInputWord.of("klaus","s"), - TestInputWord.of("peter","Boäh"), - TestInputWord.of("peter","Welt"), - TestInputWord.of("peter","Boäh"), - TestInputWord.of("klaus","s"), - TestInputWord.of("peter","Boäh"), - TestInputWord.of("klaus","s"), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Hallo")), + new KeyValue<>( + KLAUS, + TestInputWord.of(KLAUS, "Müsch")), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Welt")), + new KeyValue<>( + KLAUS, + TestInputWord.of(KLAUS, "Müsch")), + new KeyValue<>( + KLAUS, + TestInputWord.of(KLAUS, "s")), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Boäh")), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Welt")), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Boäh")), + new KeyValue<>( + KLAUS, + TestInputWord.of(KLAUS, "s")), + new KeyValue<>( + PETER, + TestInputWord.of(PETER, "Boäh")), + new KeyValue<>( + KLAUS, + TestInputWord.of(KLAUS, "s")), }; - static Stream getInputMessages() + static Stream> getInputMessages() { return Stream.of(TestData.INPUT_MESSAGES); } @@ -45,38 +70,38 @@ class TestData private static final KeyValue[] EXPECTED_MESSAGES = new KeyValue[] { KeyValue.pair( - TestOutputWord.of("peter","Hallo"), - TestOutputWordCounter.of("peter","Hallo",1)), + TestOutputWord.of(PETER, "Hallo"), + TestOutputWordCounter.of(PETER, "Hallo",1)), KeyValue.pair( - TestOutputWord.of("klaus","Müsch"), - TestOutputWordCounter.of("klaus","Müsch",1)), + TestOutputWord.of(KLAUS, "Müsch"), + TestOutputWordCounter.of(KLAUS, "Müsch",1)), KeyValue.pair( - TestOutputWord.of("peter","Welt"), - TestOutputWordCounter.of("peter","Welt",1)), + TestOutputWord.of(PETER, "Welt"), + TestOutputWordCounter.of(PETER, "Welt",1)), KeyValue.pair( - TestOutputWord.of("klaus","Müsch"), - TestOutputWordCounter.of("klaus","Müsch",2)), + TestOutputWord.of(KLAUS, "Müsch"), + TestOutputWordCounter.of(KLAUS, "Müsch",2)), KeyValue.pair( - TestOutputWord.of("klaus","s"), - TestOutputWordCounter.of("klaus","s",1)), + TestOutputWord.of(KLAUS, "s"), + TestOutputWordCounter.of(KLAUS, "s",1)), KeyValue.pair( - TestOutputWord.of("peter","Boäh"), - TestOutputWordCounter.of("peter","Boäh",1)), + TestOutputWord.of(PETER, "Boäh"), + TestOutputWordCounter.of(PETER, "Boäh",1)), KeyValue.pair( - TestOutputWord.of("peter","Welt"), - TestOutputWordCounter.of("peter","Welt",2)), + TestOutputWord.of(PETER, "Welt"), + TestOutputWordCounter.of(PETER, "Welt",2)), KeyValue.pair( - TestOutputWord.of("peter","Boäh"), - TestOutputWordCounter.of("peter","Boäh",2)), + TestOutputWord.of(PETER, "Boäh"), + TestOutputWordCounter.of(PETER, "Boäh",2)), KeyValue.pair( - TestOutputWord.of("klaus","s"), - TestOutputWordCounter.of("klaus","s",2)), + TestOutputWord.of(KLAUS, "s"), + TestOutputWordCounter.of(KLAUS, "s",2)), KeyValue.pair( - TestOutputWord.of("peter","Boäh"), - TestOutputWordCounter.of("peter","Boäh",3)), + TestOutputWord.of(PETER, "Boäh"), + TestOutputWordCounter.of(PETER, "Boäh",3)), KeyValue.pair( - TestOutputWord.of("klaus","s"), - TestOutputWordCounter.of("klaus","s",3)), + TestOutputWord.of(KLAUS, "s"), + TestOutputWordCounter.of(KLAUS, "s",3)), }; static MultiValueMap expectedMessages() -- 2.20.1