You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/02/02 08:53:41 UTC
[camel] branch camel-2.19.x updated: CAMEL-11996: RabbitConsumer could hang when RabbitMQ connection is lost and autoAck=false. Thanks to Joel Mongård for the unit test.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-2.19.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.19.x by this push:
new fe5e9f4 CAMEL-11996: RabbitConsumer could hang when RabbitMQ connection is lost and autoAck=false. Thanks to Joel Mongård for the unit test.
fe5e9f4 is described below
commit fe5e9f46bdc7106172d95762fa22c071a5b12468
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Feb 2 09:47:48 2018 +0100
CAMEL-11996: RabbitConsumer could hang when RabbitMQ connection is lost and autoAck=false. Thanks to Joel Mongård for the unit test.
---
.../camel/component/rabbitmq/RabbitConsumer.java | 4 ++
.../component/rabbitmq/RabbitConsumerHangTest.java | 54 ++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitConsumer.java b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitConsumer.java
index e96367c..d9a33d9 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitConsumer.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitConsumer.java
@@ -67,6 +67,10 @@ class RabbitConsumer implements com.rabbitmq.client.Consumer {
}
//Channel might be open because while we were waiting for the lock, stop() has been succesfully called.
if (!channel.isOpen()) {
+ // we could not open the channel so release the lock
+ if (!consumer.getEndpoint().isAutoAck()) {
+ lock.release();
+ }
return;
}
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitConsumerHangTest.java b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitConsumerHangTest.java
new file mode 100644
index 0000000..b4bf955
--- /dev/null
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitConsumerHangTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.rabbitmq;
+
+import com.rabbitmq.client.Channel;
+import com.rabbitmq.client.Connection;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import static org.junit.Assert.fail;
+
+public class RabbitConsumerHangTest {
+
+ private RabbitMQConsumer consumer = Mockito.mock(RabbitMQConsumer.class);
+ private RabbitMQEndpoint endpoint = Mockito.mock(RabbitMQEndpoint.class);
+ private Connection conn = Mockito.mock(Connection.class);
+ private Channel channel = Mockito.mock(Channel.class);
+
+ @Test(timeout = 5000)
+ public void testHandleDeliveryShouldNotHangForeverIfChanelWasClosed() throws Exception {
+ Mockito.when(consumer.getEndpoint()).thenReturn(endpoint);
+ Mockito.when(consumer.getConnection()).thenReturn(conn);
+ Mockito.when(conn.createChannel()).thenReturn(channel);
+ Mockito.when(channel.isOpen()).thenReturn(false).thenReturn(true);
+ Mockito.when(consumer.getEndpoint()).thenReturn(endpoint);
+
+ RabbitConsumer rabbitConsumer = new RabbitConsumer(consumer);
+
+ rabbitConsumer.handleDelivery(null, null, null, null);
+ // will now fail with some NPE which is expected as we have not mocked all the inner details
+ try {
+ rabbitConsumer.handleDelivery(null, null, null, null);
+ fail("Should have thrown NPE");
+ } catch (NullPointerException e) {
+ // expected
+ }
+
+ rabbitConsumer.stop();
+ }
+}
--
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.