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

index ee9ab92..0cd5edc 100644 (file)
@@ -2,23 +2,15 @@ package de.juplo.kafka.chat.backend;
 
 import de.juplo.kafka.chat.backend.implementation.kafka.*;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.kafka.clients.producer.ProducerRecord;
-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.context.properties.EnableConfigurationProperties;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.context.TestConfiguration;
 import org.springframework.boot.test.mock.mockito.MockBean;
-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 org.springframework.kafka.test.context.EmbeddedKafka;
 
-import java.util.List;
-
 import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.DATA_TOPIC;
 import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.INFO_TOPIC;
 
@@ -35,6 +27,7 @@ import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.INFO_TOPIC;
         "chat.backend.kafka.data-channel-topic=" + DATA_TOPIC,
         "chat.backend.kafka.num-partitions=10",
         })
+@Import(KafkaTestUtils.KafkaTestConfiguration.class)
 @EmbeddedKafka(
     topics = { INFO_TOPIC, DATA_TOPIC },
     partitions = 10)
@@ -64,23 +57,4 @@ class KafkaConfigurationIT extends AbstractConfigurationWithShardingIT
   {
     KafkaTestUtils.joinConsumerTasks(consumerTaskRunner);
   }
-
-
-  @TestConfiguration
-  @EnableConfigurationProperties(ChatBackendProperties.class)
-  @Import(KafkaServicesConfiguration.class)
-  static class KafkaConfigurationITConfiguration
-  {
-    @Bean
-    WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
-    {
-      return consumer ->
-      {
-        List<TopicPartition> assignedPartitions =
-            List.of(new TopicPartition(DATA_TOPIC, 2));
-        consumer.assign(assignedPartitions);
-        dataChannel.onPartitionsAssigned(assignedPartitions);
-      };
-    }
-  }
 }
index 7ba713d..256d3f2 100644 (file)
@@ -21,24 +21,24 @@ public class KafkaTestUtils
   @TestConfiguration
   @EnableConfigurationProperties(ChatBackendProperties.class)
   @Import(KafkaServicesConfiguration.class)
-  static class KafkaTestConfiguration
+  public static class KafkaTestConfiguration
   {
     @Bean
-    WorkAssignor dataChannelWorkAssignor(
+    public WorkAssignor dataChannelWorkAssignor(
         ChatBackendProperties properties,
         DataChannel dataChannel)
     {
       return consumer ->
       {
         List<TopicPartition> assignedPartitions =
-            List.of(new TopicPartition(properties.getKafka().getInfoChannelTopic(), 2));
+            List.of(new TopicPartition(properties.getKafka().getDataChannelTopic(), 2));
         consumer.assign(assignedPartitions);
         dataChannel.onPartitionsAssigned(assignedPartitions);
       };
     }
 
     @Bean
-    Clock clock()
+    public Clock clock()
     {
       return Clock.systemDefaultZone();
     }