activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cepo...@apache.org
Subject svn commit: r1446979 - /activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
Date Sun, 17 Feb 2013 00:05:42 GMT
Author: ceposta
Date: Sun Feb 17 00:05:41 2013
New Revision: 1446979

URL: http://svn.apache.org/r1446979
Log:
Fix for https://issues.apache.org/jira/browse/AMQ-4000 Added test for multiple durable consumers
across the network, per Gary's comments

Modified:
    activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java

Modified: activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java?rev=1446979&r1=1446978&r2=1446979&view=diff
==============================================================================
--- activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
(original)
+++ activemq/trunk/activemq-unit-tests/src/test/java/org/apache/activemq/usecases/DurableSubInBrokerNetworkTest.java
Sun Feb 17 00:05:41 2013
@@ -26,8 +26,6 @@ import javax.jms.TopicSubscriber;
 
 import javax.management.ObjectName;
 
-import junit.framework.Assert;
-
 import org.apache.activemq.ActiveMQConnectionFactory;
 import org.apache.activemq.network.DiscoveryNetworkConnector;
 import org.apache.activemq.network.NetworkConnector;
@@ -46,6 +44,7 @@ public class DurableSubInBrokerNetworkTe
     private static final Logger LOG = LoggerFactory.getLogger(NetworkConnector.class);
     // protected BrokerService localBroker;
     private final String subName = "Subscriber1";
+    private final String subName2 = "Subscriber2";
     private final String topicName = "TEST.FOO";
 
     protected void setUp() throws Exception {
@@ -94,22 +93,11 @@ public class DurableSubInBrokerNetworkTe
 
         // query durable sub on local and remote broker
         // raise an error if not found
-        boolean foundSub = false;
-        ObjectName[] subs = broker.getAdminView().getDurableTopicSubscribers();
-        
-        for (int i=0 ; i<subs.length; i++) {
-            if (subs[i].toString().contains(subName))
-                foundSub = true;
-        }
-        Assert.assertTrue(foundSub);
 
-        foundSub = false;
-        subs = remoteBroker.getAdminView().getDurableTopicSubscribers();
-        for (int i=0 ; i<subs.length; i++) {
-            if (subs[i].toString().contains("destinationName=" + topicName))
-                foundSub = true;
-        }
-        Assert.assertTrue(foundSub);
+        assertTrue(foundSubInLocalBroker(subName));
+
+
+        assertTrue(foundSubInRemoteBrokerByTopicName(topicName));
 
         // unsubscribe from durable sub
         sub.close();
@@ -119,22 +107,71 @@ public class DurableSubInBrokerNetworkTe
 
         // query durable sub on local and remote broker
         // raise an error if its not removed from both brokers
-        foundSub = false;
-        subs = broker.getAdminView().getDurableTopicSubscribers();
-        for (int i=0 ; i<subs.length; i++) {
-            if (subs[i].toString().contains(subName))
-                foundSub = true;
-        }
-        Assert.assertFalse(foundSub);
+        assertFalse(foundSubInLocalBroker(subName));
+
+        assertFalse("Durable subscription not unregistered on remote broker",
+                foundSubInRemoteBrokerByTopicName(topicName));
+
+
+    }
+
+    public void testTwoDurableSubsInNetworkWithUnsubscribe() throws Exception{
 
-        foundSub = false;
-        subs = remoteBroker.getAdminView().getDurableTopicSubscribers();
+        // create 1st durable sub to topic TEST.FOO
+        ActiveMQConnectionFactory fact = new ActiveMQConnectionFactory(connector.getConnectUri().toString());
+        Connection conn = fact.createConnection();
+        conn.setClientID("clientID1");
+        Session session = conn.createSession(false, 1);
+        Destination dest = session.createTopic(topicName);
+        TopicSubscriber sub = session.createDurableSubscriber((Topic)dest, subName);
+        LOG.info("Durable subscription of name " + subName + "created.");
+        TopicSubscriber sub2 = session.createDurableSubscriber((Topic) dest, subName2);
+        LOG.info("Durable subscription of name " + subName2 + "created.");
+
+        Thread.sleep(100);
+
+        // query durable sub on local and remote broker
+        // raise an error if not found
+
+        assertTrue(foundSubInLocalBroker(subName));
+        assertTrue(foundSubInLocalBroker(subName2));
+
+
+        assertTrue(foundSubInRemoteBrokerByTopicName(topicName));
+
+        // unsubscribe from durable sub
+        sub.close();
+        session.unsubscribe(subName);
+        LOG.info("Unsubscribed from durable subscription.");
+        Thread.sleep(100);
+
+        // query durable sub on local and remote broker
+        assertFalse(foundSubInLocalBroker(subName));
+        assertTrue(foundSubInLocalBroker(subName2));
+
+        assertTrue("Durable subscription should still be on remote broker",
+                foundSubInRemoteBrokerByTopicName(topicName));
+
+    }
+
+    private boolean foundSubInRemoteBrokerByTopicName(String topicName) throws Exception
{
+        boolean foundSub = false;
+        ObjectName[] subs = remoteBroker.getAdminView().getDurableTopicSubscribers();
         for (int i=0 ; i<subs.length; i++) {
             if (subs[i].toString().contains("destinationName=" + topicName))
                 foundSub = true;
         }
-        Assert.assertFalse("Durable subscription not unregistered on remote broker", foundSub);
+        return foundSub;
+    }
 
+    private boolean foundSubInLocalBroker(String subName) throws Exception {
+        boolean foundSub = false;
+        ObjectName[] subs = broker.getAdminView().getDurableTopicSubscribers();
 
+        for (int i=0 ; i<subs.length; i++) {
+            if (subs[i].toString().contains(subName))
+                foundSub = true;
+        }
+        return foundSub;
     }
 }



Mime
View raw message