This is an automated email from the ASF dual-hosted git repository.

apupier 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 7f4c7ee5b526 CAMEL-25891: camel-spring-xml - register a seda component 
polling every 10 ms in the tests
7f4c7ee5b526 is described below

commit 7f4c7ee5b526dc0fc676a7cf6103061838a35863
Author: AurĂ©lien Pupier <[email protected]>
AuthorDate: Tue Nov 10 09:24:04 2026 +0100

    CAMEL-25891: camel-spring-xml - register a seda component polling every 10 
ms in the tests
    
    Follow-up of CAMEL-25891 work on the duration of the camel-spring-xml tests,
    after #29515 (tests safe to run in parallel in the same JVM) and #29518 
(SEDA
    consumers poll faster in tests created with SpringTestHelper), both merged.
    
    A seda consumer blocks in queue.poll(pollTimeout), 1000 ms by default, and
    stopping a CamelContext waits for the consumer thread to leave that poll. A
    test stopping a context with seda routes therefore spends up to a second per
    route in its shutdown, for example "shutdown in 1s0ms" for ErrorHandlerTest.
    
    #29518 set the default poll timeout of the seda component to 10 ms for the
    contexts created with SpringTestHelper, but it cannot work for the roughly 
186
    tests extending SpringTestSupport (and the other tests building their 
context
    from a Spring XML file): their CamelContext is started when the Spring 
context
    is refreshed, so the seda endpoints are created, with the default of 1000 
ms,
    before SpringTestSupport.createCamelContext() gets the component to change 
it.
    A probe on errorHandler.xml confirmed it: the component default was 10 but 
the
    endpoint poll timeout was 1000. Starting the context later instead 
(setNoStart
    during the refresh) breaks the tests relying on the start with the Spring
    refresh event, such as EventRouteTest and MistypedPackageTest.
    
    Instead of changing the component once the context exists, register in the
    test resources a "seda" component whose default poll timeout is 10 ms
    (FastPollSedaComponent, via 
META-INF/services/org/apache/camel/component/seda
    that hides the one of camel-seda), so that it is already in place when the
    endpoints are created, whatever the way the context is started. The explicit
    setDefaultPollTimeout(10) calls of SpringTestSupport and SpringTestHelper
    become redundant and are removed, to have a single place for this setting.
    
    Results on camel-spring-xml (1186 tests, 4 forks, sequential, same machine,
    runs done one after the other):
    - wall time: 106 s and 107 s before, 93 s and 93 s after
    - total time of the context shutdowns: 54 s before, 19 s after
    - context shutdowns taking 1 s or more: 36 (52 s) before, 12 (17 s) after
    
    Co-authored-by: IBM Bob 2.2.1
    Signed-off-by: AurĂ©lien Pupier <[email protected]>
---
 .../org/apache/camel/spring/SpringTestSupport.java |  7 ++--
 .../camel/spring/processor/SpringTestHelper.java   |  4 ---
 .../spring/support/FastPollSedaComponent.java      | 38 ++++++++++++++++++++++
 .../services/org/apache/camel/component/seda       | 17 ++++++++++
 4 files changed, 57 insertions(+), 9 deletions(-)

diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringTestSupport.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringTestSupport.java
index af2e4e7f7633..a3edbf6fdd72 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringTestSupport.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/SpringTestSupport.java
@@ -28,7 +28,6 @@ import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.component.seda.SedaComponent;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.support.scan.AssignableToPackageScanFilter;
 import org.apache.camel.support.scan.DefaultPackageScanClassResolver;
@@ -160,10 +159,8 @@ public abstract class SpringTestSupport extends 
ContextTestSupport {
     @SuppressWarnings("deprecation")
     @Override
     protected CamelContext createCamelContext() throws Exception {
-        CamelContext context = 
SpringCamelContext.springCamelContext(applicationContext, true);
-        // make SEDA run faster
-        context.getComponent("seda", 
SedaComponent.class).setDefaultPollTimeout(10);
-        return context;
+        // SEDA runs faster in these tests, see FastPollSedaComponent
+        return SpringCamelContext.springCamelContext(applicationContext, true);
     }
 
     public ObjectName getContextObjectName() throws 
MalformedObjectNameException {
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTestHelper.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTestHelper.java
index a51d5c6b1988..f54817431067 100644
--- 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTestHelper.java
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringTestHelper.java
@@ -22,7 +22,6 @@ import java.util.Map;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Service;
-import org.apache.camel.component.seda.SedaComponent;
 import org.apache.camel.impl.DefaultCamelContext;
 import org.apache.camel.spring.SpringCamelContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -73,9 +72,6 @@ public final class SpringTestHelper {
         }
         
context.getCamelContextExtension().getRegistry().bind(PROPERTY_TEST_DIR, 
test.testDirectory());
         context.getPropertiesComponent().addInitialProperty(PROPERTY_TEST_DIR, 
test.testDirectory().toString());
-        // make SEDA run faster: it must be set before the context is started, 
as the consumers use it to poll their queue
-        // and the shutdown has to wait up to this time for them
-        context.getComponent("seda", 
SedaComponent.class).setDefaultPollTimeout(10);
         if (!isNoStart) {
             context.start();
         }
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/support/FastPollSedaComponent.java
 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/support/FastPollSedaComponent.java
new file mode 100644
index 000000000000..315ec57eb54f
--- /dev/null
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/java/org/apache/camel/spring/support/FastPollSedaComponent.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spring.support;
+
+import org.apache.camel.component.seda.SedaComponent;
+import org.apache.camel.spi.annotations.Component;
+
+/**
+ * A {@link SedaComponent} for the tests, which polls its queue every 10 ms 
instead of every 1000 ms.
+ * <p/>
+ * A seda consumer blocks in the poll of its queue, and stopping a 
CamelContext waits for the consumer to leave it, so
+ * with the default each test stopping a context with a seda route spends up 
to a second in its shutdown. The seda
+ * endpoints are created with the default of the component, so it has to be 
set before they are created: the
+ * CamelContext of a Spring XML test is started when the Spring context is 
refreshed, before the test support can
+ * configure the component. It is therefore registered as the "seda" component 
with
+ * {@code META-INF/services/org/apache/camel/component/seda} of the test 
resources, which hides the one of camel-seda.
+ */
+@Component("seda")
+public class FastPollSedaComponent extends SedaComponent {
+
+    public FastPollSedaComponent() {
+        setDefaultPollTimeout(10);
+    }
+}
diff --git 
a/components/camel-spring-parent/camel-spring-xml/src/test/resources/META-INF/services/org/apache/camel/component/seda
 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/META-INF/services/org/apache/camel/component/seda
new file mode 100644
index 000000000000..bf5d2865cf9c
--- /dev/null
+++ 
b/components/camel-spring-parent/camel-spring-xml/src/test/resources/META-INF/services/org/apache/camel/component/seda
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+class=org.apache.camel.spring.support.FastPollSedaComponent

Reply via email to