This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 1b84527b4940 CAMEL-26629: Try to stabilize
JettyHttpEndpointDisconnectTest (#29227)
1b84527b4940 is described below
commit 1b84527b494016a6188f735c416fe5acbc24434d
Author: Aurélien Pupier <[email protected]>
AuthorDate: Fri Nov 6 10:28:58 2026 +0100
CAMEL-26629: Try to stabilize JettyHttpEndpointDisconnectTest (#29227)
JettyHttpEndpointDisconnectTest asserted that the static
JettyHttpComponent.CONNECTORS map was completely empty after
context.stop(). That map is shared by the whole JVM and camel-jetty runs
its tests in parallel, so a connector left behind by another test class
could make this test fail even though its own connector was removed
correctly (reported failure: "Connector should have been removed",
expected 0 but was 1, on a port possibly not owned by this test).
Only assert that the connector of this test (http:localhost:<port>) has
been removed, and keep reporting its creation stack trace on failure.
Also log, at debug level, the connectors left behind by other tests with
their creation stack trace, to help finding which test leaks them.
This is an attempt to stabilize the test and not a sure fix: the root
cause of the leftover connector was not confirmed. If the failure was a
real leak of this test's own connector, the assertion still catches it.
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../jetty/JettyHttpEndpointDisconnectTest.java | 45 +++++++++++++++-------
.../src/test/resources/log4j2.properties | 2 +
2 files changed, 34 insertions(+), 13 deletions(-)
diff --git
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
index 41cb338d5691..bf64dfd40e35 100644
---
a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
+++
b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpEndpointDisconnectTest.java
@@ -21,8 +21,10 @@ import
org.apache.camel.component.jetty12.JettyHttpComponent12;
import org.apache.camel.support.ExceptionHelper;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Isolated;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
/**
* Unit test to verify that the Jetty HTTP connector is correctly disconnected
on shutdown
@@ -30,28 +32,45 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
@Isolated
public class JettyHttpEndpointDisconnectTest extends BaseJettyTest {
+ private static final Logger LOG =
LoggerFactory.getLogger(JettyHttpEndpointDisconnectTest.class);
+
private final String serverUri = "http://localhost:" + getPort() +
"/myservice";
@Test
public void testContextShutdownRemovesHttpConnector() {
context.stop();
- assertEquals(0, JettyHttpComponent.CONNECTORS.size(),
+ // only check the connector of this test, as the connectors are static
and a connector
+ // left behind by another test in the same JVM must not make this test
fail
+ String connectorKey = "http:localhost:" + getPort();
+ logOtherConnectors(connectorKey);
+ assertFalse(JettyHttpComponent.CONNECTORS.containsKey(connectorKey),
() -> {
- StringBuilder sb = new StringBuilder("Connector should
have been removed\n");
- for (String key : JettyHttpComponent.CONNECTORS.keySet()) {
- Throwable t =
JettyHttpComponent12.connectorCreation.get(key);
- if (t == null) {
- t = new Throwable("Unable to find connector
creation");
- }
-
- final String stackTrace =
ExceptionHelper.stackTraceToString(t);
-
- sb.append(key).append(": ").append(stackTrace);
+ Throwable t =
JettyHttpComponent12.connectorCreation.get(connectorKey);
+ if (t == null) {
+ t = new Throwable("Unable to find connector creation");
}
- return sb.toString();
+ return "Connector should have been removed\n" +
connectorKey + ": "
+ + ExceptionHelper.stackTraceToString(t);
});
}
+ /**
+ * Logs the connectors still registered that do not belong to this test,
with where they were created, to help
+ * finding which test leaks them.
+ */
+ private void logOtherConnectors(String connectorKey) {
+ if (!LOG.isDebugEnabled()) {
+ return;
+ }
+ for (String key : JettyHttpComponent.CONNECTORS.keySet()) {
+ if (!key.equals(connectorKey)) {
+ Throwable t = JettyHttpComponent12.connectorCreation.get(key);
+ LOG.debug("Connector left behind by another test: {}, created
at: {}", key,
+ t != null ? ExceptionHelper.stackTraceToString(t) :
"unknown");
+ }
+ }
+ }
+
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
diff --git a/components/camel-jetty/src/test/resources/log4j2.properties
b/components/camel-jetty/src/test/resources/log4j2.properties
index c0a840da371a..84bbc25c1587 100644
--- a/components/camel-jetty/src/test/resources/log4j2.properties
+++ b/components/camel-jetty/src/test/resources/log4j2.properties
@@ -26,3 +26,5 @@ appender.out.layout.type = PatternLayout
appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
rootLogger.level = INFO
rootLogger.appenderRef.file.ref = file
+logger.disconnect.name =
org.apache.camel.component.jetty.JettyHttpEndpointDisconnectTest
+logger.disconnect.level = DEBUG