From 41ca0d94647ad303c22eb1e86796203fd69dbb44 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Thu, 16 Oct 2014 16:11:26 -0400 Subject: [PATCH] Add a test case for durable topic unsubscribe. --- .../transport/amqp/JMSClientTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTest.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTest.java index 2122470e92..65ec92cf08 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTest.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/JMSClientTest.java @@ -42,6 +42,7 @@ import javax.jms.Session; import javax.jms.TextMessage; import javax.jms.Topic; +import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.broker.jmx.ConnectorViewMBean; import org.apache.activemq.broker.jmx.QueueViewMBean; import org.apache.activemq.transport.amqp.joram.ActiveMQAdmin; @@ -628,6 +629,50 @@ public class JMSClientTest extends JMSClientTestSupport { } } + @Test(timeout=30000) + public void testDurableConsumerUnsubscribe() throws Exception { + ActiveMQAdmin.enableJMSFrameTracing(); + + final BrokerViewMBean broker = getProxyToBroker(); + + connection = createConnection(); + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + Topic topic = session.createTopic(getDestinationName()); + MessageConsumer consumer = session.createDurableSubscriber(topic, "DurbaleTopic"); + + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return broker.getInactiveDurableTopicSubscribers().length == 0 && + broker.getDurableTopicSubscribers().length == 1; + } + })); + + consumer.close(); + + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return broker.getInactiveDurableTopicSubscribers().length == 1 && + broker.getDurableTopicSubscribers().length == 0; + } + })); + + session.unsubscribe("DurbaleTopic"); + assertTrue(Wait.waitFor(new Wait.Condition() { + + @Override + public boolean isSatisified() throws Exception { + return broker.getInactiveDurableTopicSubscribers().length == 0 && + broker.getDurableTopicSubscribers().length == 0; + } + })); + } + @Test(timeout=30000) public void testTopicConsumerAsync() throws Exception { ActiveMQAdmin.enableJMSFrameTracing();