oscerd commented on code in PR #26778:
URL: https://github.com/apache/camel/pull/26778#discussion_r4084297185
##########
components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java:
##########
@@ -136,10 +136,10 @@ public void run() {
// by exiting the loop. We make it explicit instead of
breaking the loop.
running = false;
} else {
- endpoint.getExceptionHandler().handleException(e);
+ getExceptionHandler().handleException("Error receiving
from pulsar", e);
Review Comment:
Done in this PR rather than a follow-up — you are right that the fix as it
stood traded a dead thread for a hot one, and a spinning thread on every
consumer thread is arguably worse than the silent death it replaced.
`AlreadyClosedException` is now terminal, like the interrupt: there is
nothing left to poll. Anything else gets an interruptible one-second wait
before the next `receive()`, so a stopping consumer still leaves promptly
(graceful shutdown interrupts it, the loop sees the interrupt and exits).
The delay is a constant (`ERROR_RETRY_DELAY_MILLIS`) rather than a new
endpoint option — happy to promote it to a `@UriParam` if you would rather have
it configurable.
_Claude Code on behalf of oscerd_
##########
components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java:
##########
@@ -136,10 +136,10 @@ public void run() {
// by exiting the loop. We make it explicit instead of
breaking the loop.
running = false;
} else {
- endpoint.getExceptionHandler().handleException(e);
+ getExceptionHandler().handleException("Error receiving
from pulsar", e);
}
} catch (Exception e) {
- endpoint.getExceptionHandler().handleException(e);
+ getExceptionHandler().handleException("Error receiving
from pulsar", e);
Review Comment:
Fixed — both handler calls now say "Error consuming from pulsar", since the
catches cover `listener.received(...)` as well as the receive itself.
_Claude Code on behalf of oscerd_
##########
components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/PulsarConsumerReceiveErrorTest.java:
##########
@@ -0,0 +1,143 @@
+/*
+ * 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.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+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.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.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * A receive error used to be reported through the endpoint exception handler,
which is null unless the route configures
+ * one, so the polling loop died on a NullPointerException and that consumer
stopped consuming in silence.
+ */
+public class PulsarConsumerReceiveErrorTest extends CamelTestSupport {
+
+ private static final String ROUTE_ID = "pulsar-receive-error";
+
+ private final CountDownLatch blockReceive = new CountDownLatch(1);
Review Comment:
Good catch, and it was worse than slow: the assertion did not prove anything
about the exit path.
Restructured — `blockReceive` is gone. The second `receive()` now reports a
closed consumer, and the test asserts with `verify(consumer,
after(1500).times(2)).receive()` that no third call follows, i.e. the loop left
rather than spun. The window is deliberately longer than the one-second retry
delay; at the 500 ms I first wrote, the assertion passed even with the terminal
branch removed, so it proved nothing. Removing that branch now fails the test.
_Claude Code on behalf of oscerd_
--
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]