WIP:neu
authorKai Moritz <kai@juplo.de>
Thu, 22 Feb 2024 20:06:43 +0000 (21:06 +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 9d30331..24baee5 100644 (file)
@@ -3,6 +3,7 @@ package de.juplo.kafka.chat.backend;
 import org.junit.jupiter.api.BeforeAll;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.KafkaContainer;
+import org.testcontainers.images.ImagePullPolicy;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 import org.testcontainers.utility.DockerImageName;
@@ -16,4 +17,14 @@ public abstract class AbstractHandoverIT
   {
 
   }
+
+
+  static final ImagePullPolicy NEVER_PULL = new ImagePullPolicy()
+  {
+    @Override
+    public boolean shouldPull(DockerImageName imageName)
+    {
+      return false;
+    }
+  };
 }
index 9880014..0950576 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.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -16,6 +17,8 @@ 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.containers.output.Slf4jLogConsumer;
+import org.testcontainers.images.ImagePullPolicy;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.utility.DockerImageName;
 
@@ -35,32 +38,32 @@ class KafkaHandoverIT extends AbstractHandoverIT
   @Container
   GenericContainer backend1 =
       new GenericContainer(DockerImageName.parse("juplo/chat-backend:0.0.1-SNAPSHOT"))
+          .withImagePullPolicy(NEVER_PULL)
           .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"))
+          .withImagePullPolicy(NEVER_PULL)
           .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"))
+          .withImagePullPolicy(NEVER_PULL)
           .withNetworkAliases("backend-3")
           .withCommand(
               "--chat.backend.services=kafka",
               "--chat.backend.kafka.bootstrap-servers=kafka:9102"
-          )
-          .withExposedPorts(8080);
+          );
 
 
   @BeforeAll
@@ -73,4 +76,12 @@ class KafkaHandoverIT extends AbstractHandoverIT
   {
 
   }
+
+
+  @BeforeEach
+  void setUpLogging()
+  {
+    Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
+    backend1.followOutput(logConsumer);
+  }
 }