Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ComposeContainer constructor to use V2 docker-compose #1994

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -55,59 +64,57 @@ 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;
private int kafkaPort;

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<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();
}
}

@Test
@Disabled
public void testSendProcessEvents() throws InterruptedException {
// Check Debezium (Kafka, MongoDB) readiness
await().ignoreExceptions()
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,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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -55,59 +64,57 @@ 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;
private int kafkaPort;

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<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();
}
}

@Test
@Disabled
public void testSendProcessEvents() throws InterruptedException {
// Check Debezium (Kafka, MongoDB) readiness
await().ignoreExceptions()
Expand Down
Loading