This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch camel-4.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.22.x by this push:
new 88a7fbb20968 [backport camel-4.22.x] CAMEL-25197: camel-cli-connector
- do not keep the JVM running after the stop action (#27215)
88a7fbb20968 is described below
commit 88a7fbb2096812e7bafc7f51acd7f2d77be0da37
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Oct 1 17:20:56 2026 +0200
[backport camel-4.22.x] CAMEL-25197: camel-cli-connector - do not keep the
JVM running after the stop action (#27215)
---
.../camel/cli/connector/LocalCliConnector.java | 3 ++
.../connector/LocalCliConnectorSigtermTest.java | 56 ++++++++++++++++++++++
2 files changed, 59 insertions(+)
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 c5859350123f..c4abbd9751ae 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
@@ -262,6 +262,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..a8193f9b4f69
--- /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.junit6.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());
+ });
+ }
+}