gnodet-bot commented on code in PR #26804:
URL: https://github.com/apache/camel/pull/26804#discussion_r4085649513
##########
core/camel-core-processor/src/main/java/org/apache/camel/processor/errorhandler/RedeliveryErrorHandler.java:
##########
@@ -2024,4 +2025,32 @@ protected void doShutdown() throws Exception {
ServiceHelper.stopAndShutdownServices(deadLetter, output, outputAsync,
taskFactory);
}
+ /**
+ * Where the failure happened, as the route and node the exchange was at
and where that node is in the source, such
+ * as {@code at route1[to3] orders.camel.yaml:18}. Empty when nothing was
captured - message history or source
Review Comment:
π **Javadoc: double space in `@code` example.**
The `@code` block opens with two spaces: `{@code at route1[to3]
orders.camel.yaml:18}`. In the rendered Javadoc HTML this produces a leading
non-breaking space before `at`, so the example reads `γ at route1β¦γ` rather
than `γat route1β¦γ`. The runtime string is correct (`" at "` starts with one
space that abuts the preceding text), but the example is misleading.
```suggestion
* as {@code at route1[to3] orders.camel.yaml:18}. Empty when nothing
was captured - message history or source
```
##########
core/camel-core/src/test/java/org/apache/camel/processor/FailedDeliveryOriginTest.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * 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.processor;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.regex.Pattern;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.LoggingLevel;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.CamelLogger;
+import org.junit.jupiter.api.Test;
+import org.slf4j.LoggerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * The failed delivery message says where the failure happened - the route,
the node, and where that node is in the
+ * source - so the reader does not have to work it out from the message
history below (CAMEL-24974).
+ */
+public class FailedDeliveryOriginTest extends ContextTestSupport {
+
+ /** Such as: at foo[throwException1] ContextTestSupport:480 */
+ private static final Pattern ORIGIN = Pattern.compile(" at foo\\[\\w+]
\\S+:\\d+");
+
+ private final RecordingLogger logger = new RecordingLogger();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ context.setMessageHistory(true);
+ context.setSourceLocationEnabled(true);
+ return context;
+ }
+
+ @Test
+ public void testFailedDeliverySaysWhere() throws Exception {
+ getMockEndpoint("mock:dead").expectedMessageCount(1);
+ template.sendBody("direct:start", "Hello World");
+ assertMockEndpointsSatisfied();
+
+ String msg = lastFailure();
+ assertTrue(msg.contains("Failed delivery for"), msg);
+ assertTrue(ORIGIN.matcher(msg).find(), "Expected the route, node and
source location in: " + msg);
+ }
+
+ private String lastFailure() {
+ assertFalse(logger.messages.isEmpty(), "The error handler should have
logged the exhausted delivery");
+ return logger.messages.get(logger.messages.size() - 1);
+ }
+
+ @Override
Review Comment:
β οΈ **Missing coverage: the `On delivery attempt: N` log path is not tested.**
The key correctness change in this PR is in
`RedeliveryTask.handleException()`: `captureFailureOrigin()` was moved *before*
the `"On delivery attempt: N"` log message so the message can include the
origin. Both tests here use `deadLetterChannel(...).logExhausted(true)` with
the default `maximumRedeliveries(0)`, so the exchange exhausts on the first
failure and goes straight to the DLC path β the `"On delivery attempt"` branch
in `RedeliveryTask.handleException()` is never reached.
Please add a test variant that configures `maximumRedeliveries(1)` (or any
value β₯ 1) so at least one retry fires, producing an `"On delivery attempt: 1"`
message that exercises the re-ordered capture and verifies the origin is
present there too. The `RecordingLogger` infrastructure already exists β
something like:
```java
errorHandler(deadLetterChannel("mock:dead")
.maximumRedeliveries(1)
.logRetryAttempted(true)
.logger(logger));
```
Then assert that the *first* logged message (the retry attempt, not the last
exhausted one) also contains the origin pattern.
--
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]