Guillaume Nodet created CAMEL-23214:
---------------------------------------

             Summary: Migrate AvailablePortFinder.getNextAvailable() to 
@RegisterExtension for proper port lifecycle
                 Key: CAMEL-23214
                 URL: https://issues.apache.org/jira/browse/CAMEL-23214
             Project: Camel
          Issue Type: Improvement
            Reporter: Guillaume Nodet
             Fix For: 4.19.0


There are 156 test files across the codebase using 
`AvailablePortFinder.getNextAvailable()` which allocates a port but never 
releases it. This causes port conflicts and flaky `BindException` failures in 
CI, especially during parallel test execution.

The fix is to migrate to `@RegisterExtension AvailablePortFinder.Port` which:
* Tracks the allocated port
* Auto-releases via `AfterAllCallback` when the test class completes
* Prevents port reuse conflicts between test classes

Top affected components by file count:
* camel-mllp (17 files)
* camel-grpc (14 files)
* camel-platform-http-vertx (12 files)
* camel-cometd (10 files)
* camel-thrift (9 files)
* camel-syslog (9 files)
* camel-jetty (9 files)
* camel-as2-component (8 files)
* camel-cxf-soap (6 files)
* camel-netty-http (5 files)
* camel-lumberjack (5 files)
* 50+ other components with 1-4 files each

Only 24 files have already been migrated to the new pattern.

This is a mechanical migration but requires care:
* Static field ports become instance fields with `@RegisterExtension`
* Port int references change to `port.getPort()` calls
* Field initializers using ports need to move to methods
* Some base test classes define shared ports



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to