Skip to content

Commit e0dd303

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

File tree

4 files changed

+81
-74
lines changed
  • kogito-quarkus-examples
  • kogito-springboot-examples

4 files changed

+81
-74
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: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,28 @@
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.BeforeAll;
31+
import org.junit.jupiter.api.BeforeEach;
2732
import org.junit.jupiter.api.Disabled;
2833
import org.junit.jupiter.api.Test;
2934
import org.kie.kogito.test.quarkus.kafka.KafkaTestClient;
3035
import org.slf4j.Logger;
3136
import org.slf4j.LoggerFactory;
32-
import org.testcontainers.containers.DockerComposeContainer;
37+
import org.testcontainers.containers.ComposeContainer;
3338
import org.testcontainers.containers.output.OutputFrame;
3439
import org.testcontainers.containers.output.Slf4jLogConsumer;
40+
import org.testcontainers.containers.wait.strategy.Wait;
41+
import org.testcontainers.junit.jupiter.Container;
42+
import org.testcontainers.junit.jupiter.Testcontainers;
3543

3644
import com.jayway.jsonpath.JsonPath;
3745

@@ -56,50 +64,49 @@ public class OutboxIT {
5664
private static final int DEBEZIUM_PORT = 8083;
5765

5866
//@Container
59-
private static DockerComposeContainer COMPOSE;
67+
private static ComposeContainer COMPOSE;
6068

6169
private int kogitoPort;
6270
private int debeziumPort;
6371
private int kafkaPort;
6472

6573
private KafkaTestClient kafkaClient;
6674

67-
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+
//@BeforeAll
76+
static void init() {
77+
Path path = Paths.get("../../docker-compose.yml");
78+
if (!path.toFile().exists()) {
79+
path = Paths.get("docker-compose.yml");
80+
}
81+
COMPOSE = new ComposeContainer(path.toFile());
82+
COMPOSE.withPull(false);
83+
COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
84+
COMPOSE.withExposedService("kogito", KOGITO_PORT);
85+
COMPOSE.withExposedService("kafka", KAFKA_PORT);
86+
COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
87+
COMPOSE.withLogConsumer("kafka", logger());
88+
COMPOSE.withLogConsumer("connect", logger());
89+
COMPOSE.withLogConsumer("sidecar", logger());
90+
COMPOSE.withLogConsumer("kogito", logger());
91+
COMPOSE.waitingFor("kafka", Wait.forListeningPort());
92+
COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
93+
COMPOSE.waitingFor("kogito", Wait.forListeningPort());
94+
COMPOSE.withLocalCompose(true);
8895
}
8996

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

94-
//@BeforeEach
101+
@BeforeEach
95102
void setup() {
96103
kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT);
97104
debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT);
98105
kafkaPort = COMPOSE.getServicePort("kafka", KAFKA_PORT);
99106
kafkaClient = new KafkaTestClient("localhost:" + kafkaPort);
100107
}
101108

102-
//@AfterEach
109+
@AfterEach
103110
void close() {
104111
if (kafkaClient != null) {
105112
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: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,25 @@
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;
3540

3641
import com.jayway.jsonpath.JsonPath;
3742

@@ -56,50 +61,49 @@ public class OutboxIT {
5661
private static final int DEBEZIUM_PORT = 8083;
5762

5863
//@Container
59-
private static DockerComposeContainer<?> COMPOSE;
64+
private static ComposeContainer COMPOSE;
6065

6166
private int kogitoPort;
6267
private int debeziumPort;
6368
private int kafkaPort;
6469

6570
private KafkaTestClient kafkaClient;
6671

67-
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");
72+
//@BeforeAll
73+
static void init() {
74+
Path path = Paths.get("../../docker-compose.yml");
75+
if (!path.toFile().exists()) {
76+
path = Paths.get("docker-compose.yml");
77+
}
78+
COMPOSE = new ComposeContainer(path.toFile());
79+
COMPOSE.withPull(false);
80+
COMPOSE.withServices("kafka", "mongodb", "connect", "sidecar", "kogito");
81+
COMPOSE.withExposedService("kogito", KOGITO_PORT);
82+
COMPOSE.withExposedService("kafka", KAFKA_PORT);
83+
COMPOSE.withExposedService("connect", DEBEZIUM_PORT);
84+
COMPOSE.withLogConsumer("kafka", logger());
85+
COMPOSE.withLogConsumer("connect", logger());
86+
COMPOSE.withLogConsumer("sidecar", logger());
87+
COMPOSE.withLogConsumer("kogito", logger());
88+
COMPOSE.waitingFor("kafka", Wait.forListeningPort());
89+
COMPOSE.waitingFor("sidecar", Wait.forListeningPort());
90+
COMPOSE.waitingFor("kogito", Wait.forListeningPort());
91+
COMPOSE.withLocalCompose(true);
8892
}
8993

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

94-
// @BeforeEach
98+
@BeforeEach
9599
void setup() {
96100
kogitoPort = COMPOSE.getServicePort("kogito", KOGITO_PORT);
97101
debeziumPort = COMPOSE.getServicePort("connect", DEBEZIUM_PORT);
98102
kafkaPort = COMPOSE.getServicePort("kafka", KAFKA_PORT);
99103
kafkaClient = new KafkaTestClient("localhost:" + kafkaPort);
100104
}
101105

102-
// @AfterEach
106+
@AfterEach
103107
void close() {
104108
if (kafkaClient != null) {
105109
kafkaClient.shutdown();

0 commit comments

Comments
 (0)