Skip to content

Commit

Permalink
detect container startup with open ports
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge committed Nov 12, 2024
1 parent 83ad212 commit 3ab2f28
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
builder -> builder.from("apache/activemq-classic:5.18.6").build()))
.withEnv("JAVA_TOOL_OPTIONS", genericJmxJvmArguments(jmxPort))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forLogMessage(".*Apache ActiveMQ.*started.*", 1));
.withExposedPorts(61616, jmxPort)
.waitingFor(Wait.forListeningPorts(61616, jmxPort));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
// making cassandra startup faster for single node, from ~1min to ~15s
+ " -Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0")
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forLogMessage(".*Startup complete.*", 1));
.withExposedPorts(9042, jmxPort)
.waitingFor(Wait.forListeningPorts(9042, jmxPort));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
container
.withEnv("JAVA_OPTIONS", genericJmxJvmArguments(jmxPort))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forLogMessage(".*Started Server.*", 1));
.withExposedPorts(8080, jmxPort)
.waitingFor(Wait.forListeningPorts(8080, jmxPort));

return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@
import java.util.Arrays;
import java.util.List;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

public class JvmIntegrationTest extends TargetSystemIntegrationTest {

@Override
protected GenericContainer<?> createTargetContainer(int jmxPort) {
// reusing test application for JVM metrics and custom yaml
return new TestAppContainer().withJmxPort(jmxPort);
//noinspection resource
return new TestAppContainer()
.withJmxPort(jmxPort)
.withExposedPorts(jmxPort)
.waitingFor(Wait.forListeningPorts(jmxPort));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
.build()))
.withEnv("CATALINA_OPTS", genericJmxJvmArguments(jmxPort))
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forListeningPort());
.withExposedPorts(8080, jmxPort)
.waitingFor(Wait.forListeningPorts(8080, jmxPort));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected GenericContainer<?> createTargetContainer(int jmxPort) {
MountableFile.forHostPath(appWarPath),
"/opt/jboss/wildfly/standalone/deployments/testapp.war")
.withStartupTimeout(Duration.ofMinutes(2))
.waitingFor(Wait.forLogMessage(".*Http management interface listening on.*", 1));
.withExposedPorts(8080, 9990)
.waitingFor(Wait.forListeningPorts(8080, 9990));
}

@Override
Expand Down

1 comment on commit 3ab2f28

@robsunday
Copy link
Contributor

@robsunday robsunday commented on 3ab2f28 Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!
It would be even better if you define some constants with descriptive names, like for ActiveMQ
private static int DEFAULT_TCP_CONNECTION_LISTENING_PORT = 61616;

Please sign in to comment.