This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch CAMEL-27326-transform-run-jmx in repository https://gitbox.apache.org/repos/asf/camel.git
commit 43ce0cc5f4622d41d88b263326cd272da669fd04 Author: Claus Ibsen <[email protected]> AuthorDate: Sat Nov 21 09:15:51 2026 +0100 CAMEL-27326: camel-jbang - a transform run has no JMX, so two at the same time in one JVM do not clash Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../core/commands/mcp/RouteDiagramToolsTest.java | 37 ++++++++++++++++++++++ .../apache/camel/dsl/jbang/run/RunPipeline.java | 3 ++ 2 files changed, 40 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-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");
