gnodet-bot commented on code in PR #26779:
URL: https://github.com/apache/camel/pull/26779#discussion_r4082393806


##########
components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarMessageListenerAcknowledgementTest.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.component.pulsar;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.apache.pulsar.client.api.Consumer;
+import org.apache.pulsar.client.api.ConsumerBuilder;
+import org.apache.pulsar.client.api.Message;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.client.api.PulsarClient;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Answers.RETURNS_SELF;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * A route failure used to leave the message neither acknowledged nor 
negatively acknowledged, so it was only
+ * redelivered once the acknowledgement timeout expired (CAMEL-16073), and a 
failing acknowledgement was reported
+ * without its cause.
+ */
+public class PulsarMessageListenerAcknowledgementTest extends CamelTestSupport 
{
+
+    private static final String ENDPOINT_URI
+            = 
"pulsar:persistent://public/default/camel-ack-test?subscriptionName=camel-subscription";
+
+    private final MessageId messageId = mock(MessageId.class);
+
+    @Test
+    public void testSuccessfulExchangeIsAcknowledged() throws Exception {
+        final Consumer<byte[]> pulsarConsumer = mock(Consumer.class);
+
+        listener().received(pulsarConsumer, message("ok"));
+
+        verify(pulsarConsumer, timeout(5000)).acknowledge(messageId);

Review Comment:
   ⚠️ **Missing test: `allowManualAcknowledgement=true` guard is untested**
   
   The three tests here all use the default endpoint URI (no 
`allowManualAcknowledgement=true`), so they only cover the 
`isAllowManualAcknowledgement() == false` path. The new `negativeAcknowledge()` 
private method contains a guard:
   
   ```java
   if (!endpoint.getPulsarConfiguration().isAllowManualAcknowledgement()) {
       consumer.negativeAcknowledge(message.getMessageId());
   }
   ```
   
   If that guard is accidentally removed, no existing test catches it. The PR 
body says the route stays in charge when manual acknowledgement is enabled — 
that guarantee needs a test:
   
   ```java
   @Test
   public void testFailedExchangeWithManualAckDoesNotNegativelyAcknowledge() 
throws Exception {
       // reconfigure the endpoint URI to include 
allowManualAcknowledgement=true
       final Consumer<byte[]> pulsarConsumer = mock(Consumer.class);
       // use an endpoint with allowManualAcknowledgement=true in its URI
       // then trigger a route failure and verify:
       verify(pulsarConsumer, never()).negativeAcknowledge(messageId);
       verify(pulsarConsumer, never()).acknowledge(messageId);
   }
   ```
   
   (The exact wiring depends on how you expose the endpoint URI with the 
parameter — you may need a second CamelContext or a `@ParameterizedTest` if the 
current context is shared.)



##########
docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_23.adoc:
##########
@@ -2567,3 +2567,17 @@ Routes that reference the constants (for example 
`setHeader(MustacheConstants.MU
 are unaffected. Routes that set the header by its literal string name, or that 
use
 `allowTemplateFromHeader=true` with the old header names, must switch to the 
new `Camel`-prefixed
 names.
+
+=== camel-pulsar - a failed exchange is negatively acknowledged
+
+When a route fails, the consumer now calls `negativeAcknowledge` on the Pulsar 
consumer instead of
+leaving the message unacknowledged. This only applies when 
`allowManualAcknowledgement` is `false`
+(the default); with manual acknowledgement the route stays in charge, as 
before.
+
+This changes when the message comes back. Previously it was redelivered once 
the acknowledgement
+timeout expired, which `camel-pulsar` sets to 10 seconds by default through 
`ackTimeoutMillis`. A
+negative acknowledgement removes the message from the client's 
unacknowledged-message tracker, so
+redelivery now follows `negativeAckRedeliveryDelayMicros`, which defaults to 
60 seconds, and honours
+`negativeAckRedeliveryBackoff` when one is configured.
+
+A route that wants the previous timing can set 
`negativeAckRedeliveryDelayMicros=10000000`.

Review Comment:
   ⚠️ **CAMEL-24933 behavior change also needs an upgrade guide entry**
   
   The nack redelivery change (CAMEL-16073) is documented here, but the fix to 
`PulsarMessageUtils.updateExchange()` (CAMEL-24933) is not. That method is 
`public static` and its return contract changed: it now returns the **same 
exchange instance** passed in, instead of a copy.
   
   Any external code that did:
   ```java
   Exchange copy = PulsarMessageUtils.updateExchange(msg, original);
   // uses both copy and original expecting them to be independent
   ```
   will silently break — both variables now point to the same object.
   
   While the only known caller is internal, the method is part of the public 
API surface. Please add a brief upgrade guide note, e.g.:
   
   ```
   === camel-pulsar - PulsarMessageUtils.updateExchange() now returns the input 
exchange
   
   Previously, `PulsarMessageUtils.updateExchange(message, exchange)` returned 
a copy of
   the exchange. It now populates and returns the same instance it received, to 
prevent
   orphan pooled exchanges. Custom extensions that relied on copy semantics 
must be updated.
   ```



-- 
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