Skip to content

Commit 044b496

Browse files
committed
Switch to ComposeContainer constructor to use V2 docker-compose
1 parent a78de16 commit 044b496

File tree

4 files changed

+82
-76
lines changed
  • kogito-quarkus-examples
  • kogito-springboot-examples

4 files changed

+82
-76
lines changed

kogito-quarkus-examples/dmn-drools-quarkus-metrics/src/test/java/org/kie/kogito/examples/quarkus/GrafanaDockerComposeIT.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.kie.kogito.testcontainers.Constants;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
29-
import org.testcontainers.containers.DockerComposeContainer;
29+
import org.testcontainers.containers.ComposeContainer;
3030
import org.testcontainers.containers.output.Slf4jLogConsumer;
3131
import org.testcontainers.containers.wait.strategy.Wait;
3232
import org.testcontainers.junit.jupiter.Container;
@@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT {
5454
private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId();
5555

5656
@Container
57-
public static DockerComposeContainer environment;
57+
public static ComposeContainer environment;
5858

5959
static {
6060
try {
61-
environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI()))
62-
.withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
63-
.withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER))
64-
.withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
65-
.withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER))
66-
.withExposedService("prometheus_1", PROMETHEUS_PORT,
61+
environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI()))
62+
.withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
63+
.withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER))
64+
.withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
65+
.withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER))
66+
.withExposedService("prometheus-1", PROMETHEUS_PORT,
6767
Wait.forHttp("/api/v1/targets")
6868
.forResponsePredicate(x -> x.contains("\"health\":\"up\""))
6969
.withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
70-
.withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER))
70+
.withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER))
7171
.withPull(false)
72-
.withLocalCompose(true)
73-
//See https://github.com/testcontainers/testcontainers-java/issues/4565
74-
.withOptions("--compatibility");
72+
.withLocalCompose(true);
7573
} catch (URISyntaxException e) {
7674
throw new RuntimeException(e);
7775
}

kogito-quarkus-examples/process-outbox-mongodb-quarkus/src/test/java/org/kie/kogito/quarkus/outbox/OutboxIT.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@
1818
*/
1919
package org.kie.kogito.quarkus.outbox;
2020

21+
import java.nio.file.Path;
22+
import java.nio.file.Paths;
2123
import java.time.Duration;
2224
import java.util.Set;
2325
import java.util.concurrent.CountDownLatch;
2426
import java.util.concurrent.TimeUnit;
2527
import java.util.function.Consumer;
2628

29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
2731
import org.junit.jupiter.api.Disabled;
2832
import org.junit.jupiter.api.Test;
2933
import org.kie.kogito.test.quarkus.kafka.KafkaTestClient;
3034
import org.slf4j.Logger;
3135
import org.slf4j.LoggerFactory;
32-
import org.testcontainers.containers.DockerComposeContainer;
36+
import org.testcontainers.containers.ComposeContainer;
3337
import org.testcontainers.containers.output.OutputFrame;
3438
import org.testcontainers.containers.output.Slf4jLogConsumer;
39+
import org.testcontainers.containers.wait.strategy.Wait;
40+
import org.testcontainers.junit.jupiter.Container;
41+
import org.testcontainers.junit.jupiter.Testcontainers;
3542

3643
import com.jayway.jsonpath.JsonPath;
3744

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

45-
//@Testcontainers
52+
@Testcontainers
4653
public class OutboxIT {
4754

4855
private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class);
@@ -55,8 +62,8 @@ public class OutboxIT {
5562
private static final int KAFKA_PORT = 9092;
5663
private static final int DEBEZIUM_PORT = 8083;
5764

58-
//@Container
59-
private static DockerComposeContainer COMPOSE;
65+
@Container
66+
private static ComposeContainer COMPOSE;
6067

6168
private int kogitoPort;
6269
private int debeziumPort;
@@ -65,41 +72,39 @@ public class OutboxIT {
6572
private KafkaTestClient kafkaClient;
6673

6774
static {
68-
// Path path = Paths.get("../../docker-compose.yml");
69-
// if (!path.toFile().exists()) {
70-
// path = Paths.get("docker-compose.yml");
71-
// }
72-
// COMPOSE = new DockerComposeContainer(path.toFile());
73-
// COMPOSE.withPull(false);
74-
// COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
75-
// COMPOSE.withExposedService("kogito", KOGITO_PORT);
76-
// COMPOSE.withExposedService("kafka", KAFKA_PORT);
77-
// COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
78-
// COMPOSE.withLogConsumer("kafka", logger());
79-
// COMPOSE.withLogConsumer("connect", logger());
80-
// COMPOSE.withLogConsumer("sidecar", logger());
81-
// COMPOSE.withLogConsumer("kogito", logger());
82-
// COMPOSE.waitingFor("kafka", Wait.forListeningPort());
83-
// COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
84-
// COMPOSE.waitingFor("kogito", Wait.forListeningPort());
85-
// COMPOSE.withLocalCompose(true);
86-
// //See https://github.com/testcontainers/testcontainers-java/issues/4565
87-
// COMPOSE.withOptions("--compatibility");
75+
Path path = Paths.get("../../docker-compose.yml");
76+
if (!path.toFile().exists()) {
77+
path = Paths.get("docker-compose.yml");
78+
}
79+
COMPOSE = new ComposeContainer(path.toFile());
80+
COMPOSE.withPull(false);
81+
COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
82+
COMPOSE.withExposedService("kogito", KOGITO_PORT);
83+
COMPOSE.withExposedService("kafka", KAFKA_PORT);
84+
COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
85+
COMPOSE.withLogConsumer("kafka", logger());
86+
COMPOSE.withLogConsumer("connect", logger());
87+
COMPOSE.withLogConsumer("sidecar", logger());
88+
COMPOSE.withLogConsumer("kogito", logger());
89+
COMPOSE.waitingFor("kafka", Wait.forListeningPort());
90+
COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
91+
COMPOSE.waitingFor("kogito", Wait.forListeningPort());
92+
COMPOSE.withLocalCompose(true);
8893
}
8994

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

94-
//@BeforeEach
99+
@BeforeEach
95100
void setup() {
96101
kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT);
97102
debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT);
98103
kafkaPort = COMPOSE.getServicePort("kafka", KAFKA_PORT);
99104
kafkaClient = new KafkaTestClient("localhost:" + kafkaPort);
100105
}
101106

102-
//@AfterEach
107+
@AfterEach
103108
void close() {
104109
if (kafkaClient != null) {
105110
kafkaClient.shutdown();

kogito-springboot-examples/dmn-drools-springboot-metrics/src/test/java/org/kie/kogito/examples/springboot/GrafanaDockerComposeIT.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import org.kie.kogito.testcontainers.Constants;
2727
import org.slf4j.Logger;
2828
import org.slf4j.LoggerFactory;
29-
import org.testcontainers.containers.DockerComposeContainer;
29+
import org.testcontainers.containers.ComposeContainer;
3030
import org.testcontainers.containers.output.Slf4jLogConsumer;
3131
import org.testcontainers.containers.wait.strategy.Wait;
3232
import org.testcontainers.junit.jupiter.Container;
@@ -54,24 +54,22 @@ public class GrafanaDockerComposeIT {
5454
private static final String PROJECT_ARTIFACT_ID = ProjectMetadataProvider.getProjectArtifactId();
5555

5656
@Container
57-
public static DockerComposeContainer environment;
57+
public static ComposeContainer environment;
5858

5959
static {
6060
try {
61-
environment = new DockerComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI()))
62-
.withExposedService("grafana_1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
63-
.withLogConsumer("grafana_1", new Slf4jLogConsumer(LOGGER))
64-
.withExposedService("hello_1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
65-
.withLogConsumer("hello_1", new Slf4jLogConsumer(LOGGER))
66-
.withExposedService("prometheus_1", PROMETHEUS_PORT,
61+
environment = new ComposeContainer(new File(GrafanaDockerComposeIT.class.getClassLoader().getResource("./docker-compose.yml").toURI()))
62+
.withExposedService("grafana-1", GRAFANA_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
63+
.withLogConsumer("grafana-1", new Slf4jLogConsumer(LOGGER))
64+
.withExposedService("hello-1", KOGITO_APPLICATION_PORT, Wait.forListeningPort().withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
65+
.withLogConsumer("hello-1", new Slf4jLogConsumer(LOGGER))
66+
.withExposedService("prometheus-1", PROMETHEUS_PORT,
6767
Wait.forHttp("/api/v1/targets")
6868
.forResponsePredicate(x -> x.contains("\"health\":\"up\""))
6969
.withStartupTimeout(STARTUP_MINUTES_TIMEOUT))
70-
.withLogConsumer("prometheus_1", new Slf4jLogConsumer(LOGGER))
70+
.withLogConsumer("prometheus-1", new Slf4jLogConsumer(LOGGER))
7171
.withPull(false)
72-
.withLocalCompose(true)
73-
//See https://github.com/testcontainers/testcontainers-java/issues/4565
74-
.withOptions("--compatibility");
72+
.withLocalCompose(true);
7573
} catch (URISyntaxException e) {
7674
throw new RuntimeException(e);
7775
}

kogito-springboot-examples/process-outbox-mongodb-springboot/src/test/java/org/kie/kogito/springboot/outbox/OutboxIT.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@
1818
*/
1919
package org.kie.kogito.springboot.outbox;
2020

21+
import java.nio.file.Path;
22+
import java.nio.file.Paths;
2123
import java.time.Duration;
2224
import java.util.Set;
2325
import java.util.concurrent.CountDownLatch;
2426
import java.util.concurrent.TimeUnit;
2527
import java.util.function.Consumer;
2628

29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.BeforeEach;
2731
import org.junit.jupiter.api.Disabled;
2832
import org.junit.jupiter.api.Test;
2933
import org.kie.kogito.test.springboot.kafka.KafkaTestClient;
3034
import org.slf4j.Logger;
3135
import org.slf4j.LoggerFactory;
32-
import org.testcontainers.containers.DockerComposeContainer;
36+
import org.testcontainers.containers.ComposeContainer;
3337
import org.testcontainers.containers.output.OutputFrame;
3438
import org.testcontainers.containers.output.Slf4jLogConsumer;
39+
import org.testcontainers.containers.wait.strategy.Wait;
40+
import org.testcontainers.junit.jupiter.Container;
41+
import org.testcontainers.junit.jupiter.Testcontainers;
3542

3643
import com.jayway.jsonpath.JsonPath;
3744

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

45-
//@Testcontainers
52+
@Testcontainers
4653
public class OutboxIT {
4754

4855
private static final Logger LOGGER = LoggerFactory.getLogger(OutboxIT.class);
@@ -55,8 +62,8 @@ public class OutboxIT {
5562
private static final int KAFKA_PORT = 9092;
5663
private static final int DEBEZIUM_PORT = 8083;
5764

58-
//@Container
59-
private static DockerComposeContainer<?> COMPOSE;
65+
@Container
66+
private static ComposeContainer COMPOSE;
6067

6168
private int kogitoPort;
6269
private int debeziumPort;
@@ -65,41 +72,39 @@ public class OutboxIT {
6572
private KafkaTestClient kafkaClient;
6673

6774
static {
68-
// Path path = Paths.get("../../docker-compose.yml");
69-
// if (!path.toFile().exists()) {
70-
// path = Paths.get("docker-compose.yml");
71-
// }
72-
// COMPOSE = new DockerComposeContainer<>(path.toFile());
73-
// COMPOSE.withPull(false);
74-
// COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
75-
// COMPOSE.withExposedService("kogito", KOGITO_PORT);
76-
// COMPOSE.withExposedService("kafka", KAFKA_PORT);
77-
// COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
78-
// COMPOSE.withLogConsumer("kafka", logger());
79-
// COMPOSE.withLogConsumer("connect", logger());
80-
// COMPOSE.withLogConsumer("sidecar", logger());
81-
// COMPOSE.withLogConsumer("kogito", logger());
82-
// COMPOSE.waitingFor("kafka", Wait.forListeningPort());
83-
// COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
84-
// COMPOSE.waitingFor("kogito", Wait.forListeningPort());
85-
// COMPOSE.withLocalCompose(true);
86-
// //See https://github.com/testcontainers/testcontainers-java/issues/4565
87-
// COMPOSE.withOptions("--compatibility");
75+
Path path = Paths.get("../../docker-compose.yml");
76+
if (!path.toFile().exists()) {
77+
path = Paths.get("docker-compose.yml");
78+
}
79+
COMPOSE = new ComposeContainer(path.toFile());
80+
COMPOSE.withPull(false);
81+
COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
82+
COMPOSE.withExposedService("kogito", KOGITO_PORT);
83+
COMPOSE.withExposedService("kafka", KAFKA_PORT);
84+
COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
85+
COMPOSE.withLogConsumer("kafka", logger());
86+
COMPOSE.withLogConsumer("connect", logger());
87+
COMPOSE.withLogConsumer("sidecar", logger());
88+
COMPOSE.withLogConsumer("kogito", logger());
89+
COMPOSE.waitingFor("kafka", Wait.forListeningPort());
90+
COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
91+
COMPOSE.waitingFor("kogito", Wait.forListeningPort());
92+
COMPOSE.withLocalCompose(true);
8893
}
8994

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

94-
// @BeforeEach
99+
@BeforeEach
95100
void setup() {
96101
kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT);
97102
debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT);
98103
kafkaPort = COMPOSE.getServicePort("kafka", KAFKA_PORT);
99104
kafkaClient = new KafkaTestClient("localhost:" + kafkaPort);
100105
}
101106

102-
// @AfterEach
107+
@AfterEach
103108
void close() {
104109
if (kafkaClient != null) {
105110
kafkaClient.shutdown();

0 commit comments

Comments
 (0)