From 72146c26f795888d74f05e887e2bcb6d2a4bf909 Mon Sep 17 00:00:00 2001 From: Kai Moritz Date: Thu, 22 Feb 2024 20:42:46 +0100 Subject: [PATCH] WIP:neu --- .../chat/backend/AbstractHandoverIT.java | 14 +---- .../kafka/chat/backend/KafkaHandoverIT.java | 59 ++++++++++++++----- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java index 945b1c56..9d30331e 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java @@ -11,21 +11,9 @@ import org.testcontainers.utility.DockerImageName; @Testcontainers public abstract class AbstractHandoverIT { - @Container - KafkaContainer kafka = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")).withKraft(); - - @Container - GenericContainer backend1 = new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")); - @Container - GenericContainer backend2 = new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")); - @Container - GenericContainer backend3 = new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")); - - @BeforeAll - void startInstances() + static void startInstances() { } - var bootstrapServers = kafka.getBootstrapServers(); } diff --git a/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java b/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java index afb373f0..677e8892 100644 --- a/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java +++ b/src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java @@ -6,6 +6,7 @@ import de.juplo.kafka.chat.backend.implementation.kafka.KafkaTestUtils; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.TestConfiguration; @@ -13,32 +14,62 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.test.context.EmbeddedKafka; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.KafkaContainer; import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.utility.DockerImageName; import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.DATA_TOPIC; import static de.juplo.kafka.chat.backend.KafkaConfigurationIT.INFO_TOPIC; -@SpringBootTest( - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - 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}", - "chat.backend.kafka.info-channel-topic=" + INFO_TOPIC, - "chat.backend.kafka.data-channel-topic=" + DATA_TOPIC, - "chat.backend.kafka.num-partitions=10", - }) @Slf4j class KafkaHandoverIT extends AbstractHandoverIT { + @Container + KafkaContainer kafka = + new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0")) + .withNetworkAliases("kafka") + .withKraft(); + + @Container + GenericContainer backend1 = + new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")) + .withNetworkAliases("backend-1") + .withCommand( + "--chat.backend.services=kafka", + "--chat.backend.kafka.bootstrap-servers=kafka:9102" + ) + .withExposedPorts(8080); + @Container + GenericContainer backend2 = + new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")) + .withNetworkAliases("backend-2") + .withCommand( + "--chat.backend.services=kafka", + "--chat.backend.kafka.bootstrap-servers=kafka:9102" + ) + .withExposedPorts(8080); + + @Container + GenericContainer backend3 = + new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT")) + .withNetworkAliases("backend-3") + .withCommand( + "--chat.backend.services=kafka", + "--chat.backend.kafka.bootstrap-servers=kafka:9102" + ) + .withExposedPorts(8080); + + @BeforeAll - public static void setUp() + static void setUp() { } - @Container + @Test + void test() + { + } } -- 2.20.1