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 2c63c7b931a1 CAMEL-27471: add regression test for SEDA consumer 
surviving non-fatal Error (#31136)
2c63c7b931a1 is described below

commit 2c63c7b931a13087d2a4fa68cc3a1a0dd8204958
Author: Guillaume Nodet <[email protected]>
AuthorDate: Tue Dec 1 09:23:57 2026 +0100

    CAMEL-27471: add regression test for SEDA consumer surviving non-fatal 
Error (#31136)
    
    …l Error
    
    Add SedaConsumerNonFatalErrorTest to document and validate that the SEDA 
consumer
    thread survives a non-fatal Error (e.g. AssertionError) thrown during 
exchange
    processing. The consumer must pass the error to the exception handler and 
continue
    draining the queue.
    
    The production fix for the original thread-death was delivered by 
CAMEL-27515 (#30739),
    which added an outer catch (Throwable) inside the while loop. This test 
validates and
    documents that behaviour.
    
    Closes CAMEL-27471
    
    Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
 .../seda/SedaConsumerNonFatalErrorTest.java        | 114 +++++++++++++++++++++
 1 file changed, 114 insertions(+)

diff --git 
a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerNonFatalErrorTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerNonFatalErrorTest.java
new file mode 100644
index 000000000000..cdddc5fe8819
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerNonFatalErrorTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.component.seda;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Tests that the SEDA consumer handles non-fatal errors thrown during 
exchange processing correctly (CAMEL-27471).
+ * <p>
+ * The desired behaviour: a non-fatal {@code Error} (e.g. {@link 
AssertionError}) thrown by route code must NOT kill the
+ * consumer thread. The consumer must pass it to the exception handler and 
continue draining the queue.
+ */
+class SedaConsumerNonFatalErrorTest extends ContextTestSupport {
+
+    private final AtomicInteger processedCount = new AtomicInteger();
+    private final AtomicInteger callCount = new AtomicInteger();
+
+    private SedaEndpoint faultyEndpoint(String uri, Component component, int 
consumers, Error errorToThrow) {
+        return new SedaEndpoint(uri, component, new 
LinkedBlockingQueueFactory<>(), consumers) {
+            @Override
+            protected SedaConsumer createNewConsumer(Processor processor) {
+                return new SedaConsumer(this, processor) {
+                    @Override
+                    protected void processPolledExchange(Exchange exchange) {
+                        if (callCount.getAndIncrement() == 0) {
+                            throw errorToThrow;
+                        }
+                        processedCount.incrementAndGet();
+                    }
+                };
+            }
+        };
+    }
+
+    /**
+     * A non-fatal {@link Error} (e.g. {@link AssertionError}) thrown by route 
code must NOT kill the consumer thread.
+     * The consumer catches it via the exception handler and continues 
draining the queue.
+     */
+    @Test
+    void testConsumerSurvivesNonFatalError() throws Exception {
+        // Send 5 messages; the consumer throws AssertionError on the first 
and counts the rest
+        for (int i = 0; i < 5; i++) {
+            template.sendBody("seda:in", "msg" + i);
+        }
+
+        // Consumer must continue after the AssertionError and drain the 
remaining 4 exchanges
+        await().atMost(10, TimeUnit.SECONDS).until(() -> processedCount.get() 
>= 4);
+
+        assertEquals(4, processedCount.get(),
+                "Consumer thread must survive AssertionError and drain the 
remaining 4 exchanges");
+        assertEquals(0, context.getEndpoint("seda:in", 
SedaEndpoint.class).getQueue().size(),
+                "SEDA queue must be empty after all exchanges are consumed");
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext ctx = super.createCamelContext();
+        ctx.addComponent("seda", new SedaComponent() {
+            @Override
+            protected SedaEndpoint createEndpoint(
+                    String endpointUri, Component component,
+                    BlockingQueueFactory<Exchange> queueFactory, int 
concurrentConsumers) {
+                return faultyEndpoint(endpointUri, component, 
concurrentConsumers,
+                        new AssertionError("simulated non-fatal Error for 
CAMEL-27471"));
+            }
+
+            @Override
+            protected SedaEndpoint createEndpoint(
+                    String endpointUri, Component component,
+                    BlockingQueue<Exchange> queue, int concurrentConsumers) {
+                return faultyEndpoint(endpointUri, component, 
concurrentConsumers,
+                        new AssertionError("simulated non-fatal Error for 
CAMEL-27471"));
+            }
+        });
+        return ctx;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("seda:in").to("mock:result");
+            }
+        };
+    }
+}

Reply via email to