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 dc43a82957fb CAMEL-27326: camel-jbang - transient runs at the same
time no longer clash on the JMX name transform (#30544)
dc43a82957fb is described below
commit dc43a82957fbb119b82f037ca00fb9d6174fcffc
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 09:42:17 2026 +0100
CAMEL-27326: camel-jbang - transient runs at the same time no longer clash
on the JMX name transform (#30544)
A transform run (route diagram, route structure, transform route,
yaml-normalize) runs with camel.main.jmxEnabled=false: two at the same time in
one JVM, as the MCP server does, both named their context transform and the
second failed with InstanceAlreadyExistsException. This made
RouteDiagramToolsTest.callsAtTheSameTime flaky. A new test asserts that a
transform run registers no MBeans. The tests of camel-jbang-run and
camel-jbang-plugin-tui run with Camel JMX off.
_Claude Code on behalf of Claus Ibsen_
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../core/commands/mcp/RouteDiagramToolsTest.java | 37 ++++++++++++++++++++++
dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml | 2 ++
dsl/camel-jbang/camel-jbang-run/pom.xml | 2 ++
.../apache/camel/dsl/jbang/run/RunPipeline.java | 3 ++
4 files changed, 44 insertions(+)
diff --git
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RouteDiagramToolsTest.java
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RouteDiagramToolsTest.java
index 87be32bca765..f8149f7e4f52 100644
---
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RouteDiagramToolsTest.java
+++
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/RouteDiagramToolsTest.java
@@ -16,16 +16,24 @@
*/
package org.apache.camel.dsl.jbang.core.commands.mcp;
+import java.lang.management.ManagementFactory;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerDelegate;
+import javax.management.MBeanServerNotification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
import io.quarkiverse.mcp.server.ToolCallException;
import org.apache.camel.dsl.jbang.core.common.CommandLineHelper;
import org.junit.jupiter.api.Test;
@@ -183,6 +191,35 @@ class RouteDiagramToolsTest {
}
}
+ @Test
+ void aTransformRunRegistersNoMBeans(@TempDir Path dir) throws Exception {
+ // CAMEL-27326: every transform run names its context transform; with
JMX on, two runs at the same time in one
+ // JVM (the MCP server) could both take that name, and the second
failed with InstanceAlreadyExistsException,
+ // which made callsAtTheSameTime flaky. A transform run only dumps the
routes to files, so it has no JMX.
+ MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ List<ObjectName> registered = new CopyOnWriteArrayList<>();
+ NotificationListener listener = (notification, handback) -> {
+ if (notification instanceof MBeanServerNotification n
+ &&
MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(n.getType())
+ && "org.apache.camel".equals(n.getMBeanName().getDomain())
+ // the MBeans of the transform run; other tests may start contexts
of their own meanwhile
+ &&
String.valueOf(n.getMBeanName().getKeyProperty("context")).startsWith("transform"))
{
+ registered.add(n.getMBeanName());
+ }
+ };
+ server.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME,
listener, null, null);
+ try {
+ RouteDiagramTools.RouteDiagramResult result = new
RouteDiagramTools().camel_render_route_diagram(
+ route(dir, "lonely").toString(), null, "ascii", null,
null, null, null, null, null);
+
+ assertThat(result.success()).as(result.message()).isTrue();
+ assertThat(result.asciiDiagram()).contains("lonely");
+ } finally {
+
server.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener);
+ }
+ assertThat(registered).isEmpty();
+ }
+
private static Path route(Path dir, String id) throws Exception {
Path source = dir.resolve(id + ".camel.yaml");
Files.writeString(source, """
diff --git a/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
b/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
index e2c0f2e01cd4..8c4f091c1bc9 100644
--- a/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-plugin-tui/pom.xml
@@ -190,6 +190,8 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
+ <!-- the tests need no Camel JMX: fewer MBeans, and
contexts started at the same time do not clash -->
+
<org.apache.camel.jmx.disabled>true</org.apache.camel.jmx.disabled>
<!-- the tests write prompt and shell histories,
settings and the camel-jbang log under the home
directory: a home of their own keeps them out of
the developer's. The local Maven
repository stays the build's, so what the tests
resolve is not downloaded again -->
diff --git a/dsl/camel-jbang/camel-jbang-run/pom.xml
b/dsl/camel-jbang/camel-jbang-run/pom.xml
index 33d5e0d4140a..15bda05417dd 100644
--- a/dsl/camel-jbang/camel-jbang-run/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-run/pom.xml
@@ -140,6 +140,8 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
+ <!-- the tests need no Camel JMX: fewer MBeans, and
contexts started at the same time do not clash -->
+
<org.apache.camel.jmx.disabled>true</org.apache.camel.jmx.disabled>
<!-- a home of its own (~/.camel), out of the
developer's. The local Maven repository stays
the build's, so what the tests resolve is not
downloaded again -->
<user.home>${project.build.directory}/test-home</user.home>
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
index d6f175afe159..8fb7b9e91b15 100644
---
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
+++
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java
@@ -533,6 +533,9 @@ public class RunPipeline {
// do not run for very long in silent run
main.addInitialProperty("camel.main.autoStartup", "false");
main.addInitialProperty("camel.main.durationMaxSeconds", "-1");
+ // every transform run names its context transform: two at the
same time in one JVM (such as the MCP
+ // server) would register the same JMX names, and it only dumps
the routes to files
+ main.addInitialProperty("camel.main.jmxEnabled", "false");
} else if (request.transformMessageRun) {
// do not start any routes
main.addInitialProperty("camel.main.autoStartup", "false");