apupier opened a new pull request, #28676:
URL: https://github.com/apache/camel/pull/28676

   Root cause
   ----------
   CXFTestSupport holds 8 static final AvailablePortFinder.Port fields 
(PORT1-PORT7, SSL_PORT) allocated once at JVM class-load time. Every test class 
that calls CXFTestSupport.getPort1() etc. gets the *same* integer, so when 
Maven Surefire runs test classes concurrently they all attempt to bind the same 
port simultaneously, causing:
   
     org.apache.cxf.service.factory.ServiceConstructionException:
       There is an endpoint already running on http://localhost:47767/...
     java.net.BindException: Address already in use
   
   Reproduction
   ------------
   Added junit-platform.properties (not committed) to both 
camel-cxf-rest/src/test/resources/ and
   camel-cxf-soap/src/test/resources/ with:
   
     junit.jupiter.execution.parallel.enabled=true
     junit.jupiter.execution.parallel.mode.classes.default=concurrent
     junit.jupiter.execution.parallel.config.fixed.parallelism=4
   
   Then ran:
     mvn test -pl "components/camel-cxf/camel-cxf-rest,\
                  components/camel-cxf/camel-cxf-soap" -T1C
   
   Before fix: 4/20 runs failed (20% failure rate) with BindException.
   After fix:  0/20 runs failed (verified across 20 consecutive runs).
   
   Fix
   ---
   Replace every CXFTestSupport.getPortX() call with a per-class 
@RegisterExtension AvailablePortFinder.Port field so each test-class instance 
reserves its own unique port:
   
   * Standalone leaf classes  -> @RegisterExtension static final Port PORT (one 
allocation per class, safe for concurrent forks)
   
   * Parent classes whose subclasses use getClass().getSimpleName() in the URL 
(CxfSimpleRouterTest, CxfConsumerMessageTest, CxfConsumerPayloadFaultTest, 
CxfConsumerStreamCacheTest, CxfCustomizedExceptionTest, 
CxfPayLoadSoapHeaderTestAbstract, CXFWsdlOnlyPayloadModeNoSpringTest, 
CxfProducerTest, CxfSchemaValidationTest) -> @RegisterExtension final Port port 
(instance field - each subclass instance gets its own port)
   
   Readability improvements (no functional change)
   -----------------------------------------------
   * Removed dead int-shim fields (legacy portN = PORT.getPort() helpers left 
over from migration) in CxfJavaOnlyPayloadModeTest, 
CxfJavaOnlyCamelContextAwareTest, LoadDistributorFeatureTest.
   
   * Renamed opaque PORT_2/PORT_3/PORT_4 to semantic names:
     - FailOverFeatureTest:      PORT -> SERVICE_PORT,
                                  PORT_2 -> PAYLOAD_PROXY_PORT,
                                  PORT_3 -> POJO_PROXY_PORT,
                                  PORT_4 -> NONE_EXIST_PORT
     - LoadDistributorFeatureTest: PORT -> SERVICE_PORT,
                                    PORT_2 -> PAYLOAD_PROXY_PORT,
                                    PORT_3 -> POJO_PROXY_PORT
   
   * Extracted repeated URL literals to named constants:
     - CxfRsConsumerSimpleBindingTest: BASE_URL (was repeated 11 times)
     - CxfRsConvertBodyToTest: REST/STATUS/EMPTY _ENDPOINT_URI and 
REST/STATUS/EMPTY _TEST_URL constants (deduplicated from both 
createRouteBuilder() and individual test methods)
   
   Changed files (45 total)
   ------------------------
   camel-cxf-rest (12 test classes):
     CxfRsStreamCacheTest, CxfRsResponseWithHeadersTest,
     CxfRsConsumerWithBeanTest, CxfRsConvertBodyToTest,
     CxfRsConsumerSuspendTest, CxfRsConsumerClientDisconnectedTest,
     CxfRsStreamCacheContentTypeTest, CxfRsProducerHttpMethodHeaderTest,
     CxfRsProducerParameterParsingTest,
     CxfRsBindingConfigurationSelectionTest,
     simplebinding/CxfRsConsumerSimpleBindingTest,
     simplebinding/CxfRsConsumerSimpleBindingImplTest
   
   camel-cxf-soap (33 test classes):
     CxfSimpleRouterTest, CxfConsumerTest, CxfConsumerMessageTest,
     CxfConsumerResponseTest, CxfConsumerProviderTest,
     CxfConsumerContinuationTimeoutTest, 
CxfConsumerPayloadXPathClientServerTest,
     CxfConsumerStreamCacheTest, CxfConsumerSuspendTest,
     CxfConsumerClientDisconnectedTest, CxfConsumerStartTwiceTest,
     CxfConsumerMuteExceptionTest, CxfConsumerPayloadFaultTest,
     CxfCustomizedExceptionTest, CxfPayLoadSoapHeaderTestAbstract,
     CXFWsdlOnlyPayloadModeNoSpringTest,
     CXFWsdlOnlyPayloadModeMultiPartNoSpringTest,
     CxfMultipleConsumersSupportTest, CxfMixedModeRouterTest,
     CxfProducerTest, CxfProducerContextTest,
     CxfProducerRouterTest, CxfProducerSoapFaultTest,
     CxfProducerSynchronousTest, CxfProducerSynchronousFalseTest,
     CxfProducerSessionTest, CxfJavaOnlyPayloadModeTest,
     CxfJavaOnlyCamelContextAwareTest,
     JaxWsWebFaultAnnotationToFaultTest, CxfSchemaValidationTest,
     FailOverFeatureTest, LoadDistributorFeatureTest,
     holder/CxfHolderConsumerTest
   
   Co-authored-by: IBM Bob 2.2.1
   
   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other 
small items do not require a JIRA issue. In this case your pull request should 
address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful 
subject line and body.
   
   <!--
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] 
Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the 
appropriate JIRA issue.
   -->
   
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   <!--
   You can run the aforementioned command in your module so that the build 
auto-formats your code. This will also be verified as part of the checks and 
your PR may be rejected if if there are uncommited changes after running `mvn 
clean install -DskipTests`.
   
   You can learn more about the contribution guidelines at 
https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   # AI-assisted contributions
   
   - [ ] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to