VORTASTEN
authorKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 10:57:33 +0000 (12:57 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 11:17:29 +0000 (13:17 +0200)
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 25ea676..6d52c25 100644 (file)
@@ -1,25 +1,16 @@
 package de.juplo.kafka.chat.backend.implementation.kafka;
 
-import de.juplo.kafka.chat.backend.ChatBackendProperties;
 import de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.common.TopicPartition;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
 import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.context.TestConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Import;
 import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.kafka.test.context.EmbeddedKafka;
 
-import java.time.Clock;
-import java.util.List;
-
 import static de.juplo.kafka.chat.backend.domain.ChatHomeServiceWithShardsTest.NUM_SHARDS;
 import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.DATA_TOPIC;
 import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.INFO_TOPIC;
@@ -27,7 +18,7 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ
 
 @SpringBootTest(
     classes = {
-        KafkaChatHomeServiceTest.KafkaChatHomeTestConfiguration.class,
+        KafkaTestUtils.KafkaTestConfiguration.class,
         KafkaAutoConfiguration.class,
         TaskExecutionAutoConfiguration.class,
     },
@@ -51,31 +42,6 @@ public class KafkaChatHomeServiceTest extends ChatHomeServiceWithShardsTest
   final static String DATA_TOPIC = "KAFKA_CHAT_HOME_TEST_DATA";
 
 
-  @TestConfiguration
-  @EnableConfigurationProperties(ChatBackendProperties.class)
-  @Import(KafkaServicesConfiguration.class)
-  static class KafkaChatHomeTestConfiguration
-  {
-    @Bean
-    WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
-    {
-      return consumer ->
-      {
-        List<TopicPartition> assignedPartitions =
-            List.of(new TopicPartition(DATA_TOPIC, 2));
-        consumer.assign(assignedPartitions);
-        dataChannel.onPartitionsAssigned(assignedPartitions);
-      };
-    }
-
-    @Bean
-    Clock clock()
-    {
-      return Clock.systemDefaultZone();
-    }
-  }
-
-
   @BeforeAll
   static void sendAndLoadStoredData(
       @Autowired ConsumerTaskRunner consumerTaskRunner,
index 656ba78..a00f2c1 100644 (file)
@@ -1,11 +1,19 @@
 package de.juplo.kafka.chat.backend.implementation.kafka;
 
+import de.juplo.kafka.chat.backend.ChatBackendProperties;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.producer.ProducerRecord;
 import org.apache.kafka.common.TopicPartition;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.boot.test.context.TestConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Import;
 import org.springframework.kafka.core.KafkaTemplate;
 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;
 
@@ -13,6 +21,31 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ
 @Slf4j
 public class KafkaTestUtils
 {
+  @TestConfiguration
+  @EnableConfigurationProperties(ChatBackendProperties.class)
+  @Import(KafkaServicesConfiguration.class)
+  static class KafkaTestConfiguration
+  {
+    @Bean
+    WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
+    {
+      return consumer ->
+      {
+        List<TopicPartition> assignedPartitions =
+            List.of(new TopicPartition(DATA_TOPIC, 2));
+        consumer.assign(assignedPartitions);
+        dataChannel.onPartitionsAssigned(assignedPartitions);
+      };
+    }
+
+    @Bean
+    Clock clock()
+    {
+      return Clock.systemDefaultZone();
+    }
+  }
+
+
   static void sendAndLoadStoredData(
       ConsumerTaskRunner consumerTaskRunner,
       KafkaTemplate<String, String> messageTemplate)