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


##########
core/camel-core/src/test/java/org/apache/camel/component/timer/TimerNegativeDelayVirtualMachineErrorTest.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.timer;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Verifies that a VirtualMachineError (StackOverflowError) thrown in a timer 
route with a negative delay (executor
+ * path) is caught and logged, and that the route's fire loop terminates 
rather than propagating the error.
+ *
+ * @see <a 
href="https://issues.apache.org/jira/browse/CAMEL-27470";>CAMEL-27470</a>
+ */
+class TimerNegativeDelayVirtualMachineErrorTest extends ContextTestSupport {
+
+    /** Open once route A has thrown its Error, confirming the error was 
processed, not silently lost. */
+    private final CountDownLatch errorThrown = new CountDownLatch(1);
+
+    @Test
+    void negativeDelayRouteLoopTerminatesOnVirtualMachineError() throws 
InterruptedException {
+        // The executor path catches the Throwable: the loop must terminate 
and the
+        // latch must open. If the error propagated uncaught and killed the 
thread,
+        // the latch still opens because the lambda completes — so the main 
assertion
+        // is that this finishes in time (not that it hangs).
+        boolean thrown = errorThrown.await(5, TimeUnit.SECONDS);
+        assertTrue(thrown, "executor path must catch the StackOverflowError 
and not hang");
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("timer:negDelay?delay=-1&period=0&synchronous=true")
+                        .routeId("route-neg-delay")
+                        .process(exchange -> {
+                            errorThrown.countDown();
+                            throw new StackOverflowError("simulated 
StackOverflowError in negative-delay route");

Review Comment:
   ⚠️ **Test is tautological** — `errorThrown.countDown()` is called **before** 
the `throw`, so the latch opens regardless of whether the fix is in place or 
not. With or without the `catch (Throwable t)` block, the lambda body reaches 
`countDown()` before propagating the error. This test passes against the 
unfixed code, so it provides no regression safety for the executor path.
   
   PR [#30726](https://github.com/apache/camel/pull/30726) on `main` already 
recognized this and reworks the test to assert the ERROR log line instead 
(using `LogCaptureAppender`). Consider the same approach here, or at minimum 
move `countDown()` to after the throw (via a finally block or an 
`AtomicBoolean` set in the catch) so the latch only opens when the error is 
actually caught:
   
   ```suggestion
                               try {
                                   throw new StackOverflowError("simulated 
StackOverflowError in negative-delay route");
                               } catch (StackOverflowError e) {
                                   errorThrown.countDown();
                                   throw e;
                               }
   ```



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