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 10cb428c1eaa CAMEL-26954: camel-core - BacklogDebugger: a
single-stepped exchange no longer replaces the exchange suspended at the node
(#30313)
10cb428c1eaa is described below
commit 10cb428c1eaa08606dd74529aa0f5f5d93ceb5e6
Author: allthingssecurity <[email protected]>
AuthorDate: Wed Nov 18 18:19:24 2026 +0530
CAMEL-26954: camel-core - BacklogDebugger: a single-stepped exchange no
longer replaces the exchange suspended at the node (#30313)
The step breakpoint registered its exchange at the node with put, so a
step into a node where another exchange was suspended by a node
breakpoint replaced that exchange: the debugger no longer showed it, a
resume of the node continued the stepped exchange only, and the other
exchange waited until the fallback timeout.
The step now waits until no other exchange is suspended at the node
(within the fallback timeout), then suspends there. If its single step
ended meanwhile (a resume, resumeAll) or the debugger was disabled, the
exchange continues without suspending.
A part of a split or multicast is single-stepped through the exchange it
was created from (its correlation id), so a
part that waited for a node now suspends there instead of skipping it. In
single step mode, stepBreakpoint() and
stepBreakpoint(nodeId) return after step(), so the exchange that the step
lets suspend at a node is not stepped on
at once. The step removes its message after every wait (a resume removes
the message before the exchange), and an
interrupted step no longer stays registered at the node.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../impl/debugger/DefaultBacklogDebugger.java | 169 ++++++++++-----
.../BacklogDebuggerStepIntoSuspendedNodeTest.java | 227 +++++++++++++++++++++
2 files changed, 340 insertions(+), 56 deletions(-)
diff --git
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
index fb62e6435b05..22d1652eeb89 100644
---
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
+++
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java
@@ -123,6 +123,13 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
public boolean awaitExchange(long timeout) throws InterruptedException
{
return latch.await(timeout, TimeUnit.SECONDS);
}
+
+ /**
+ * Waits (for another exchange) until this exchange continues, or the
given time in nanoseconds elapsed.
+ */
+ public void awaitContinue(long nanos) throws InterruptedException {
+ latch.await(nanos, TimeUnit.NANOSECONDS);
+ }
}
/**
@@ -624,6 +631,8 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
if (isSingleStepMode()) {
logger.log("Step breakpoint is already in single step mode, so
stepping instead.");
step();
+ // the step may let an exchange that waited for a node suspend
there: it must not be stepped on as well
+ return;
}
if (suspendedBreakpointMessages.size() != 1) {
@@ -653,6 +662,8 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
if (isSingleStepMode()) {
logger.log("Step breakpoint " + nodeId + " is already in single
step mode, so stepping instead.");
step();
+ // the step may let an exchange that waited for a node suspend
there: it must not be stepped on as well
+ return;
}
logger.log("Step breakpoint " + nodeId);
@@ -1078,34 +1089,7 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
toNodeShortName, toNodeLabel, level,
exchangeId, correlationExchangeId, breadcrumbId,
false, false, data);
- suspendedBreakpointMessages.put(toNode, msg);
-
- // suspend at this breakpoint
- SuspendedExchange se = new SuspendedExchange(exchange);
- suspendedBreakpoints.put(toNode, se);
-
- // now wait until we should continue
- logger.log(
- String.format("StepBreakpoint at node %s is waiting to
continue for exchangeId: %s", toNode,
- exchange.getExchangeId()));
- try {
- boolean hit = se.awaitExchange(fallbackTimeout);
- if (!hit) {
- // remove breakpoint as it timed out (only the ones of
this exchange)
- removeMessageOf(toNode, exchange.getExchangeId());
- suspendedBreakpoints.remove(toNode, se);
- logger.log(
- String.format("StepBreakpoint at node %s timed out
and is continued exchangeId: %s", toNode,
- exchange.getExchangeId()),
- LoggingLevel.WARN);
- } else {
- logger.log(String.format("StepBreakpoint at node %s is
continued exchangeId: %s", toNode,
- exchange.getExchangeId()));
- }
- } catch (InterruptedException e) {
- // ignore
- Thread.currentThread().interrupt();
- }
+ suspendStep(toNode, exchange, msg);
}
@Override
@@ -1154,6 +1138,106 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
}
}
+ /**
+ * Suspends the single-stepped exchange at the node, and waits until
it should continue. Another exchange may be
+ * suspended at the node by a node breakpoint: the step then waits
until that exchange is no longer suspended
+ * there, as the debugger keeps one suspended exchange per node, and
must not replace the other exchange. The
+ * step can so wait up to twice the fallback timeout: for the node,
then at the node.
+ */
+ private void suspendStep(String toNode, Exchange exchange,
BacklogTracerEventMessage msg) {
+ String exchangeId = exchange.getExchangeId();
+ SuspendedExchange se = new SuspendedExchange(exchange);
+ boolean registered = false;
+ try {
+ if (!awaitNode(toNode, se)) {
+ return;
+ }
+ registered = true;
+ // publish the message only while this exchange is the one
suspended at the node
+ suspendedBreakpointMessages.compute(toNode, (k, m) ->
suspendedBreakpoints.get(k) == se ? msg : m);
+
+ // now wait until we should continue
+ logger.log(
+ String.format("StepBreakpoint at node %s is waiting to
continue for exchangeId: %s", toNode,
+ exchangeId));
+ boolean hit = se.awaitExchange(fallbackTimeout);
+ // a resume removes the message, then the suspended exchange:
the message published above between
+ // the two must not stay at the node (only the message of this
exchange is removed)
+ removeMessageOf(toNode, exchangeId);
+ if (!hit) {
+ // remove breakpoint as it timed out (only the ones of
this exchange)
+ suspendedBreakpoints.remove(toNode, se);
+ logger.log(
+ String.format("StepBreakpoint at node %s timed out
and is continued exchangeId: %s", toNode,
+ exchangeId),
+ LoggingLevel.WARN);
+ } else {
+ logger.log(String.format("StepBreakpoint at node %s is
continued exchangeId: %s", toNode,
+ exchangeId));
+ }
+ } catch (InterruptedException e) {
+ if (registered) {
+ // the exchange continues: a later step to this node must
not wait for it
+ removeMessageOf(toNode, exchangeId);
+ suspendedBreakpoints.remove(toNode, se);
+ }
+ Thread.currentThread().interrupt();
+ }
+ }
+
+ /**
+ * Registers the exchange as the one suspended at the node, after
waiting (up to the fallback timeout) until no
+ * other exchange is suspended there.
+ *
+ * @return {@code false} if the exchange should continue without
suspending at the node: the wait timed out, or
+ * the exchange is no longer single-stepped (it was resumed
while it waited, or the debugger was
+ * disabled)
+ */
+ private boolean awaitNode(String toNode, SuspendedExchange se) throws
InterruptedException {
+ String exchangeId = se.getExchange().getExchangeId();
+ long deadline = System.nanoTime() +
TimeUnit.SECONDS.toNanos(fallbackTimeout);
+ boolean waited = false;
+ SuspendedExchange other;
+ while ((other = suspendedBreakpoints.putIfAbsent(toNode, se)) !=
null) {
+ long left = deadline - System.nanoTime();
+ if (left <= 0) {
+ logger.log(
+ String.format("StepBreakpoint at node %s timed out
waiting for exchangeId: %s to continue,"
+ + " and is continued exchangeId: %s",
+ toNode,
other.getExchange().getExchangeId(), exchangeId),
+ LoggingLevel.WARN);
+ return false;
+ }
+ if (!waited) {
+ waited = true;
+ logger.log(String.format("StepBreakpoint at node %s is
waiting for exchangeId: %s suspended there,"
+ + " before it suspends
exchangeId: %s",
+ toNode, other.getExchange().getExchangeId(),
exchangeId));
+ }
+ // until the other exchange continues, or checks again soon,
as its breakpoint can time out and be
+ // removed without a resume
+ other.awaitContinue(Math.min(left,
TimeUnit.MILLISECONDS.toNanos(100)));
+ }
+ if (waited && (!isEnabled() ||
!isSingleStepped(se.getExchange()))) {
+ // the single step of this exchange ended while it waited
(resumed, or the debugger was disabled)
+ suspendedBreakpoints.remove(toNode, se);
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Whether the exchange is still single-stepped: by its own id, or by
the id of the exchange it was created from
+ * (such as a split or multicast part), as the debugger also steps
those.
+ */
+ private boolean isSingleStepped(Exchange exchange) {
+ if (singleStepExchangeId.contains(exchange.getExchangeId())) {
+ return true;
+ }
+ String id =
exchange.getProperty(ExchangePropertyKey.CORRELATION_ID, String.class);
+ return id != null && singleStepExchangeId.contains(id);
+ }
+
@SuppressWarnings("unchecked")
private NamedRoute getOriginalRoute(Exchange exchange) {
List<MessageHistory> list =
exchange.getProperty(ExchangePropertyKey.MESSAGE_HISTORY, List.class);
@@ -1197,34 +1281,7 @@ public final class DefaultBacklogDebugger extends
ServiceSupport implements Back
msg.setException(cause);
}
- suspendedBreakpointMessages.put(toNode, msg);
-
- // suspend at this breakpoint
- SuspendedExchange se = new SuspendedExchange(exchange);
- suspendedBreakpoints.put(toNode, se);
-
- // now wait until we should continue
- logger.log(
- String.format("StepBreakpoint at node %s is waiting to
continue for exchangeId: %s", toNode,
- exchange.getExchangeId()));
- try {
- boolean hit = se.awaitExchange(fallbackTimeout);
- if (!hit) {
- // remove breakpoint as it timed out (only the ones of
this exchange)
- removeMessageOf(toNode, exchange.getExchangeId());
- suspendedBreakpoints.remove(toNode, se);
- logger.log(
- String.format("StepBreakpoint at node %s timed out
and is continued exchangeId: %s", toNode,
- exchange.getExchangeId()),
- LoggingLevel.WARN);
- } else {
- logger.log(String.format("StepBreakpoint at node %s is
continued exchangeId: %s", toNode,
- exchange.getExchangeId()));
- }
- } catch (InterruptedException e) {
- // ignore
- Thread.currentThread().interrupt();
- }
+ suspendStep(toNode, exchange, msg);
}
}
diff --git
a/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerStepIntoSuspendedNodeTest.java
b/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerStepIntoSuspendedNodeTest.java
new file mode 100644
index 000000000000..348469f78a9f
--- /dev/null
+++
b/core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerStepIntoSuspendedNodeTest.java
@@ -0,0 +1,227 @@
+/*
+ * 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.management;
+
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.BacklogDebugger;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.DisabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+import static org.awaitility.Awaitility.await;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * An exchange that is single-stepped into a node where another exchange is
suspended by a node breakpoint does not
+ * replace that exchange: it suspends at the node once the other exchange
continues.
+ */
+@DisabledOnOs(OS.AIX)
+public class BacklogDebuggerStepIntoSuspendedNodeTest extends
ManagementTestSupport {
+
+ private BacklogDebugger debugger;
+
+ @Override
+ @BeforeEach
+ public void setUp() throws Exception {
+ super.setUp();
+ debugger = context.hasService(BacklogDebugger.class);
+ debugger.enableDebugger();
+ // the exchanges of a failed test continue after this, not after the
default 300 seconds
+ debugger.setFallbackTimeout(20);
+ }
+
+ @AfterEach
+ void resumeAll() {
+ if (debugger != null) {
+ debugger.resumeAll();
+ }
+ }
+
+ @Test
+ public void testStepIntoNodeWithSuspendedExchange() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Second", "First");
+
+ // the second exchange is suspended at bar by its node breakpoint
+ debugger.addBreakpoint("bar");
+ template.sendBody("seda:start", "Second");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ String second = debugger.getSuspendedExchangeIds().iterator().next();
+
+ // the first exchange is suspended at foo, and is single-stepped from
there into bar
+ debugger.addBreakpoint("foo");
+ template.sendBody("seda:start", "First");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("foo", "bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ String first = debugger.getSuspendedExchangeIds().stream().filter(id
-> !id.equals(second)).findFirst()
+ .orElseThrow();
+ long counter = debugger.getDebugCounter();
+ debugger.stepBreakpoint("foo");
+
+ // the step of the first exchange reaches bar (it counts a message
there)
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
debugger.getDebugCounter() > counter);
+
+ // the debugger still shows the second exchange suspended at bar
+ await().during(500, TimeUnit.MILLISECONDS).atMost(2,
TimeUnit.SECONDS).untilAsserted(() -> {
+ assertEquals(Set.of(second), debugger.getSuspendedExchangeIds());
+ String dump = debugger.dumpTracedMessagesAsXml("bar");
+ assertTrue(dump.contains(second), dump);
+ assertTrue(dump.contains("Second"), dump);
+ });
+
+ // a step continues the second exchange, and then the first exchange
is suspended at bar
+ debugger.step();
+ await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
+ assertEquals(Set.of(first), debugger.getSuspendedExchangeIds());
+ String dump = debugger.dumpTracedMessagesAsXml("bar");
+ assertTrue(dump != null && dump.contains(first), dump);
+ assertTrue(dump.contains("First"), dump);
+ });
+
+ // the first exchange is resumed too, and both exchanges complete
+ debugger.resumeBreakpoint("bar");
+ MockEndpoint.assertIsSatisfied(10, TimeUnit.SECONDS, mock);
+ }
+
+ @Test
+ public void testResumeWhileTheStepWaitsForTheNode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceivedInAnyOrder("Second", "First");
+
+ debugger.addBreakpoint("bar");
+ template.sendBody("seda:start", "Second");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ String second = debugger.getSuspendedExchangeIds().iterator().next();
+
+ debugger.addBreakpoint("foo");
+ template.sendBody("seda:start", "First");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("foo", "bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ long counter = debugger.getDebugCounter();
+ debugger.stepBreakpoint("foo");
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
debugger.getDebugCounter() > counter);
+ await().during(500, TimeUnit.MILLISECONDS).atMost(2, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of(second),
debugger.getSuspendedExchangeIds()));
+
+ // a resume (not a step) continues the second exchange and ends the
single step of the first exchange, which
+ // then continues without suspending at bar
+ debugger.resumeBreakpoint("bar");
+ MockEndpoint.assertIsSatisfied(10, TimeUnit.SECONDS, mock);
+ assertEquals(Set.of(), debugger.getSuspendedExchangeIds());
+ }
+
+ @Test
+ public void testStepBreakpointInSingleStepModeOnlySteps() throws Exception
{
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Second", "First");
+
+ debugger.addBreakpoint("bar");
+ template.sendBody("seda:start", "Second");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ String second = debugger.getSuspendedExchangeIds().iterator().next();
+
+ debugger.addBreakpoint("foo");
+ template.sendBody("seda:start", "First");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("foo", "bar"),
debugger.getSuspendedBreakpointNodeIds()));
+ String first = debugger.getSuspendedExchangeIds().stream().filter(id
-> !id.equals(second)).findFirst()
+ .orElseThrow();
+ long counter = debugger.getDebugCounter();
+ debugger.stepBreakpoint("foo");
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
debugger.getDebugCounter() > counter);
+ await().during(500, TimeUnit.MILLISECONDS).atMost(2, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of(second),
debugger.getSuspendedExchangeIds()));
+
+ // in single step mode, stepBreakpoint() steps (as the dev console and
camel debug do): the second exchange
+ // continues, and the first exchange then stays suspended at bar, it
is not stepped on past it
+ debugger.stepBreakpoint();
+ await().during(500, TimeUnit.MILLISECONDS).atMost(5,
TimeUnit.SECONDS).untilAsserted(() -> {
+ assertEquals(Set.of(first), debugger.getSuspendedExchangeIds());
+ assertEquals(Set.of("bar"),
debugger.getSuspendedBreakpointNodeIds());
+ String dump = debugger.dumpTracedMessagesAsXml("bar");
+ assertTrue(dump != null && dump.contains(first) &&
dump.contains("First"), dump);
+ });
+
+ debugger.resumeBreakpoint("bar");
+ MockEndpoint.assertIsSatisfied(10, TimeUnit.SECONDS, mock);
+ }
+
+ @Test
+ public void testSplitPartWaitsForTheNodeAndSuspendsThere() throws
Exception {
+ MockEndpoint mock = getMockEndpoint("mock:split");
+ mock.expectedMessageCount(2);
+
+ debugger.addBreakpoint("split-foo");
+ template.sendBody("seda:split", "a,b");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("split-foo"),
debugger.getSuspendedBreakpointNodeIds()));
+ debugger.stepBreakpoint("split-foo");
+ await().atMost(5, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("split"),
debugger.getSuspendedBreakpointNodeIds()));
+
+ // the parts are single-stepped as the split exchange is: one is
suspended at inner, the other waits for it
+ long counter = debugger.getDebugCounter();
+ debugger.step();
+ await().atMost(5, TimeUnit.SECONDS).until(() ->
debugger.getDebugCounter() >= counter + 2);
+ await().during(500, TimeUnit.MILLISECONDS).atMost(2, TimeUnit.SECONDS)
+ .untilAsserted(() -> assertEquals(Set.of("inner"),
debugger.getSuspendedBreakpointNodeIds()));
+
+ // a step continues the first part to the next node, and the part that
waited is suspended at inner (it is
+ // still single-stepped through the split exchange, its correlation id)
+ debugger.step();
+ await().atMost(5, TimeUnit.SECONDS).untilAsserted(
+ () -> assertEquals(Set.of("inner", "split-result"),
debugger.getSuspendedBreakpointNodeIds()));
+
+ // a resume ends the single step, and both parts complete
+ debugger.resumeBreakpoint("inner");
+ debugger.resumeAll();
+ MockEndpoint.assertIsSatisfied(10, TimeUnit.SECONDS, mock);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ context.setDebugging(true);
+
+ from("seda:start?concurrentConsumers=2")
+ .setProperty("num", constant(1)).id("foo")
+ .setHeader("node", constant("bar")).id("bar")
+ .convertBodyTo(String.class)
+ .to("mock:result");
+
+ from("seda:split")
+ .setProperty("num", constant(1)).id("split-foo")
+
.split(body().tokenize(",")).parallelProcessing().id("split")
+ .setHeader("node", constant("inner")).id("inner")
+ .to("mock:split").id("split-result")
+ .end();
+ }
+ };
+ }
+}