Skip to content

Commit 7f709cb

Browse files
kwartkiview
andauthored
Update Javadoc to highlight the potentially stale behavior of getMappedPort (#6303)
Co-authored-by: Kevin Wittek <[email protected]>
1 parent f591ac7 commit 7f709cb

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core/src/main/java/org/testcontainers/containers/ContainerState.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ default boolean isHealthy() {
119119
}
120120
}
121121

122+
/**
123+
* Inspects the container and returns up-to-date inspection response.
124+
*
125+
* @return up-to-date container inspect response
126+
* @see #getContainerInfo()
127+
*/
122128
default InspectContainerResponse getCurrentContainerInfo() {
123129
return getDockerClient().inspectContainerCmd(getContainerId()).exec();
124130
}
@@ -140,10 +146,16 @@ default Integer getFirstMappedPort() {
140146

141147
/**
142148
* Get the actual mapped port for a given port exposed by the container.
143-
* Should be used in conjunction with {@link #getHost()}.
149+
* It should be used in conjunction with {@link #getHost()}.
150+
* <p>
151+
* Note: The returned port number might be outdated (for instance, after disconnecting from a network and reconnecting
152+
* again). If you always need up-to-date value, override the {@link #getContainerInfo()} to return the
153+
* {@link #getCurrentContainerInfo()}.
144154
*
145155
* @param originalPort the original TCP port that is exposed
146156
* @return the port that the exposed port is mapped to, or null if it is not exposed
157+
* @see #getContainerInfo()
158+
* @see #getCurrentContainerInfo()
147159
*/
148160
default Integer getMappedPort(int originalPort) {
149161
Preconditions.checkState(
@@ -222,7 +234,10 @@ default String getContainerId() {
222234
}
223235

224236
/**
237+
* Returns the container inspect response. The response might be cached/outdated.
238+
*
225239
* @return the container info
240+
* @see #getCurrentContainerInfo()
226241
*/
227242
InspectContainerResponse getContainerInfo();
228243

0 commit comments

Comments
 (0)