From 46eb5b7be173becc1fa7a742e3de7860b27b1623 Mon Sep 17 00:00:00 2001 From: Huba Peter Date: Wed, 6 Jul 2022 16:23:04 +0300 Subject: [PATCH] Fix testing guide's example for Testcontainers Fixes quarkusio#26573 If container.start() is missing, it will fail with "java.lang.IllegalStateException: Mapped port can only be obtained after the container is started", or can get a NPE at a later phase of execution, if no call to retrieving port info is made --- docs/src/main/asciidoc/getting-started-testing.adoc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/src/main/asciidoc/getting-started-testing.adoc b/docs/src/main/asciidoc/getting-started-testing.adoc index 1528abf6eb1fa..0f532813fdb65 100644 --- a/docs/src/main/asciidoc/getting-started-testing.adoc +++ b/docs/src/main/asciidoc/getting-started-testing.adoc @@ -1317,6 +1317,9 @@ public class CustomResource implements QuarkusTestResourceLifecycleManager, DevS // apply the network to the container containerNetworkId.ifPresent(container::withNetworkMode); + // start container before retrieving its URL or other properties + container.start(); + String jdbcUrl = container.getJdbcUrl(); if (containerNetworkId.isPresent()) { // Replace hostname + port in the provided JDBC URL with the hostname of the Docker container