From ea5da67c3adcc4ff516972adbf001716ee216ef2 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 15 Sep 2023 13:36:05 +0200 Subject: [PATCH] VORTASTEN --- .../chat/backend/KafkaConfigurationIT.java | 28 +------------------ .../implementation/kafka/KafkaTestUtils.java | 8 +++--- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java index ee9ab92f..0cd5edc4 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/KafkaConfigurationIT.java @@ -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 assignedPartitions = - List.of(new TopicPartition(DATA_TOPIC, 2)); - consumer.assign(assignedPartitions); - dataChannel.onPartitionsAssigned(assignedPartitions); - }; - } - } } diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java index 7ba713db..256d3f2a 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java @@ -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 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(); } -- 2.20.1