activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1501878 - /activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
Date Wed, 10 Jul 2013 17:49:57 GMT
Author: tabish
Date: Wed Jul 10 17:49:56 2013
New Revision: 1501878

URL: http://svn.apache.org/r1501878
Log:
Adds a unit test that demonstrates how to properly unsubscribe and remove a durable subscription
and what happen when there is an active subscriber.  

Modified:
    activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java

Modified: activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java?rev=1501878&r1=1501877&r2=1501878&view=diff
==============================================================================
--- activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
(original)
+++ activemq/trunk/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java
Wed Jul 10 17:49:56 2013
@@ -980,6 +980,82 @@ public class Stomp11Test extends StompTe
     }
 
     @Test
+    public void testDurableSubAndUnSubFlow() throws Exception {
+        stompConnection.setVersion(Stomp.V1_1);
+
+        String domain = "org.apache.activemq";
+        ObjectName brokerName = new ObjectName(domain + ":type=Broker,brokerName=localhost");
+
+        BrokerViewMBean view = (BrokerViewMBean)brokerService.getManagementContext().newProxyInstance(brokerName,
BrokerViewMBean.class, true);
+
+        String connectFrame = "STOMP\n" +
+                "login:system\n" + "passcode:manager\n" + "accept-version:1.1\n" +
+                "host:localhost\n" + "client-id:test\n" + "\n" + Stomp.NULL;
+        stompConnection.sendFrame(connectFrame);
+
+        String frame = stompConnection.receiveFrame();
+        LOG.debug("Broker sent: " + frame);
+
+        assertTrue(frame.startsWith("CONNECTED"));
+        assertEquals(view.getDurableTopicSubscribers().length, 0);
+
+        // subscribe to first destination durably
+        frame = "SUBSCRIBE\n" +
+                "destination:/topic/" + getQueueName() + "1" + "\n" +
+                "ack:auto\n" + "receipt:1\n" + "id:durablesub-1\n" +
+                "activemq.subscriptionName:test1\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+
+        StompFrame receipt = stompConnection.receive();
+        LOG.debug("Broker sent: " + receipt);
+        assertTrue(receipt.getAction().startsWith("RECEIPT"));
+        assertEquals("1", receipt.getHeaders().get("receipt-id"));
+        assertEquals(view.getDurableTopicSubscribers().length, 1);
+
+        // attempt to remove the durable subscription while there is an active subscription
+        frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
+                "id:durablesub-1\n" + "receipt:3\n" +
+                "activemq.subscriptionName:test1\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+        receipt = stompConnection.receive();
+        LOG.debug("Broker sent: " + receipt);
+        assertTrue(receipt.getAction().startsWith("ERROR"));
+        assertEquals("3", receipt.getHeaders().get("receipt-id"));
+
+        assertEquals(view.getInactiveDurableTopicSubscribers().length, 0);
+        assertEquals(view.getDurableTopicSubscribers().length, 1);
+
+        // attempt to remove the subscriber leaving the durable sub in place.
+        frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
+                "id:durablesub-1\n" + "receipt:4\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+        receipt = stompConnection.receive();
+        LOG.debug("Broker sent: " + receipt);
+        assertTrue(receipt.getAction().startsWith("RECEIPT"));
+        assertEquals("4", receipt.getHeaders().get("receipt-id"));
+
+        assertEquals(view.getInactiveDurableTopicSubscribers().length, 1);
+        assertEquals(view.getDurableTopicSubscribers().length, 0);
+
+        // attempt to remove the durable subscription which should succeed since there are
no
+        // active durable subscribers
+        frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
+                "id:durablesub-1\n" + "receipt:5\n" +
+                "activemq.subscriptionName:test1\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+        receipt = stompConnection.receive();
+        LOG.debug("Broker sent: " + receipt);
+        assertTrue(receipt.getAction().startsWith("RECEIPT"));
+        assertEquals("5", receipt.getHeaders().get("receipt-id"));
+
+        assertEquals(view.getInactiveDurableTopicSubscribers().length, 0);
+        assertEquals(view.getDurableTopicSubscribers().length, 0);
+
+        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
+        stompConnection.sendFrame(frame);
+    }
+
+    @Test
     public void testMultipleDurableSubsWithOfflineMessages() throws Exception {
         stompConnection.setVersion(Stomp.V1_1);
 



Mime
View raw message