gnodet-bot commented on code in PR #31136:
URL: https://github.com/apache/camel/pull/31136#discussion_r4743556342


##########
core/camel-core/src/test/java/org/apache/camel/component/seda/SedaConsumerVirtualMachineErrorTest.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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 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.
+ * <p>
+ * On current {@code main} this behaviour is already provided by the outer 
{@code catch (Throwable)} in
+ * {@code SedaConsumer.doRun()}, which was added by CAMEL-27515. This PR adds 
an inner {@code catch (Error)} at the call
+ * site of {@code processPolledExchange} as a defensiveness and clarity 
measure, handling the error adjacent to where it
+ * arises. The two behaviours are functionally equivalent for the synchronous 
path.
+ * <p>
+ * The inner {@code catch (Error)} also re-throws {@link VirtualMachineError} 
explicitly so that the outer
+ * {@code catch (VirtualMachineError)} calls {@code handleFatalError} and 
stops the consumer cleanly (CAMEL-27515).
+ */
+class SedaConsumerVirtualMachineErrorTest extends ContextTestSupport {
+
+    private static final AtomicInteger processedCount = new AtomicInteger();
+    private static final AtomicInteger callCount = new AtomicInteger();

Review Comment:
   ⚠️ **Test isolation:** `static` `AtomicInteger` fields are shared across all 
instances in the JVM. The `testConsumerSurvivesNonFatalError` body resets them 
with `.set(0)`, which handles sequential runs, but a parallel test touching the 
same statics would race with the reset. With a single `@Test` method here the 
practical risk is very low; instance fields are the conventional, safer choice:
   
   ```suggestion
       private final AtomicInteger processedCount = new AtomicInteger();
       private final AtomicInteger callCount = new AtomicInteger();
   ```
   
   You'd pass them into `faultyEndpoint()` as parameters (or capture via the 
outer-class `this`). The `.set(0)` calls in the test body can then be dropped.



-- 
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