gnodet-bot commented on code in PR #30713: URL: https://github.com/apache/camel/pull/30713#discussion_r4679825276
########## 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: The latch is counted down **before** the `StackOverflowError` is thrown, so `await()` returns `true` regardless of whether the `catch (Throwable)` block in the executor path actually fires. Trace: 1. lambda calls `errorThrown.countDown()` → latch opens 2. lambda throws `StackOverflowError` 3. test's `await()` already returned `true` at step 1 — the catch block may or may not have run Without the fix (SOE escapes uncaught and kills the executor thread), `countDown()` already completed before the throw, so the test still passes. The test comment even acknowledges: *"the latch still opens because the lambda completes"* — which means the assertion does not distinguish caught vs uncaught. The `TimerVirtualMachineErrorTest` (the shared-timer test) is properly validated because route B can only fire if the shared Timer thread survived. This test lacks an equivalent structural check. To make this test meaningful, the latch (or an alternative signal) should only open from inside the `catch` block — for example by using a log capture to assert the ERROR message was emitted, or by verifying the executor thread is still alive after the error (possible if the executor is exposed for test inspection). -- 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]
