activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1235481 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/TopicRegion.java test/java/org/apache/activemq/bugs/AMQ3674Test.java test/java/org/apache/activemq/bugs/AMQ3675Test.java
Date Tue, 24 Jan 2012 20:37:07 GMT
Author: tabish
Date: Tue Jan 24 20:37:06 2012
New Revision: 1235481

URL: http://svn.apache.org/viewvc?rev=1235481&view=rev
Log:
fix and test for: https://issues.apache.org/jira/browse/AMQ-3675

Added:
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java 
 (with props)
Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3674Test.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java?rev=1235481&r1=1235480&r2=1235481&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/TopicRegion.java
Tue Jan 24 20:37:06 2012
@@ -195,7 +195,7 @@ public class TopicRegion extends Abstrac
             destinationsLock.readLock().unlock();
         }
 
-        if (subscriptions.get(sub.getConsumerInfo()) != null) {
+        if (subscriptions.get(sub.getConsumerInfo().getConsumerId()) != null) {
             super.removeConsumer(context, sub.getConsumerInfo());
         } else {
             // try destroying inactive subscriptions

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3674Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3674Test.java?rev=1235481&r1=1235480&r2=1235481&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3674Test.java (original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3674Test.java Tue
Jan 24 20:37:06 2012
@@ -24,7 +24,6 @@ import javax.jms.DeliveryMode;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TopicSubscriber;
-import javax.management.ObjectName;
 
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.broker.BrokerService;

Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java?rev=1235481&view=auto
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java (added)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java Tue
Jan 24 20:37:06 2012
@@ -0,0 +1,161 @@
+/**
+ * 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.activemq.bugs;
+
+import static org.junit.Assert.*;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TopicSubscriber;
+import javax.management.ObjectName;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.TransportConnector;
+import org.apache.activemq.broker.jmx.BrokerView;
+import org.apache.activemq.broker.jmx.TopicViewMBean;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.util.Wait;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AMQ3675Test {
+
+    private static Logger LOG = LoggerFactory.getLogger(AMQ3675Test.class);
+
+    private final static int deliveryMode = DeliveryMode.NON_PERSISTENT;
+    private final static ActiveMQTopic destination = new ActiveMQTopic("XYZ");
+
+    private ActiveMQConnectionFactory factory;
+    private BrokerService broker;
+
+    public TopicViewMBean getTopicView() throws Exception {
+        ObjectName destinationName = broker.getAdminView().getTopics()[0];
+        TopicViewMBean topicView = (TopicViewMBean) broker.getManagementContext().newProxyInstance(destinationName,
TopicViewMBean.class, true);
+        return topicView;
+    }
+
+    @Test
+    public void countConsumers() throws Exception {
+
+        final Connection producerConnection = factory.createConnection();
+        producerConnection.start();
+        final Connection consumerConnection = factory.createConnection();
+
+        consumerConnection.setClientID("subscriber1");
+        Session consumerMQSession = consumerConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+        TopicSubscriber consumer = consumerMQSession.createDurableSubscriber(destination,
"myTopic");
+        consumerConnection.start();
+
+        Session session = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        MessageProducer producer = session.createProducer(destination);
+        producer.setDeliveryMode(deliveryMode);
+
+        final BrokerView brokerView = broker.getAdminView();
+        final TopicViewMBean topicView = getTopicView();
+
+        assertTrue("Should have one consumer on topic: ", Wait.waitFor(new Wait.Condition()
{
+            @Override
+            public boolean isSatisified() throws Exception {
+                return topicView.getConsumerCount() == 1;
+            }
+        }));
+
+        consumer.close();
+
+        assertTrue("Durable consumer should now be inactive.", Wait.waitFor(new Wait.Condition()
{
+            @Override
+            public boolean isSatisified() throws Exception {
+                return brokerView.getInactiveDurableTopicSubscribers().length == 1;
+            }
+        }));
+
+        try {
+            brokerView.removeTopic(destination.getTopicName());
+        } catch (Exception e1) {
+            fail("Unable to remove destination:" + destination.getPhysicalName());
+        }
+
+        assertTrue("Should have no topics on the broker", Wait.waitFor(new Wait.Condition()
{
+            @Override
+            public boolean isSatisified() throws Exception {
+                return brokerView.getTopics().length == 0;
+            }
+        }));
+
+        try {
+            brokerView.destroyDurableSubscriber("subscriber1", "myTopic");
+        } catch(Exception e) {
+            fail("Exception not expected when attempting to delete Durable consumer.");
+        }
+
+        assertTrue("Should be no durable consumers active or inactive.", Wait.waitFor(new
Wait.Condition() {
+            @Override
+            public boolean isSatisified() throws Exception {
+                return brokerView.getInactiveDurableTopicSubscribers().length == 0 &&
+                       brokerView.getDurableTopicSubscribers().length == 0;
+            }
+        }));
+
+        consumer = consumerMQSession.createDurableSubscriber(destination, "myTopic");
+
+        consumer.close();
+
+        assertTrue("Should be one consumer on the Topic.", Wait.waitFor(new Wait.Condition()
{
+            @Override
+            public boolean isSatisified() throws Exception {
+                LOG.info("Number of inactive consumers: " + brokerView.getInactiveDurableTopicSubscribers().length);
+                return brokerView.getInactiveDurableTopicSubscribers().length == 1;
+            }
+        }));
+
+        final TopicViewMBean recreatedTopicView = getTopicView();
+
+        assertTrue("Should have one consumer on topic: ", Wait.waitFor(new Wait.Condition()
{
+            @Override
+            public boolean isSatisified() throws Exception {
+                return recreatedTopicView.getConsumerCount() == 1;
+            }
+        }));
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        broker = new BrokerService();
+        broker.setPersistent(false);
+        broker.setUseJmx(true);
+        broker.setAdvisorySupport(false);
+        broker.setDeleteAllMessagesOnStartup(true);
+        TransportConnector connector = broker.addConnector("tcp://localhost:0");
+        broker.start();
+
+        factory = new ActiveMQConnectionFactory(connector.getPublishableConnectString());
+        factory.setAlwaysSyncSend(true);
+        factory.setDispatchAsync(false);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        broker.stop();
+    }
+}

Propchange: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/bugs/AMQ3675Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message