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 b5f409d436ea CAMEL-23886: Fix flaky NatsConsumerWithRedeliveryIT 
(#24609)
b5f409d436ea is described below

commit b5f409d436eafad69c8fe6c933f3787ed779d26a
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sun Jul 12 08:33:41 2026 +0200

    CAMEL-23886: Fix flaky NatsConsumerWithRedeliveryIT (#24609)
    
    CAMEL-23886: Fix flaky NatsConsumerWithRedeliveryIT
    
    Co-authored-by: Claude Opus 4.6 <[email protected]>
---
 .../nats/integration/NatsConsumerWithRedeliveryIT.java | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git 
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
index b3dbd92db2dc..2325041eb91b 100644
--- 
a/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
+++ 
b/components/camel-nats/src/test/java/org/apache/camel/component/nats/integration/NatsConsumerWithRedeliveryIT.java
@@ -20,13 +20,14 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.EndpointInject;
 import org.apache.camel.LoggingLevel;
+import org.apache.camel.Route;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.nats.NatsConsumer;
 import org.junit.jupiter.api.Test;
 
 import static org.awaitility.Awaitility.await;
-import static org.junit.jupiter.api.Assertions.assertEquals;
 
 public class NatsConsumerWithRedeliveryIT extends NatsITSupport {
 
@@ -43,16 +44,17 @@ public class NatsConsumerWithRedeliveryIT extends 
NatsITSupport {
         mockResultEndpoint.setExpectedMessageCount(1);
         exception.setExpectedMessageCount(1);
 
+        // Wait for the NATS consumer to be subscribed before sending messages,
+        // since core NATS does not persist messages for inactive subscribers
+        await().atMost(10, TimeUnit.SECONDS)
+                .until(() -> context.getRoutes().stream()
+                        .map(Route::getConsumer)
+                        .anyMatch(c -> c instanceof NatsConsumer nc && 
nc.isActive()));
+
         template.sendBody("direct:send", "test");
         template.sendBody("direct:send", "golang");
 
-        await().atMost(30, TimeUnit.SECONDS)
-                .untilAsserted(() -> {
-                    assertEquals(1, exception.getReceivedCounter(),
-                            "mock:exception should have received the message 
after redelivery exhaustion");
-                    assertEquals(1, mockResultEndpoint.getReceivedCounter(),
-                            "mock:result should have received the non-failing 
message");
-                });
+        MockEndpoint.assertIsSatisfied(context, 30, TimeUnit.SECONDS);
     }
 
     @Override

Reply via email to