From: Kai Moritz Date: Fri, 25 Aug 2023 10:21:41 +0000 (+0200) Subject: WIP:KafkaChatHomeTest X-Git-Tag: wip-kafka-chat-home-test--springboot~3 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=114099c3eeba955ebe05f891dea12cfa6aa8e229;p=demos%2Fkafka%2Fchat WIP:KafkaChatHomeTest --- diff --git a/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeTest.java b/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeTest.java index 1298122a..a99a75cc 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeTest.java +++ b/src/test/java/de/juplo/kafka/chat/backend/persistence/kafka/KafkaChatHomeTest.java @@ -1,31 +1,36 @@ package de.juplo.kafka.chat.backend.persistence.kafka; -import de.juplo.kafka.chat.backend.ChatBackendProperties; import de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTestBase; -import de.juplo.kafka.chat.backend.persistence.kafka.messages.AbstractMessageTo; import lombok.extern.slf4j.Slf4j; import org.apache.kafka.clients.consumer.Consumer; -import org.apache.kafka.clients.producer.Producer; 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.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.kafka.test.context.EmbeddedKafka; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import java.time.Clock; -import java.time.ZoneId; import java.util.List; import java.util.concurrent.CompletableFuture; +import static de.juplo.kafka.chat.backend.domain.ChatHomeWithShardsTestBase.NUM_SHARDS; import static de.juplo.kafka.chat.backend.persistence.kafka.KafkaChatHomeTest.TOPIC; +@PropertySource({ + "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}", + "chat.backend.kafka.chatroom-channel-topic=" + TOPIC, + "chat.backend.kafka.num-partitions=" + NUM_SHARDS, +}) @EmbeddedKafka(topics = { TOPIC }, partitions = 10) @Slf4j public class KafkaChatHomeTest extends ChatHomeWithShardsTestBase @@ -36,35 +41,9 @@ public class KafkaChatHomeTest extends ChatHomeWithShardsTestBase @TestConfiguration + @Import(KafkaServicesConfiguration.class) static class Configuration { - @Bean - KafkaChatHome chatHome(ChatRoomChannel chatRoomChannel) - { - return new KafkaChatHome(numShards(), chatRoomChannel); - } - - @Bean - ChatRoomChannel chatRoomChannel( - Producer chatRoomChannelProducer, - Consumer chatRoomChannelConsumer, - ZoneId zoneId, - Clock clock) - { - return new ChatRoomChannel( - TOPIC, - chatRoomChannelProducer, - chatRoomChannelConsumer, - zoneId, - numShards(), - 8, - clock); - } - - Integer numShards() - { - return 10; - } } @BeforeAll public static void sendAndLoadStoredData(