[Feature]: Add a method to GenericContainer
to expose a random container port with the same number as the host port
#9553
Labels
Module
Core
Problem
org.testcontainers.containers.FixedHostPortGenericContainer
. For HiveServer2 with Zookeeper service discovery enabled, there are similar operations as follows.org.apache.curator.test.InstanceSpec#getRandomPort()
is to get a random host port. This can sometimes conflict with the port in the container.org.testcontainers.containers.FixedHostPortGenericContainer
to use a random numeric port both on the host, inside the container, and in the container's environment variables.Solution
GenericContainer
to expose the same host port number on a random container port. If this method is calledorg.testcontainers.containers.GenericContainer#withRandomExposedPorts()
, it can expose a random container port. And allow the host to obtain this port number throughorg.testcontainers.containers.GenericContainer#getFirstMappedPort()
, then the use oforg.testcontainers.containers.FixedHostPortGenericContainer
can obviously be simplified to,Benefit
Alternatives
org.testcontainers.containers.FixedHostPortGenericContainer
can indeed directly solve the current issue, which is what Support connecting to HiveServer2 with ZooKeeper Service Discovery enabled in GraalVM Native Image apache/shardingsphere#33768 and Improve GraalVM Reachability Metadata and corresponding nativeTest related unit tests apache/shardingsphere#29052 are doing.org.testcontainers.containers.FixedHostPortGenericContainer
has been deprecated.Would you like to help contributing this feature?
No
The text was updated successfully, but these errors were encountered: