davsclaus commented on code in PR #26778:
URL: https://github.com/apache/camel/pull/26778#discussion_r4083551226
##########
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:
Nit: this catch also covers failures inside `listener.received(...)`
(creating or updating the exchange), not just receiving. Something like "Error
consuming from pulsar" would fit better.
##########
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:
Now that the loop keeps going, a failure that never clears makes `receive()`
throw straight away on every iteration. Examples: a terminated topic or a
closed consumer (`AlreadyClosedException`), or a consumer in `Failed` state
(`NotConnectedException`). That becomes a busy loop on each of the
`numberOfConsumerThreads` threads, logging a WARN with a stack trace every
time, or creating a bridged exchange every time with `bridgeErrorHandler=true`.
Suggestion: treat `PulsarClientException.AlreadyClosedException` as
terminal, like the interrupt branch (`running = false`). For other errors,
pause briefly before the next `receive()`, in a way that can be interrupted so
stopping stays prompt. The JIRA already raises this. OK to do it in a follow-up.
##########
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:
`blockReceive` is never counted down, so the loop only leaves the second
`receive()` when shutdown interrupts it after the 500 ms graceful timeout. That
adds about 0.5 s and asserts nothing about the exit path. Consider counting it
down (or renaming it), then asserting that the route stops promptly and
`receiveCalls` stays at 2, i.e. the loop exited instead of spinning.
--
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]