This is an automated email from the ASF dual-hosted git repository. apupier pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 3f6f8aacca946aba7829821a4cdcc90f3fe1162f Author: Aurélien Pupier <[email protected]> AuthorDate: Wed Nov 25 14:33:25 2026 +0100 CAMEL-26366: camel-nats - the new test no longer polls the state of the disconnecting thread Review comment of gnodet-bot on the PR: the test waited for the disconnecting thread to be in Thread.State.TIMED_WAITING, which relies on Awaitility sleeping between two checks. The thread can be RUNNABLE while the predicate is evaluated, so this is not strictly deterministic. FakeServer.disconnect() now counts down a latch (disconnectWaiting) as its first step, and the test waits on that latch instead of reading the state of the thread. It then checks that the server stays connected for 2 seconds (Awaitility during, with an explicit atMost) and that the disconnecting thread is still alive, before it releases the listener. Verification: NatsConsumerPushConsumerDeletedTest, 14 of 14 tests passed in 2 runs (mvn -o test -Dtest=NatsConsumerPushConsumerDeletedTest). Co-authored-by: IBM Bob 2.2.1 Signed-off-by: Aurélien Pupier <[email protected]> --- .../resources/META-INF/org/apache/camel/component/nats/nats.json | 2 +- .../component/nats/NatsConsumerPushConsumerDeletedTest.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json b/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json index bda963743d05..5eed5b88b3db 100644 --- a/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json +++ b/components/camel-nats/src/generated/resources/META-INF/org/apache/camel/component/nats/nats.json @@ -78,7 +78,7 @@ "CamelNatsQueueName": { "index": 4, "kind": "header", "displayName": "", "group": "common", "label": "", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "description": "The Queue name of a consumed message (may be null).", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_QUEUE_NAME" }, "CamelNatsStatusCode": { "index": 5, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "important": true, "description": "Status message code", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_STATUS_CODE" }, "CamelNatsStatusError": { "index": 6, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "String", "deprecated": false, "autowired": false, "secret": false, "important": true, "description": "Status message error message", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_STATUS_ERROR" }, - "CamelNatsDeliveryCounter": { "index": 7, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "important": true, "description": "Number of times this message has been delivered (1 = first, > 1 then message has been redelivered)", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_DELIVERY_COUNTER" }, + "CamelNatsDeliveryCounter": { "index": 7, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "long", "deprecated": false, "autowired": false, "secret": false, "important": true, "description": "Number of times this message has been delivered (1 = first, 1 then message has been redelivered)", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_DELIVERY_COUNTER" }, "CamelNatsManualAck": { "index": 8, "kind": "header", "displayName": "", "group": "consumer", "label": "consumer", "required": false, "javaType": "org.apache.camel.component.nats.NatsManualAck", "deprecated": false, "autowired": false, "secret": false, "description": "The manual acknowledgment handle for JetStream messages (only set when manualAck=true).", "constantName": "org.apache.camel.component.nats.NatsConstants#NATS_MANUAL_ACK" } }, "bodyTypes": { diff --git a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerPushConsumerDeletedTest.java b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerPushConsumerDeletedTest.java index ed5cf58ddefb..393beac6d083 100644 --- a/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerPushConsumerDeletedTest.java +++ b/components/camel-nats/src/test/java/org/apache/camel/component/nats/NatsConsumerPushConsumerDeletedTest.java @@ -278,9 +278,9 @@ class NatsConsumerPushConsumerDeletedTest extends CamelTestSupport { disconnecting.start(); // the disconnect must wait for the listener, else it deletes the consumer that is being subscribed and the // reconnect reaches nobody - await().atMost(10, TimeUnit.SECONDS) - .until(() -> disconnecting.getState() == Thread.State.TIMED_WAITING); - assertTrue(server.isConnected(), "not disconnected while the consumer does not listen"); + assertTrue(server.disconnectWaiting.await(10, TimeUnit.SECONDS), "the disconnect started"); + await().during(2, TimeUnit.SECONDS).atMost(10, TimeUnit.SECONDS).until(server::isConnected); + assertTrue(disconnecting.isAlive(), "the disconnect waits while the consumer does not listen"); release.countDown(); disconnecting.join(30_000); @@ -583,6 +583,8 @@ class NatsConsumerPushConsumerDeletedTest extends CamelTestSupport { int consumersCreated; // runs on the thread that subscribes, before the subscription is made volatile Runnable beforeSubscribe; + // counted down when a disconnect starts to wait until the consumer listens to the connection + final CountDownLatch disconnectWaiting = new CountDownLatch(1); // runs on the thread that adds a connection listener, before the listener is added volatile Runnable beforeAddListener; Connection connection; @@ -634,6 +636,7 @@ class NatsConsumerPushConsumerDeletedTest extends CamelTestSupport { } void disconnect() { + disconnectWaiting.countDown(); // the consumer subscribes on its own executor and listens to the connection only once the subscribe // returned, which can be after it delivered its first message: a disconnect before that deletes the // consumer that is being subscribed, and the reconnect reaches no keeper, so nothing checks the consumer
