From 12636476b306a6471e95789fc69e35d6a779d607 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Fri, 15 Sep 2023 12:52:25 +0200 Subject: [PATCH] WHATTHEFUCK --- .../kafka/KafkaChatHomeServiceTest.java | 45 ++++++++++++++++++- .../implementation/kafka/KafkaTestUtils.java | 32 ------------- src/test/resources/application.yml | 2 +- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java index 1f7ec4d7..3390da32 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java @@ -1,15 +1,25 @@ 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 org.springframework.test.context.TestPropertySource; + +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; @@ -18,7 +28,7 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ @SpringBootTest( classes = { - KafkaTestUtils.KafkaTestConfiguration.class, + KafkaChatHomeServiceTest.KafkaChatHomeTestConfiguration.class, KafkaAutoConfiguration.class, TaskExecutionAutoConfiguration.class, }, @@ -36,6 +46,39 @@ public class KafkaChatHomeServiceTest extends ChatHomeServiceWithShardsTest final static String INFO_TOPIC = "KAFKA_CHAT_HOME_TEST_INFO"; final static String DATA_TOPIC = "KAFKA_CHAT_HOME_TEST_DATA"; + + @TestConfiguration + @EnableConfigurationProperties(ChatBackendProperties.class) + @Import(KafkaServicesConfiguration.class) + @TestPropertySource(properties = { + "spring.main.allow-bean-definition-overriding=true", + "chat.backend.services=kafka", + "chat.backend.kafka.client-id-PREFIX=TEST", + "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", + "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", + }) + static class KafkaChatHomeTestConfiguration + { + @Bean + WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel) + { + return consumer -> + { + List 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, 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 94c3dd1f..823886a6 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 @@ -22,38 +22,6 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ @Slf4j public class KafkaTestUtils { - @TestConfiguration - @EnableConfigurationProperties(ChatBackendProperties.class) - @Import(KafkaServicesConfiguration.class) - @TestPropertySource(properties = { - "spring.main.allow-bean-definition-overriding=true", - "chat.backend.services=kafka", - "chat.backend.kafka.client-id-PREFIX=TEST", - "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", - "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}", - }) - public static class KafkaTestConfiguration - { - @Bean - public WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel) - { - return consumer -> - { - List assignedPartitions = - List.of(new TopicPartition(DATA_TOPIC, 2)); - consumer.assign(assignedPartitions); - dataChannel.onPartitionsAssigned(assignedPartitions); - }; - } - - @Bean - public Clock clock() - { - return Clock.systemDefaultZone(); - } - } - - static void sendAndLoadStoredData( ConsumerTaskRunner consumerTaskRunner, KafkaTemplate messageTemplate) diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 96b0cb3b..b5579d06 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -1,4 +1,4 @@ logging: level: - root: INFO + root: DEBUG de.juplo.kafka.chat.backend: DEBUG -- 2.20.1