This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 15ba7df185fb CAMEL-27474: add tests for Error on poll, and log
rollback failures in seda consumer (#30741)
15ba7df185fb is described below
commit 15ba7df185fb172999db9100d226185c1ff2a0bd
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 30 14:34:40 2026 +0100
CAMEL-27474: add tests for Error on poll, and log rollback failures in seda
consumer (#30741)
* CAMEL-27474: address review comments
* CAMEL-27474: use 10 s timeout in queue poll-error test for CI robustness
AI-assisted: Hermès on behalf of @gnodet
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../hazelcast/seda/HazelcastSedaConsumer.java | 8 +-
...zelcastQueueConsumerPollErrorThrowableTest.java | 89 +++++++++++++++++++++
...azelcastSedaConsumerPollErrorThrowableTest.java | 91 ++++++++++++++++++++++
3 files changed, 186 insertions(+), 2 deletions(-)
diff --git
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/seda/HazelcastSedaConsumer.java
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/seda/HazelcastSedaConsumer.java
index f424cf22f635..4526b191b060 100644
---
a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/seda/HazelcastSedaConsumer.java
+++
b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/seda/HazelcastSedaConsumer.java
@@ -199,7 +199,9 @@ public class HazelcastSedaConsumer extends DefaultConsumer
implements Runnable {
if (transactionCtx != null) {
try {
transactionCtx.rollbackTransaction();
- } catch (Exception ignore) {
+ } catch (Exception rollbackEx) {
+ LOG.debug("Rollback after VirtualMachineError failed
for transaction: {}",
+ transactionCtx.getTxnId(), rollbackEx);
}
}
LOG.error("Fatal error consuming from: {}. The consumer stops
consuming until the route is restarted.",
@@ -212,7 +214,9 @@ public class HazelcastSedaConsumer extends DefaultConsumer
implements Runnable {
LOG.trace("Rollback transaction: {}",
transactionCtx.getTxnId());
try {
transactionCtx.rollbackTransaction();
- } catch (Exception ignore) {
+ } catch (Exception rollbackEx) {
+ LOG.debug("Rollback after Error failed for
transaction: {}",
+ transactionCtx.getTxnId(), rollbackEx);
}
}
getExceptionHandler().handleException("Error processing
exchange", exchange, e);
diff --git
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollErrorThrowableTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollErrorThrowableTest.java
new file mode 100644
index 000000000000..3578c48d4a59
--- /dev/null
+++
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollErrorThrowableTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.hazelcast;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.hazelcast.collection.IQueue;
+import com.hazelcast.core.HazelcastInstance;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * The queue consumer in poll mode must keep polling after a poll throws an
Error (e.g. NoClassDefFoundError from
+ * deserialization), not just after an Exception.
+ */
+public class HazelcastQueueConsumerPollErrorThrowableTest extends
HazelcastCamelTestSupport {
+
+ @Mock
+ private IQueue<String> queue;
+
+ private final LinkedBlockingQueue<String> items = new
LinkedBlockingQueue<>();
+ private final AtomicBoolean failed = new AtomicBoolean();
+
+ @Override
+ protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance)
{
+ when(hazelcastInstance.<String> getQueue("foo")).thenReturn(queue);
+ try {
+ when(queue.poll(anyLong(),
any(TimeUnit.class))).thenAnswer(invocation -> {
+ // the first poll throws an Error simulating a deserialization
failure
+ if (failed.compareAndSet(false, true)) {
+ throw new NoClassDefFoundError("Simulated deserialization
failure");
+ }
+ return items.poll(invocation.getArgument(0),
invocation.getArgument(1));
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ protected void verifyHazelcastInstance(HazelcastInstance
hazelcastInstance) {
+ verify(hazelcastInstance).getQueue("foo");
+ }
+
+ @Test
+ void testKeepsPollingAfterError() throws Exception {
+ MockEndpoint out = getMockEndpoint("mock:result");
+ out.expectedBodiesReceived("bar");
+
+ items.add("bar");
+
+ MockEndpoint.assertIsSatisfied(context, 10, TimeUnit.SECONDS);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+
from(String.format("hazelcast-%sfoo?queueConsumerMode=Poll&pollingTimeout=100",
+ HazelcastConstants.QUEUE_PREFIX))
+ .to("mock:result");
+ }
+ };
+ }
+}
diff --git
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaConsumerPollErrorThrowableTest.java
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaConsumerPollErrorThrowableTest.java
new file mode 100644
index 000000000000..307bf1c566ab
--- /dev/null
+++
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastSedaConsumerPollErrorThrowableTest.java
@@ -0,0 +1,91 @@
+/*
+ * 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.hazelcast;
+
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import com.hazelcast.collection.IQueue;
+import com.hazelcast.core.HazelcastInstance;
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.hazelcast.seda.HazelcastSedaComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit6.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+/**
+ * The SEDA consumer must keep polling after a poll throws an Error (e.g.
NoClassDefFoundError from deserialization),
+ * not just after an Exception.
+ */
+class HazelcastSedaConsumerPollErrorThrowableTest extends CamelTestSupport {
+
+ private final LinkedBlockingQueue<String> items = new
LinkedBlockingQueue<>();
+ private final AtomicBoolean failed = new AtomicBoolean();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ IQueue<String> queue = mock(IQueue.class);
+ try {
+ when(queue.poll(anyLong(),
any(TimeUnit.class))).thenAnswer(invocation -> {
+ // the first poll throws an Error simulating a deserialization
failure
+ if (failed.compareAndSet(false, true)) {
+ throw new NoClassDefFoundError("Simulated deserialization
failure");
+ }
+ return items.poll(invocation.getArgument(0),
invocation.getArgument(1));
+ });
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+
+ HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
+ when(hazelcastInstance.<String> getQueue("foo")).thenReturn(queue);
+
+ CamelContext context = super.createCamelContext();
+ HazelcastSedaComponent seda = new HazelcastSedaComponent(context);
+ seda.setHazelcastInstance(hazelcastInstance);
+ context.addComponent("hazelcast-seda", seda);
+ return context;
+ }
+
+ @Test
+ void testKeepsPollingAfterError() throws Exception {
+ MockEndpoint out = getMockEndpoint("mock:result");
+ out.expectedBodiesReceived("bar");
+
+ items.add("bar");
+
+ MockEndpoint.assertIsSatisfied(context, 5, TimeUnit.SECONDS);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from(String.format("hazelcast-%sfoo?onErrorDelay=100",
HazelcastConstants.SEDA_PREFIX))
+ .to("mock:result");
+ }
+ };
+ }
+}