Skip to content

Commit

Permalink
Switch to ComposeContainer constructor to use V2 docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
gmunozfe committed Aug 6, 2024
1 parent a78de16 commit a58f30a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,11 +54,11 @@ 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()))
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
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;

Expand All @@ -56,7 +56,7 @@ public class OutboxIT {
private static final int DEBEZIUM_PORT = 8083;

//@Container
private static DockerComposeContainer COMPOSE;
private static ComposeContainer COMPOSE;

private int kogitoPort;
private int debeziumPort;
Expand All @@ -69,7 +69,7 @@ public class OutboxIT {
// if (!path.toFile().exists()) {
// path = Paths.get("docker-compose.yml");
// }
// COMPOSE = new DockerComposeContainer(path.toFile());
// COMPOSE = new ComposeContainer(path.toFile());
// COMPOSE.withPull(false);
// COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
// COMPOSE.withExposedService("kogito", KOGITO_PORT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,11 +54,11 @@ 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()))
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
*/
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.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;

Expand All @@ -42,7 +49,7 @@
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertTrue;

//@Testcontainers
@Testcontainers
public class OutboxIT {

private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class);
Expand All @@ -55,8 +62,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;
Expand All @@ -65,41 +72,41 @@ 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");
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);
//See https://github.com/testcontainers/testcontainers-java/issues/4565
COMPOSE.withOptions("--compatibility");
}

private static Consumer<OutputFrame> logger() {
return new Slf4jLogConsumer(LOGGER);
}

// @BeforeEach
@BeforeEach
void setup() {
kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT);
debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT);
kafkaPort = COMPOSE.getServicePort("kafka", KAFKA_PORT);
kafkaClient = new KafkaTestClient("localhost:" + kafkaPort);
}

// @AfterEach
@AfterEach
void close() {
if (kafkaClient != null) {
kafkaClient.shutdown();
Expand Down

0 comments on commit a58f30a

Please sign in to comment.