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 f3656061b1ea CAMEL-25001: camel-core - Supervising route controller: 
an exhausted route stays unhealthy after it is started manually (#26859)
f3656061b1ea is described below

commit f3656061b1ea0e6c303281c344d6244fd28aec9e
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Sep 27 10:10:44 2026 +0200

    CAMEL-25001: camel-core - Supervising route controller: an exhausted route 
stays unhealthy after it is started manually (#26859)
    
    A manual start or stop of a supervised route takes it over from the
    supervisor, and already cancels a pending restart and clears the last
    restart exception. It now also removes the route from the exhausted
    routes, so a route started manually after its restarts were exhausted
    is no longer reported as exhausted and unhealthy.
    
    Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
    Signed-off-by: Claus Ibsen <[email protected]>
---
 .../engine/DefaultSupervisingRouteController.java  |   2 +
 ...pervisingRouteControllerExhaustedStartTest.java | 105 +++++++++++++++++++++
 2 files changed, 107 insertions(+)

diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java
index 3167772b362b..0e21c2a19079 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultSupervisingRouteController.java
@@ -750,6 +750,8 @@ public class DefaultSupervisingRouteController extends 
DefaultRouteController im
 
         boolean release(RouteHolder route) {
             exceptions.remove(route.getId());
+            // the route is now managed manually, so it is no longer exhausted 
(and unhealthy) if it was
+            exhausted.remove(route);
             BackOffTimer.Task task = routes.remove(route);
             if (task != null) {
                 LOG.debug("Cancelling restart task for route: {}", 
route.getId());
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultSupervisingRouteControllerExhaustedStartTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultSupervisingRouteControllerExhaustedStartTest.java
new file mode 100644
index 000000000000..e8b0ed877a07
--- /dev/null
+++ 
b/core/camel-core/src/test/java/org/apache/camel/impl/engine/DefaultSupervisingRouteControllerExhaustedStartTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.impl.engine;
+
+import java.time.Duration;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.SupervisingRouteController;
+import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.support.DefaultConsumer;
+import org.apache.camel.support.DefaultEndpoint;
+import org.junit.jupiter.api.Test;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * A route whose restarts were exhausted, and which is then started manually, 
is no longer regarded as exhausted (or
+ * unhealthy).
+ */
+public class DefaultSupervisingRouteControllerExhaustedStartTest extends 
ContextTestSupport {
+
+    private final AtomicBoolean failing = new AtomicBoolean(true);
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+
+    @Test
+    public void testManualStartAfterExhausted() throws Exception {
+        context.addComponent("flaky", new DefaultComponent() {
+            @Override
+            protected Endpoint createEndpoint(String uri, String remaining, 
Map<String, Object> parameters) {
+                return new DefaultEndpoint(uri, this) {
+                    @Override
+                    public Producer createProducer() {
+                        throw new UnsupportedOperationException();
+                    }
+
+                    @Override
+                    public Consumer createConsumer(Processor processor) {
+                        return new DefaultConsumer(this, processor) {
+                            @Override
+                            protected void doStart() throws Exception {
+                                if (failing.get()) {
+                                    throw new IllegalStateException("Cannot 
connect");
+                                }
+                                super.doStart();
+                            }
+                        };
+                    }
+                };
+            }
+        });
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("flaky:start").routeId("flaky").to("mock:result");
+            }
+        });
+
+        SupervisingRouteController src = 
context.getRouteController().supervising();
+        src.setBackOffDelay(10);
+        src.setBackOffMaxAttempts(2);
+        src.setInitialDelay(10);
+        src.setUnhealthyOnExhausted(true);
+        context.start();
+
+        await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> 
assertEquals(1, src.getExhaustedRoutes().size()));
+        assertTrue(((DefaultSupervisingRouteController) 
src).hasUnhealthyRoutes());
+
+        // the cause is fixed, and the route is started manually
+        failing.set(false);
+        context.getRouteController().startRoute("flaky");
+
+        assertEquals("Started", 
context.getRouteController().getRouteStatus("flaky").toString());
+        assertEquals(0, src.getExhaustedRoutes().size(), "the started route 
should no longer be exhausted");
+        assertFalse(((DefaultSupervisingRouteController) 
src).hasUnhealthyRoutes(),
+                "the started route should no longer be unhealthy");
+    }
+}

Reply via email to