From d9112eee52a783975db05acf84e361be5810dcf7 Mon Sep 17 00:00:00 2001 From: gmunozfe Date: Tue, 6 Aug 2024 15:00:10 +0200 Subject: [PATCH] Switch to ComposeContainer constructor to use V2 docker-compose --- .../quarkus/GrafanaDockerComposeIT.java | 22 +++---- .../kie/kogito/quarkus/outbox/OutboxIT.java | 63 ++++++++++--------- .../springboot/GrafanaDockerComposeIT.java | 22 +++---- .../kogito/springboot/outbox/OutboxIT.java | 63 ++++++++++--------- 4 files changed, 90 insertions(+), 80 deletions(-) diff --git a/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java b/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java index fc0a4a1f76..8642a55948 100644 --- a/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java +++ b/kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java @@ -26,7 +26,7 @@ import org.kie.kogito.testcontainers.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; @@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT { private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId(); @Container - public static DockerComposeContainer environment; + public static ComposeContainer environment; static { try { - environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) - .withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("prometheus_1", PROMETHEUS_PORT, + environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) + .withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("prometheus-1", PROMETHEUS_PORT, Wait.forHttp("/api/v1/targets") .forResponsePredicate(x -> x.contains("\"health\":\"up\"")) .withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER)) + .withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER)) .withPull(false) - .withLocalCompose(true) - //See https://github.com/testcontainers/testcontainers-java/issues/4565 - .withOptions("--compatibility"); + .withLocalCompose(true); } catch (URISyntaxException e) { throw new RuntimeException(e); } diff --git a/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java b/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java index 5832a8f472..13355cfddb 100644 --- a/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java +++ b/kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java @@ -18,20 +18,28 @@ */ package org.kie.kogito.quarkus.outbox; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.kogito.test.quarkus.kafka.KafkaTestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import com.jayway.jsonpath.JsonPath; @@ -42,7 +50,8 @@ import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertTrue; -//@Testcontainers +@Testcontainers +@Disabled public class OutboxIT { private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class); @@ -55,8 +64,8 @@ public class OutboxIT { private static final int KAFKA_PORT = 9092; private static final int DEBEZIUM_PORT = 8083; - //@Container - private static DockerComposeContainer COMPOSE; + @Container + private static ComposeContainer COMPOSE; private int kogitoPort; private int debeziumPort; @@ -64,34 +73,33 @@ public class OutboxIT { private KafkaTestClient kafkaClient; - static { - // Path path = Paths.get("../../docker-compose.yml"); - // if (!path.toFile().exists()) { - // path = Paths.get("docker-compose.yml"); - // } - // COMPOSE = new DockerComposeContainer(path.toFile()); - // COMPOSE.withPull(false); - // COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); - // COMPOSE.withExposedService("kogito", KOGITO_PORT); - // COMPOSE.withExposedService("kafka", KAFKA_PORT); - // COMPOSE.withExposedService("connect", DEBEZIUM_PORT); - // COMPOSE.withLogConsumer("kafka", logger()); - // COMPOSE.withLogConsumer("connect", logger()); - // COMPOSE.withLogConsumer("sidecar", logger()); - // COMPOSE.withLogConsumer("kogito", logger()); - // COMPOSE.waitingFor("kafka", Wait.forListeningPort()); - // COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); - // COMPOSE.waitingFor("kogito", Wait.forListeningPort()); - // COMPOSE.withLocalCompose(true); - // //See https://github.com/testcontainers/testcontainers-java/issues/4565 - // COMPOSE.withOptions("--compatibility"); + @BeforeAll + static void init() { + Path path = Paths.get("../../docker-compose.yml"); + if (!path.toFile().exists()) { + path = Paths.get("docker-compose.yml"); + } + COMPOSE = new ComposeContainer(path.toFile()); + COMPOSE.withPull(false); + COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); + COMPOSE.withExposedService("kogito", KOGITO_PORT); + COMPOSE.withExposedService("kafka", KAFKA_PORT); + COMPOSE.withExposedService("connect", DEBEZIUM_PORT); + COMPOSE.withLogConsumer("kafka", logger()); + COMPOSE.withLogConsumer("connect", logger()); + COMPOSE.withLogConsumer("sidecar", logger()); + COMPOSE.withLogConsumer("kogito", logger()); + COMPOSE.waitingFor("kafka", Wait.forListeningPort()); + COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); + COMPOSE.waitingFor("kogito", Wait.forListeningPort()); + COMPOSE.withLocalCompose(true); } private static Consumer logger() { return new Slf4jLogConsumer(LOGGER); } - //@BeforeEach + @BeforeEach void setup() { kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT); debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT); @@ -99,7 +107,7 @@ void setup() { kafkaClient = new KafkaTestClient("localhost:" + kafkaPort); } - //@AfterEach + @AfterEach void close() { if (kafkaClient != null) { kafkaClient.shutdown(); @@ -107,7 +115,6 @@ void close() { } @Test - @Disabled public void testSendProcessEvents() throws InterruptedException { // Check Debezium (Kafka, MongoDB) readiness await().ignoreExceptions() diff --git a/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java b/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java index 871de1ab3d..5fa6e2289c 100644 --- a/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java +++ b/kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java @@ -26,7 +26,7 @@ import org.kie.kogito.testcontainers.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.Slf4jLogConsumer; import org.testcontainers.containers.wait.strategy.Wait; import org.testcontainers.junit.jupiter.Container; @@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT { private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId(); @Container - public static DockerComposeContainer environment; + public static ComposeContainer environment; static { try { - environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) - .withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER)) - .withExposedService("prometheus_1", PROMETHEUS_PORT, + environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI())) + .withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) + .withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER)) + .withExposedService("prometheus-1", PROMETHEUS_PORT, Wait.forHttp("/api/v1/targets") .forResponsePredicate(x -> x.contains("\"health\":\"up\"")) .withStartupTimeout(STARTUP_MINUTES_TIMEOUT)) - .withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER)) + .withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER)) .withPull(false) - .withLocalCompose(true) - //See https://github.com/testcontainers/testcontainers-java/issues/4565 - .withOptions("--compatibility"); + .withLocalCompose(true); } catch (URISyntaxException e) { throw new RuntimeException(e); } diff --git a/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java b/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java index 1379657c3d..455d64c24c 100644 --- a/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java +++ b/kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java @@ -18,20 +18,28 @@ */ package org.kie.kogito.springboot.outbox; +import java.nio.file.Path; +import java.nio.file.Paths; import java.time.Duration; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.kie.kogito.test.springboot.kafka.KafkaTestClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.ComposeContainer; import org.testcontainers.containers.output.OutputFrame; import org.testcontainers.containers.output.Slf4jLogConsumer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import com.jayway.jsonpath.JsonPath; @@ -42,7 +50,8 @@ import static org.hamcrest.Matchers.hasSize; import static org.junit.jupiter.api.Assertions.assertTrue; -//@Testcontainers +@Testcontainers +@Disabled public class OutboxIT { private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class); @@ -55,8 +64,8 @@ public class OutboxIT { private static final int KAFKA_PORT = 9092; private static final int DEBEZIUM_PORT = 8083; - //@Container - private static DockerComposeContainer COMPOSE; + @Container + private static ComposeContainer COMPOSE; private int kogitoPort; private int debeziumPort; @@ -64,34 +73,33 @@ public class OutboxIT { private KafkaTestClient kafkaClient; - static { - // Path path = Paths.get("../../docker-compose.yml"); - // if (!path.toFile().exists()) { - // path = Paths.get("docker-compose.yml"); - // } - // COMPOSE = new DockerComposeContainer<>(path.toFile()); - // COMPOSE.withPull(false); - // COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); - // COMPOSE.withExposedService("kogito", KOGITO_PORT); - // COMPOSE.withExposedService("kafka", KAFKA_PORT); - // COMPOSE.withExposedService("connect", DEBEZIUM_PORT); - // COMPOSE.withLogConsumer("kafka", logger()); - // COMPOSE.withLogConsumer("connect", logger()); - // COMPOSE.withLogConsumer("sidecar", logger()); - // COMPOSE.withLogConsumer("kogito", logger()); - // COMPOSE.waitingFor("kafka", Wait.forListeningPort()); - // COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); - // COMPOSE.waitingFor("kogito", Wait.forListeningPort()); - // COMPOSE.withLocalCompose(true); - // //See https://github.com/testcontainers/testcontainers-java/issues/4565 - // COMPOSE.withOptions("--compatibility"); + @BeforeAll + static void init() { + Path path = Paths.get("../../docker-compose.yml"); + if (!path.toFile().exists()) { + path = Paths.get("docker-compose.yml"); + } + COMPOSE = new ComposeContainer(path.toFile()); + COMPOSE.withPull(false); + COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito"); + COMPOSE.withExposedService("kogito", KOGITO_PORT); + COMPOSE.withExposedService("kafka", KAFKA_PORT); + COMPOSE.withExposedService("connect", DEBEZIUM_PORT); + COMPOSE.withLogConsumer("kafka", logger()); + COMPOSE.withLogConsumer("connect", logger()); + COMPOSE.withLogConsumer("sidecar", logger()); + COMPOSE.withLogConsumer("kogito", logger()); + COMPOSE.waitingFor("kafka", Wait.forListeningPort()); + COMPOSE.waitingFor("sidecar", Wait.forListeningPort()); + COMPOSE.waitingFor("kogito", Wait.forListeningPort()); + COMPOSE.withLocalCompose(true); } private static Consumer logger() { return new Slf4jLogConsumer(LOGGER); } - // @BeforeEach + @BeforeEach void setup() { kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT); debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT); @@ -99,7 +107,7 @@ void setup() { kafkaClient = new KafkaTestClient("localhost:" + kafkaPort); } - // @AfterEach + @AfterEach void close() { if (kafkaClient != null) { kafkaClient.shutdown(); @@ -107,7 +115,6 @@ void close() { } @Test - @Disabled public void testSendProcessEvents() throws InterruptedException { // Check Debezium (Kafka, MongoDB) readiness await().ignoreExceptions()