Skip to content

Commit

Permalink
Handle container start failures more gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
tishun committed Nov 7, 2024
1 parent 7cfbbfc commit 6cf01e6
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.containers.output.OutputFrame;
import org.testcontainers.containers.wait.strategy.Wait;
Expand All @@ -25,6 +26,8 @@ public class RedisContainerIntegrationTests {

private static final String REDIS_STACK_CLUSTER = "clustered-stack";

private static Exception initializationException;

public static ComposeContainer CLUSTERED_STACK = new ComposeContainer(
new File("src/test/resources/docker/docker-compose.yml")).withExposedService(REDIS_STACK_CLUSTER, 36379)
.withExposedService(REDIS_STACK_CLUSTER, 36380).withExposedService(REDIS_STACK_CLUSTER, 36381)
Expand All @@ -41,7 +44,18 @@ public class RedisContainerIntegrationTests {

CLUSTERED_STACK.waitingFor(REDIS_STACK_CLUSTER,
Wait.forLogMessage(".*Background RDB transfer terminated with success.*", 1));
CLUSTERED_STACK.start();
try {
CLUSTERED_STACK.start();
} catch (Exception e) {
initializationException = e;
}
}

@BeforeAll
public static void checkContainerInitialization() {
if (initializationException != null) {
throw new IllegalStateException("Failed to initialize containers", initializationException);
}
}

}

0 comments on commit 6cf01e6

Please sign in to comment.