davsclaus commented on code in PR #30313:
URL: https://github.com/apache/camel/pull/30313#discussion_r4611497998


##########
core/camel-base-engine/src/main/java/org/apache/camel/impl/debugger/DefaultBacklogDebugger.java:
##########
@@ -1154,6 +1134,85 @@ public void onEvent(Exchange exchange, ExchangeEvent 
event, NamedNode definition
             }
         }
 
+        /**
+         * 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.
+         */
+        private void suspendStep(String toNode, Exchange exchange, 
BacklogTracerEventMessage msg) {
+            String exchangeId = exchange.getExchangeId();
+            SuspendedExchange se = new SuspendedExchange(exchange);
+            try {
+                if (!awaitNode(toNode, se)) {
+                    return;
+                }
+                // 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);
+                if (!hit) {
+                    // remove breakpoint as it timed out (only the ones of 
this exchange)
+                    removeMessageOf(toNode, exchangeId);
+                    suspendedBreakpoints.remove(toNode, se);
+                    logger.log(
+                            String.format("StepBreakpoint at node %s timed out 
and is continued exchangeId: %s", toNode,
+                                    exchangeId),
+                            LoggingLevel.WARN);
+                } else {

Review Comment:
   Addressed in bb584f99fe: the `suspendStep` javadoc now states that a step 
can wait up to twice the fallback timeout (for the node, then at it). This 
matches node breakpoints, where matching and waiting are separate timeouts.
   
   _Claude Code on behalf of davsclaus_



##########
core/camel-management/src/test/java/org/apache/camel/management/BacklogDebuggerStepIntoSuspendedNodeTest.java:
##########
@@ -0,0 +1,150 @@
+/*
+ * 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);
+        });
+

Review Comment:
   No change needed: the test identifies the first exchange by its exchange id 
(`assertEquals(Set.of(first), ...)` and `dump.contains(first)`), which is 
stricter than the body, and `mock.expectedBodiesReceived("Second", "First")` 
checks the order of the bodies.
   
   _Claude Code on behalf of davsclaus_



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to