From 9988a3c94fc75163b55e2e7fb936bd8cc8a7ae07 Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 10 Jul 2013 17:49:56 +0000 Subject: [PATCH] Adds a unit test that demonstrates how to properly unsubscribe and remove a durable subscription and what happen when there is an active subscriber. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1501878 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/transport/stomp/Stomp11Test.java | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java b/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java index 5f099b24ca..2e3a49e968 100644 --- a/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java +++ b/activemq-stomp/src/test/java/org/apache/activemq/transport/stomp/Stomp11Test.java @@ -979,6 +979,82 @@ public class Stomp11Test extends StompTestSupport { stompConnection.sendFrame(frame); } + @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);