import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.shaded.org.awaitility.Awaitility;
import org.testcontainers.utility.DockerImageName;
{
Integer port = haproxy.getMappedPort(8400);
webTestClient = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
-
- Awaitility
- .await()
- .atMost(Duration.ofSeconds(15))
- .untilAsserted(() -> webTestClient
- .get()
- .uri("/actuator/health")
- .exchange()
- .expectStatus().isOk()
- .expectBody().jsonPath("$.status").isEqualTo("UP"));
}
Network network = Network.newNetwork();
- @Container
- GenericContainer haproxy =
- new GenericContainer(DockerImageName.parse("haproxytech/haproxy-debian:2.8"))
- .withNetwork(network)
- .withNetworkAliases("haproxy")
- .withClasspathResourceMapping(
- "haproxy.cfg",
- "/usr/local/etc/haproxy/haproxy.cfg",
- BindMode.READ_ONLY)
- .withClasspathResourceMapping(
- "sharding.map",
- "/usr/local/etc/haproxy/sharding.map",
- BindMode.READ_WRITE)
- .withExposedPorts(8400) // , 8401, 8404, 5555)
- .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("HAPROXY"));
-
@Container
KafkaContainer kafka =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0"))
.withListener(() -> "kafka:9999")
.withEnv("KAFKA_NUM_PARTITIONS", "10")
.withKraft()
+ .waitingFor(Wait.forLogMessage(".*Kafka Server started.*\\n", 1))
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("KAFKA"));
@Container
"--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
"--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
+ .dependsOn(kafka)
+ .waitingFor(Wait.forHttp("/actuator/health"))
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-1"));
@Container
"--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
"--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
+ .dependsOn(kafka)
+ .waitingFor(Wait.forHttp("/actuator/health"))
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-2"));
@Container
"--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
"--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
+ .dependsOn(kafka)
+ .waitingFor(Wait.forHttp("/actuator/health"))
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-3"));
+
+ @Container
+ GenericContainer haproxy =
+ new GenericContainer(DockerImageName.parse("haproxytech/haproxy-debian:2.8"))
+ .withNetwork(network)
+ .withNetworkAliases("haproxy")
+ .withClasspathResourceMapping(
+ "haproxy.cfg",
+ "/usr/local/etc/haproxy/haproxy.cfg",
+ BindMode.READ_ONLY)
+ .withClasspathResourceMapping(
+ "sharding.map",
+ "/usr/local/etc/haproxy/sharding.map",
+ BindMode.READ_WRITE)
+ .withExposedPorts(8400) // , 8401, 8404, 5555)
+ .dependsOn(backend_1, backend_2, backend_3)
+ .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("HAPROXY"));
}