Skip to content

feat: add getMappedPort(int, InternetProtocol) overload#11916

Open
glasses-and-hat wants to merge 1 commit into
testcontainers:mainfrom
glasses-and-hat:feat/get-mapped-port-protocol
Open

feat: add getMappedPort(int, InternetProtocol) overload#11916
glasses-and-hat wants to merge 1 commit into
testcontainers:mainfrom
glasses-and-hat:feat/get-mapped-port-protocol

Conversation

@glasses-and-hat

Copy link
Copy Markdown

Summary

  • Adds ContainerState#getMappedPort(int originalPort, InternetProtocol protocol), allowing the host-mapped port to be looked up for a specific protocol (TCP or UDP) instead of always assuming TCP.
  • The existing getMappedPort(int) now delegates to the new overload with InternetProtocol.TCP, so behavior is unchanged for existing callers.
  • This addresses containers that expose the same port number over both TCP and UDP (e.g. Jaeger's UDP ports), where the previous API could only ever resolve the TCP binding.

Fixes #554

Test plan

  • Added ContainerStateTest#getMappedPortDistinguishesTcpAndUdpBindingsForSamePort verifying TCP vs UDP bindings on the same port number resolve independently, and that getMappedPort(int) still defaults to TCP.
  • Added ContainerStateTest#getMappedPortThrowsWhenPortNotMappedForProtocol verifying the error message reflects the requested protocol when no binding exists.
  • ./gradlew :testcontainers:compileJava :testcontainers:compileTestJava succeeds.
  • ./gradlew :testcontainers:test --tests "org.testcontainers.containers.ContainerStateTest" passes (8/8).
  • ./gradlew :testcontainers:spotlessCheck passes.

Allows retrieving the host-mapped port for a container port that is
exposed over UDP (or explicitly over TCP) instead of always assuming
TCP, so containers that expose the same port number for both
protocols (e.g. Jaeger's UDP ports) can be queried unambiguously.

Fixes testcontainers#554
@glasses-and-hat glasses-and-hat requested a review from a team as a code owner July 6, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add getMappedPort(Integer originalPort, InternetProtocol protocol)

1 participant