This is an automated email from the ASF dual-hosted git repository.

gnodet 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 fd5bc4452c66 Miscellaneous test fixes (#22129)
fd5bc4452c66 is described below

commit fd5bc4452c664d5dca0518141e8166819cdda1b8
Author: Guillaume Nodet <[email protected]>
AuthorDate: Fri Mar 20 09:51:04 2026 +0100

    Miscellaneous test fixes (#22129)
    
    * Miscellaneous test fixes
    
    - Disable flaky LogCaptureTest in camel-netty and camel-netty-http
    - Remove unnecessary (Object) cast on constant(null) calls
    - Disable flaky HazelcastQueueConsumerPollTest on CI
    - Remove deprecated StorageBackend.COUCHSTORE from 
CouchbaseIntegrationTestBase
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * CAMEL-23214: Harden NettyHttpSSLHandshakeErrorTest against Netty 
exception wrapping
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * Restore (Object) cast for constant(null) to avoid varargs ambiguity
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * Revert unrelated changes: restore LogCaptureTest, 
CouchbaseIntegrationTestBase, and .thenReturn(null)
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    * CAMEL-22110: Fix flaky HazelcastQueueConsumerPollTest properly
    
    The consumer's background thread starts polling queue.poll() during
    context startup, but the Mockito stub was only set up in the test
    method — after the consumer was already polling. This is a Mockito
    thread-safety race (concurrent stubbing and invocation).
    
    Fix: set up queue.poll() mock in trainHazelcastInstance() (before
    context start) using an Answer backed by a LinkedBlockingQueue.
    Tests put items into the backing queue, which is fully thread-safe.
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
    
    ---------
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../hazelcast/HazelcastQueueConsumerPollTest.java  | 28 +++++++++++++++++-----
 .../netty/http/NettyHttpSSLHandshakeErrorTest.java |  7 ++++--
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollTest.java
 
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollTest.java
index 34de00ce0911..6403fd9ed357 100644
--- 
a/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollTest.java
+++ 
b/components/camel-hazelcast/src/test/java/org/apache/camel/component/hazelcast/HazelcastQueueConsumerPollTest.java
@@ -17,6 +17,7 @@
 package org.apache.camel.component.hazelcast;
 
 import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
 
 import com.hazelcast.collection.IQueue;
@@ -30,6 +31,8 @@ import org.slf4j.LoggerFactory;
 
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.Mockito.atLeast;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -40,16 +43,29 @@ public class HazelcastQueueConsumerPollTest extends 
HazelcastCamelTestSupport {
     @Mock
     private IQueue<String> queue;
 
+    // Thread-safe backing queue: the mock's poll() delegates here,
+    // so stubbing is set up before the consumer starts polling.
+    private final LinkedBlockingQueue<String> mockItems = new 
LinkedBlockingQueue<>();
+
     @Override
     protected void trainHazelcastInstance(HazelcastInstance hazelcastInstance) 
{
         when(hazelcastInstance.<String> getQueue("foo")).thenReturn(queue);
+        try {
+            when(queue.poll(anyLong(), 
any(TimeUnit.class))).thenAnswer(invocation -> {
+                long timeout = invocation.getArgument(0);
+                TimeUnit unit = invocation.getArgument(1);
+                return mockItems.poll(timeout, unit);
+            });
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     @Override
     protected void verifyHazelcastInstance(HazelcastInstance 
hazelcastInstance) {
         verify(hazelcastInstance).getQueue("foo");
         try {
-            verify(queue, atLeast(1)).poll(10000, TimeUnit.MILLISECONDS);
+            verify(queue, atLeast(1)).poll(anyLong(), any(TimeUnit.class));
         } catch (InterruptedException e) {
             LOG.debug("Interrupted during test execution", e);
         }
@@ -57,21 +73,21 @@ public class HazelcastQueueConsumerPollTest extends 
HazelcastCamelTestSupport {
 
     @Test
     public void add() throws InterruptedException {
-        when(queue.poll(10000, 
TimeUnit.MILLISECONDS)).thenReturn("foo").thenReturn(null);
+        mockItems.add("foo");
 
         MockEndpoint out = getMockEndpoint("mock:result");
         out.expectedMessageCount(1);
 
-        MockEndpoint.assertIsSatisfied(context, 2000, TimeUnit.MILLISECONDS);
+        MockEndpoint.assertIsSatisfied(context, 5000, TimeUnit.MILLISECONDS);
 
         
this.checkHeadersAbsence(out.getExchanges().get(0).getIn().getHeaders(), 
HazelcastConstants.ADDED);
     }
 
     @Test
     public void pollTimeout() throws InterruptedException {
-        // if nothing to poll after timeout the queue.poll returns NULL, the 
consumer shouldn't send this NULL message
-        when(queue.poll(10000, TimeUnit.MILLISECONDS)).thenReturn(null);
-
+        // Don't add anything — the backing queue is empty so poll() will
+        // block for the configured timeout and return null.
+        // The consumer should NOT send a null message.
         MockEndpoint out = getMockEndpoint("mock:result");
         out.expectedMessageCount(0);
 
diff --git 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java
 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java
index 29e1fd32527f..9eb2f11668ba 100644
--- 
a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java
+++ 
b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/NettyHttpSSLHandshakeErrorTest.java
@@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
 import org.junit.jupiter.api.condition.DisabledOnOs;
 
-import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
@@ -62,7 +61,11 @@ public class NettyHttpSSLHandshakeErrorTest extends 
BaseNettyTestSupport {
 
         assertTrue(response.isFailed(), "should have failed");
         assertNotNull(ex);
-        assertEquals(javax.net.ssl.SSLHandshakeException.class, ex.getClass(), 
"SSLHandshakeException expected");
+        // Netty may wrap SSLHandshakeException in DecoderException
+        boolean isSslError = ex instanceof javax.net.ssl.SSLHandshakeException
+                || (ex.getCause() instanceof 
javax.net.ssl.SSLHandshakeException);
+        assertTrue(isSslError,
+                "Expected SSLHandshakeException (possibly wrapped) but got: " 
+ ex.getClass().getName());
 
         MockEndpoint.assertIsSatisfied(context);
     }

Reply via email to