Skip to content
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 @@ -22,6 +22,7 @@ public final class Labels {

public static final String COMPOSE_WAIT_FOR = QUARKUS_COMPOSE_PREFIX + ".wait_for";
public static final String COMPOSE_WAIT_FOR_LOGS = COMPOSE_WAIT_FOR + ".logs";
public static final String COMPOSE_WAIT_FOR_LOGS_TIMEOUT = COMPOSE_WAIT_FOR_LOGS + ".timeout";
public static final String COMPOSE_WAIT_FOR_PORTS = COMPOSE_WAIT_FOR + ".ports";
public static final String COMPOSE_WAIT_FOR_PORTS_DISABLE = COMPOSE_WAIT_FOR_PORTS + ".disable";
public static final String COMPOSE_WAIT_FOR_PORTS_TIMEOUT = COMPOSE_WAIT_FOR_PORTS + ".timeout";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,20 @@ private void registerWaitStrategies(ComposeFiles composeFiles,
// Add wait for log message
if (e.getKey().startsWith(COMPOSE_WAIT_FOR_LOGS)) {
int times = 1;
if (COMPOSE_WAIT_FOR_LOGS_TIMEOUT.equals(e.getKey())) {
continue;
}
if (e.getKey().length() > COMPOSE_WAIT_FOR_LOGS.length()) {
try {
times = Integer.parseInt(e.getKey().replace(COMPOSE_WAIT_FOR_LOGS + ".", ""));
} catch (NumberFormatException t) {
LOG.warnv("Cannot parse label `{}`", e.getKey());
}
}
addWaitStrategy(waitStrategies, serviceName, Wait.forLogMessage((String) e.getValue(), times));
String waitForTimeout = (String) labels.get(COMPOSE_WAIT_FOR_LOGS_TIMEOUT);
Duration timeout = waitForTimeout != null ? Duration.parse("PT" + waitForTimeout) : startupTimeout;
addWaitStrategy(waitStrategies, serviceName, Wait.forLogMessage((String) e.getValue(), times)
.withStartupTimeout(timeout));
}
}
// Add wait for port availability
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void testValidComposeFileParsing() {
assertNotNull(db);
assertEquals("db", db.getServiceName());
assertEquals("database system is ready to accept connections",
db.getLabels().get("io.quarkus.devservices.compose.wait_for.logs"));
db.getLabels().get("io.quarkus.devservices.compose.wait_for.logs.2"));
assertFalse(db.hasHealthCheck());

// Test Redis service
Expand Down Expand Up @@ -91,7 +91,7 @@ void testServiceDefinitionExtraction() {
// Test labels
Map<String, Object> labels = db.getLabels();
assertEquals("database system is ready to accept connections",
labels.get("io.quarkus.devservices.compose.wait_for.logs"));
labels.get("io.quarkus.devservices.compose.wait_for.logs.2"));

// Test container name (should be null for valid compose)
assertNull(db.getContainerName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.lang.reflect.Field;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;
import org.testcontainers.containers.wait.strategy.WaitAllStrategy;
import org.testcontainers.containers.wait.strategy.WaitStrategy;

public class ComposeProjectTest {

Expand All @@ -36,11 +40,45 @@ void testBasicProject() {
assertTrue(waitStrategies.containsKey("db"));
assertTrue(waitStrategies.containsKey("redis"));

// check wait strategy startup times
WaitAllStrategy db = waitStrategies.get("db");
List<WaitStrategy> strategies = getChildStrategies(db);
assertEquals(1, strategies.size());
Duration startupTimeout = getStartupTimeout(strategies.get(0));
assertEquals(Duration.of(10, ChronoUnit.SECONDS), startupTimeout);

WaitAllStrategy redis = waitStrategies.get("redis");
strategies = getChildStrategies(redis);
assertEquals(2, strategies.size());
for (WaitStrategy strategy : strategies) {
assertEquals(Duration.of(2, ChronoUnit.MINUTES), getStartupTimeout(strategy));
}

// Verify project name
String project = composeProject.getProject();
assertEquals("test", project);
}

private static Duration getStartupTimeout(WaitStrategy waitStrategy) {
try {
Field startupTimeout = AbstractWaitStrategy.class.getDeclaredField("startupTimeout");
startupTimeout.setAccessible(true);
return (Duration) startupTimeout.get(waitStrategy);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

private static List<WaitStrategy> getChildStrategies(WaitAllStrategy db) {
try {
Field strategies = WaitAllStrategy.class.getDeclaredField("strategies");
strategies.setAccessible(true);
return (List) strategies.get(db);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}

@Test
void testProjectWithWaitStrategies() {
ComposeFiles files = new ComposeFiles(List.of(composeFileWithProfiles));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ services:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
labels:
io.quarkus.devservices.compose.wait_for.logs: "database system is ready to accept connections"
io.quarkus.devservices.compose.wait_for.logs.2: "database system is ready to accept connections"
io.quarkus.devservices.compose.wait_for.logs.timeout: 10s
io.quarkus.devservices.compose.wait_for.ports.disable: true

redis:
image: redis:6
ports:
- "6379:6379"
labels:
io.quarkus.devservices.compose.wait_for.logs: "The server is now ready to accept connections"

kafka:
profiles:
Expand Down
Loading