VORTASTEN
authorKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 11:28:27 +0000 (13:28 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 11:28:27 +0000 (13:28 +0200)
src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java
src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java
src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java

index 04caad6..ee9ab92 100644 (file)
@@ -54,6 +54,8 @@ class KafkaConfigurationIT extends AbstractConfigurationWithShardingIT
   {
     KafkaTestUtils.sendAndLoadStoredData(
         messageTemplate,
+        INFO_TOPIC,
+        DATA_TOPIC,
         consumerTaskRunner);
   }
 
index 33d2600..394ba1b 100644 (file)
@@ -49,6 +49,8 @@ public class KafkaChatHomeServiceTest extends ChatHomeServiceWithShardsTest
   {
     KafkaTestUtils.sendAndLoadStoredData(
         messageTemplate,
+        INFO_TOPIC,
+        DATA_TOPIC,
         consumerTaskRunner);
   }
 
index e19473b..7ba713d 100644 (file)
@@ -14,9 +14,6 @@ import org.springframework.kafka.support.SendResult;
 import java.time.Clock;
 import java.util.List;
 
-import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.DATA_TOPIC;
-import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.INFO_TOPIC;
-
 
 @Slf4j
 public class KafkaTestUtils
@@ -27,12 +24,14 @@ public class KafkaTestUtils
   static class KafkaTestConfiguration
   {
     @Bean
-    WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
+    WorkAssignor dataChannelWorkAssignor(
+        ChatBackendProperties properties,
+        DataChannel dataChannel)
     {
       return consumer ->
       {
         List<TopicPartition> assignedPartitions =
-            List.of(new TopicPartition(DATA_TOPIC, 2));
+            List.of(new TopicPartition(properties.getKafka().getInfoChannelTopic(), 2));
         consumer.assign(assignedPartitions);
         dataChannel.onPartitionsAssigned(assignedPartitions);
       };
@@ -48,13 +47,15 @@ public class KafkaTestUtils
 
   public static void sendAndLoadStoredData(
       KafkaTemplate<String, String> messageTemplate,
+      String infoTopic,
+      String dataTopic,
       ConsumerTaskRunner consumerTaskRunner)
   {
-    send(messageTemplate, INFO_TOPIC, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\": \"5c73531c-6fc4-426c-adcb-afc5c140a0f7\", \"shard\": 2, \"name\": \"FOO\" }", "event_chatroom_created");
-    send(messageTemplate, DATA_TOPIC, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"peter\", \"text\" : \"Hallo, ich heiße Peter!\" }", "event_chatmessage_received");
-    send(messageTemplate, DATA_TOPIC, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"ute\", \"text\" : \"Ich bin Ute...\" }", "event_chatmessage_received");
-    send(messageTemplate, DATA_TOPIC, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 2, \"user\" : \"peter\", \"text\" : \"Willst du mit mir gehen?\" }", "event_chatmessage_received");
-    send(messageTemplate, DATA_TOPIC, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"klaus\", \"text\" : \"Ja? Nein? Vielleicht??\" }", "event_chatmessage_received");
+    send(messageTemplate, infoTopic, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\": \"5c73531c-6fc4-426c-adcb-afc5c140a0f7\", \"shard\": 2, \"name\": \"FOO\" }", "event_chatroom_created");
+    send(messageTemplate, dataTopic, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"peter\", \"text\" : \"Hallo, ich heiße Peter!\" }", "event_chatmessage_received");
+    send(messageTemplate, dataTopic, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"ute\", \"text\" : \"Ich bin Ute...\" }", "event_chatmessage_received");
+    send(messageTemplate, dataTopic, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 2, \"user\" : \"peter\", \"text\" : \"Willst du mit mir gehen?\" }", "event_chatmessage_received");
+    send(messageTemplate, dataTopic, "5c73531c-6fc4-426c-adcb-afc5c140a0f7","{ \"id\" : 1, \"user\" : \"klaus\", \"text\" : \"Ja? Nein? Vielleicht??\" }", "event_chatmessage_received");
 
     consumerTaskRunner.run();
   }