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;
{
}
+
+
+ static final ImagePullPolicy NEVER_PULL = new ImagePullPolicy()
+ {
+ @Override
+ public boolean shouldPull(DockerImageName imageName)
+ {
+ return false;
+ }
+ };
}
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;
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;
@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
{
}
+
+
+ @BeforeEach
+ void setUpLogging()
+ {
+ Slf4jLogConsumer logConsumer = new Slf4jLogConsumer(log);
+ backend1.followOutput(logConsumer);
+ }
}