This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-4.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.18.x by this push:
     new c16900966ebe [backport camel-4.18.x] CAMEL-25197: camel-cli-connector 
- do not keep the JVM running after the stop action (#27382)
c16900966ebe is described below

commit c16900966ebe1fb3eb2e59c2c6feb65b7570387e
Author: Federico Mariani <[email protected]>
AuthorDate: Mon Oct 5 20:35:54 2026 +0200

    [backport camel-4.18.x] CAMEL-25197: camel-cli-connector - do not keep the 
JVM running after the stop action (#27382)
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 dsl/camel-cli-connector/pom.xml                    | 11 +++++
 .../camel/cli/connector/LocalCliConnector.java     |  3 ++
 .../connector/LocalCliConnectorSigtermTest.java    | 56 ++++++++++++++++++++++
 3 files changed, 70 insertions(+)

diff --git a/dsl/camel-cli-connector/pom.xml b/dsl/camel-cli-connector/pom.xml
index 17eb90c04bd7..813fdb6b1782 100644
--- a/dsl/camel-cli-connector/pom.xml
+++ b/dsl/camel-cli-connector/pom.xml
@@ -69,6 +69,17 @@
             <artifactId>camel-test-junit5</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <version>${awaitility-version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-slf4j2-impl</artifactId>
diff --git 
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
 
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
index eaf6e37df925..98c33a466b5a 100644
--- 
a/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
+++ 
b/dsl/camel-cli-connector/src/main/java/org/apache/camel/cli/connector/LocalCliConnector.java
@@ -250,6 +250,9 @@ public class LocalCliConnector extends ServiceSupport 
implements CliConnector, C
                 }
             }
         });
+        // the thread ends once the task is done: a non-daemon thread left 
waiting for more tasks keeps the JVM
+        // running (Spring Boot)
+        terminateExecutor.shutdown();
     }
 
     protected void task() {
diff --git 
a/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorSigtermTest.java
 
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorSigtermTest.java
new file mode 100644
index 000000000000..39813d03649f
--- /dev/null
+++ 
b/dsl/camel-cli-connector/src/test/java/org/apache/camel/cli/connector/LocalCliConnectorSigtermTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.cli.connector;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.spi.CliConnectorFactory;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+class LocalCliConnectorSigtermTest extends CamelTestSupport {
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext context = super.createCamelContext();
+        // do not let the context start the connector found on the classpath, 
the test uses its own
+        DefaultCliConnectorFactory disabled = new DefaultCliConnectorFactory();
+        disabled.setEnabled(false);
+        
context.getCamelContextExtension().addContextPlugin(CliConnectorFactory.class, 
disabled);
+        return context;
+    }
+
+    @Test
+    void terminateThreadEndsOnceCamelIsStopped() {
+        LocalCliConnector connector = new LocalCliConnector(new 
DefaultCliConnectorFactory());
+        connector.setCamelContext(context);
+
+        connector.sigterm();
+
+        await().atMost(20, TimeUnit.SECONDS).untilAsserted(() -> {
+            assertThat(context.getStatus()).isEqualTo(ServiceStatus.Stopped);
+            // a non-daemon thread left behind keeps the JVM running (Spring 
Boot)
+            assertThat(Thread.getAllStackTraces().keySet())
+                    .noneMatch(t -> t.getName().endsWith("Terminate JVM task") 
&& t.isAlive());
+        });
+    }
+}

Reply via email to