ramu11 commented on code in PR #26006:
URL: https://github.com/apache/camel/pull/26006#discussion_r3910340515


##########
components/camel-hivemq/src/test/java/org/apache/camel/component/hivemq/HiveMQConsumerReleaseTest.java:
##########
@@ -0,0 +1,126 @@
+/*
+ * 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.hivemq;
+
+import java.lang.reflect.Method;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.support.AsyncProcessorSupport;
+import org.apache.camel.support.DefaultExchange;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class HiveMQConsumerReleaseTest {
+
+    private DefaultCamelContext camelContext;
+    private HiveMQComponent component;
+    private HiveMQEndpoint endpoint;
+
+    @BeforeEach
+    void setUp() {
+        camelContext = new DefaultCamelContext();
+        component = new HiveMQComponent();
+        component.setCamelContext(camelContext);
+        endpoint = new HiveMQEndpoint("hivemq:test", component, new 
HiveMQConfiguration(), "test");
+        endpoint.setCamelContext(camelContext);
+    }
+
+    @AfterEach
+    void tearDown() {
+        camelContext.stop();
+    }
+
+    @Test
+    @DisplayName("Synchronous processing releases the exchange exactly once")
+    void syncProcessingReleasesOnce() throws Exception {
+        CountingConsumer consumer = new CountingConsumer(endpoint, exchange -> 
{
+        });
+
+        invokeProcessExchange(consumer, new DefaultExchange(camelContext));
+
+        assertThat(consumer.releases.get()).isEqualTo(1);
+    }
+
+    @Test
+    @DisplayName("Asynchronous processing releases the exchange exactly once")
+    void asyncProcessingReleasesOnce() throws Exception {
+        CountDownLatch processed = new CountDownLatch(1);
+        CountingConsumer consumer = new CountingConsumer(endpoint, new 
AsyncProcessorSupport() {
+            @Override
+            public boolean process(Exchange exchange, AsyncCallback callback) {
+                CompletableFuture.runAsync(() -> {
+                    callback.done(false);
+                    processed.countDown();
+                });
+                return false;
+            }
+        });
+
+        invokeProcessExchange(consumer, new DefaultExchange(camelContext));
+        assertThat(processed.await(5, TimeUnit.SECONDS)).isTrue();
+
+        assertThat(consumer.releases.get()).isEqualTo(1);
+    }
+
+    @Test
+    @DisplayName("Callback plus thrown exception still releases the exchange 
exactly once")
+    void callbackThenThrowReleasesOnce() throws Exception {
+        CountingConsumer consumer = new CountingConsumer(endpoint, new 
AsyncProcessorSupport() {
+            @Override
+            public boolean process(Exchange exchange, AsyncCallback callback) {
+                callback.done(true);
+                throw new RuntimeException("after callback");
+            }
+        });
+
+        invokeProcessExchange(consumer, new DefaultExchange(camelContext));
+
+        assertThat(consumer.releases.get()).isEqualTo(1);
+    }
+
+    private static void invokeProcessExchange(HiveMQConsumer consumer, 
Exchange exchange) throws Exception {

Review Comment:
   Thanks, agreed. I’ll keep this as-is for now since it’s only a minor test 
refactoring suggestion and not blocking. I’ll consider making `processExchange` 
package-private in a follow-up cleanup.
   



-- 
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]

Reply via email to