WIP:neu
authorKai Moritz <kai@juplo.de>
Thu, 22 Feb 2024 19:42:46 +0000 (20:42 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 23 Feb 2024 15:40:03 +0000 (16:40 +0100)
src/test/java/de/juplo/kafka/chat/backend/AbstractHandoverIT.java
src/test/java/de/juplo/kafka/chat/backend/KafkaHandoverIT.java

index 945b1c5..9d30331 100644 (file)
@@ -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();
 }
index afb373f..677e889 100644 (file)
@@ -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()
+  {
 
+  }
 }