You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2016/11/17 22:47:03 UTC

qpid-jms git commit: QPIDJMS-220 Additional testing of the Subscription Tracker

Repository: qpid-jms
Updated Branches:
  refs/heads/master 529ca03c1 -> e96821664


QPIDJMS-220 Additional testing of the Subscription Tracker

Add some additional testing of the subscription tracker to cover
expected exceptions and other cases not yet covered. 

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e9682166
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e9682166
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e9682166

Branch: refs/heads/master
Commit: e9682166439b311125c4e156bc40880c16c0f464
Parents: 529ca03
Author: Timothy Bish <ta...@gmail.com>
Authored: Thu Nov 17 17:46:37 2016 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Thu Nov 17 17:46:37 2016 -0500

----------------------------------------------------------------------
 .../amqp/AmqpSubscriptionTrackerTest.java       | 241 ++++++++++++++++++-
 1 file changed, 239 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e9682166/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSubscriptionTrackerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSubscriptionTrackerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSubscriptionTrackerTest.java
index 2a7c893..daa0b56 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSubscriptionTrackerTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSubscriptionTrackerTest.java
@@ -26,6 +26,8 @@ import static org.junit.Assert.fail;
 
 import java.util.concurrent.atomic.AtomicInteger;
 
+import javax.jms.JMSRuntimeException;
+
 import org.apache.qpid.jms.JmsTopic;
 import org.apache.qpid.jms.meta.JmsConsumerId;
 import org.apache.qpid.jms.meta.JmsConsumerInfo;
@@ -40,7 +42,7 @@ public class AmqpSubscriptionTrackerTest {
     }
 
     private JmsConsumerInfo createConsumerInfo(String subscriptionName, String topicName, boolean shared, boolean durable, String selector, boolean isExplicitClientID) {
-        JmsConsumerId consumerId = new JmsConsumerId("ID:MOCK:1", 1, consumerIdCounter .incrementAndGet());
+        JmsConsumerId consumerId = new JmsConsumerId("ID:MOCK:1", 1, consumerIdCounter.incrementAndGet());
         JmsTopic topic = new JmsTopic(topicName);
 
         JmsConsumerInfo consumerInfo = new JmsConsumerInfo(consumerId);
@@ -56,6 +58,36 @@ public class AmqpSubscriptionTrackerTest {
     }
 
     @Test
+    public void testReserveNextSubscriptionLinkNameExceptions() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        JmsConsumerInfo consumerInfo = createConsumerInfo(subscriptionName1, topicName, true, true, true);
+
+        try {
+            tracker.reserveNextSubscriptionLinkName(null, consumerInfo);
+            fail("Should throw IAE on null subscription name");
+        } catch (IllegalArgumentException iae) {}
+
+        try {
+            tracker.reserveNextSubscriptionLinkName("", consumerInfo);
+            fail("Should throw IAE on empty subscription name");
+        } catch (IllegalArgumentException iae) {}
+
+        try {
+            tracker.reserveNextSubscriptionLinkName("test" + SUB_NAME_DELIMITER, consumerInfo);
+            fail("Should throw IAE on subscription name with delimiter");
+        } catch (IllegalArgumentException iae) {}
+
+        try {
+            tracker.reserveNextSubscriptionLinkName("test", null);
+            fail("Should throw IAE on null Consumer Info");
+        } catch (IllegalArgumentException iae) {}
+    }
+
+    @Test
     public void testReserveNextSubscriptionLinkNameSharedDurable() {
         String topicName = "myTopic";
         String subscriptionName1 = "mySubscription1";
@@ -83,6 +115,67 @@ public class AmqpSubscriptionTrackerTest {
     }
 
     @Test
+    public void testReserveNextSubscriptionLinkNameSharedDurableWithNonMatchingSelector() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name with selector 'color = red'
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, true, "color = red", true);
+        assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // For the next shared sub name with selector 'color = blue'
+        JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName, true, true, "color = blue", true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+
+        // For the next shared sub name with selector 'color = blue'
+        JmsConsumerInfo sub1consumer3 = createConsumerInfo(subscriptionName1, topicName, true, true, true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer3);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+
+        // Remove the consumer and add a new one with no selector
+        tracker.consumerRemoved(sub1consumer1);
+
+        JmsConsumerInfo sub1consumer4 = createConsumerInfo(subscriptionName1, topicName, true, true, true);
+        assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer4));
+
+        // Try adding the second consumer again with selector "color = blue"
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+    }
+
+    @Test
+    public void testReserveNextSubscriptionLinkNameSharedDurableWithNonMatchingTopic() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name on Topic
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, true, true);
+        assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // For the next shared sub name on different Topic
+        JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName + "-Alt", true, true, true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when Topic doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+    }
+
+    @Test
     public void testReserveNextSubscriptionLinkNameSharedDurableWithoutClientID() {
         String topicName = "myTopic";
         String subscriptionName1 = "mySubscription1";
@@ -118,22 +211,90 @@ public class AmqpSubscriptionTrackerTest {
         AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
 
         // For the first shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName1));
         JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
         assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName1));
         JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
         assertEquals("Unexpected second sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile2", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName1));
 
         // For the second shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
         JmsConsumerInfo sub2consumer1 = createConsumerInfo(subscriptionName2, topicName, true, false, true);
         assertEquals("Unexpected first sub link name", subscriptionName2 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer1));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
         JmsConsumerInfo sub2consumer2 = createConsumerInfo(subscriptionName2, topicName, true, false, true);
         assertEquals("Unexpected second sub link name", subscriptionName2 + SUB_NAME_DELIMITER + "volatile2", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer2));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
 
         // Register a third subscriber for a subscription, after removing the first subscriber for the subscription.
         // Validate the new link name isn't the same as the second subscribers (which is still using its name...)
         tracker.consumerRemoved(sub2consumer1);
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
         JmsConsumerInfo sub2consumer3 = createConsumerInfo(subscriptionName2, topicName, true, false, true);
         assertEquals("Unexpected third subscriber link name", subscriptionName2 + SUB_NAME_DELIMITER + "volatile3", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer3));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
+    }
+
+    @Test
+    public void testReserveNextSubscriptionLinkNameSharedVolatileWithNonMatchingSelector() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name with selector 'color = red'
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, "color = red", true);
+        assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // For the next shared sub name with selector 'color = blue'
+        JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName, true, false, "color = blue", true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+
+        // For the first shared sub name with no selector
+        JmsConsumerInfo sub1consumer3 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer3);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+
+        // Remove the consumer and add the third one which has no selector
+        tracker.consumerRemoved(sub1consumer1);
+
+        assertEquals("Unexpected second sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer3));
+
+        // Try adding the second consumer again with selector "color = blue"
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when selector doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
+    }
+
+    @Test
+    public void testReserveNextSubscriptionLinkNameSharedVolatileWithNonMatchingTopic() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name with Topic
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
+        assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // For the next shared sub name with different Topic
+        JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName + "-alt", true, false, true);
+        try {
+            tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
+            fail("Expected JMSRuntimeException when Topic doesn't match previous subscription");
+        } catch (JMSRuntimeException jmsre) {
+        }
     }
 
     @Test
@@ -145,16 +306,20 @@ public class AmqpSubscriptionTrackerTest {
         AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
 
         // For the first shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName1));
         JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, false);
         assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "global-volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
         JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName, true, false, false);
         assertEquals("Unexpected second sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "global-volatile2", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName1));
 
         // For the second shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
         JmsConsumerInfo sub2consumer1 = createConsumerInfo(subscriptionName2, topicName, true, false, false);
         assertEquals("Unexpected first sub link name", subscriptionName2 + SUB_NAME_DELIMITER + "global-volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer1));
         JmsConsumerInfo sub2consumer2 = createConsumerInfo(subscriptionName2, topicName, true, false, false);
         assertEquals("Unexpected second sub link name", subscriptionName2 + SUB_NAME_DELIMITER + "global-volatile2", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer2));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveSharedVolatileSub(subscriptionName2));
 
         // Register a third subscriber for a subscription, after removing the first subscriber for the subscription.
         // Validate the new link name isn't the same as the second subscribers (which is still using its name...)
@@ -162,6 +327,7 @@ public class AmqpSubscriptionTrackerTest {
         JmsConsumerInfo sub2consumer3 = createConsumerInfo(subscriptionName2, topicName, true, false, false);
         assertEquals("Unexpected third subscriber link name", subscriptionName2 + SUB_NAME_DELIMITER + "global-volatile3", tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer3));
     }
+
     @Test
     public void testReserveNextSubscriptionLinkNameExclusiveDurable() {
         String topicName = "myTopic";
@@ -171,16 +337,20 @@ public class AmqpSubscriptionTrackerTest {
         AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
 
         // For the first shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveExclusiveDurableSub(subscriptionName1));
         JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, false, true, true);
         assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveExclusiveDurableSub(subscriptionName1));
         // This shouldn't happen, checks elsewhere should stop requests for an exclusive durable sub link
         // name if its already in use, but check we get the same name anyway even with an existing registration.
         JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName, false, true, true);
         assertEquals("Unexpected second sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2));
 
         // For the second shared sub name
+        assertFalse("Should be active shard volatile sub", tracker.isActiveExclusiveDurableSub(subscriptionName2));
         JmsConsumerInfo sub2consumer1 = createConsumerInfo(subscriptionName2, topicName, false, true, true);
         assertEquals("Unexpected first sub link name", subscriptionName2, tracker.reserveNextSubscriptionLinkName(subscriptionName2, sub2consumer1));
+        assertTrue("Should be active shard volatile sub", tracker.isActiveExclusiveDurableSub(subscriptionName2));
         // This shouldn't happen, checks elsewhere should stop requests for an exclusive durable sub link
         // name if its already in use, but check we get the same name anyway even with an existing registration.
         JmsConsumerInfo sub2consumer2 = createConsumerInfo(subscriptionName2, topicName, false, true, true);
@@ -282,4 +452,71 @@ public class AmqpSubscriptionTrackerTest {
         assertFalse(tracker2.isActiveExclusiveDurableSub(subscriptionName));
         assertFalse(tracker2.isActiveSharedDurableSub(subscriptionName));
     }
-}
+
+    @Test
+    public void testConsumerRemovedIgnoresConsumersWithoutSubscriptions() {
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // Should not throw for no subscription
+        JmsConsumerInfo subInfo1 = createConsumerInfo(null, "myTopic", true, true, true);
+        tracker.consumerRemoved(subInfo1);
+
+        // Should not throw for empty subscription
+        JmsConsumerInfo subInfo2 = createConsumerInfo("", "myTopic", true, true, true);
+        tracker.consumerRemoved(subInfo2);
+    }
+
+    @Test
+    public void testConsumerRemovedIgnoresUntrackedSharedDurable() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+        String subscriptionName2 = "mySubscription2";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, true, true);
+        assertEquals("Unexpected first sub link name", subscriptionName1, tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // Create another shared sub that is not registered and remove it
+        JmsConsumerInfo sub2consumer1 = createConsumerInfo(subscriptionName2, topicName, true, true, true);
+
+        tracker.consumerRemoved(sub2consumer1);
+
+        // First sub should still be active
+        assertTrue(tracker.isActiveSharedDurableSub(subscriptionName1));
+
+        // remove the first one and it should now go inactive.
+        tracker.consumerRemoved(sub1consumer1);
+
+        // First sub should still be active
+        assertFalse(tracker.isActiveSharedDurableSub(subscriptionName1));
+    }
+
+    @Test
+    public void testConsumerRemovedIgnoresUntrackedSharedVolatile() {
+        String topicName = "myTopic";
+        String subscriptionName1 = "mySubscription1";
+        String subscriptionName2 = "mySubscription2";
+
+        AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();
+
+        // For the first shared sub name
+        JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
+        assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));
+
+        // Create another shared sub that is not registered and remove it
+        JmsConsumerInfo sub2consumer1 = createConsumerInfo(subscriptionName2, topicName, true, false, true);
+
+        tracker.consumerRemoved(sub2consumer1);
+
+        // First sub should still be active
+        assertTrue(tracker.isActiveSharedVolatileSub(subscriptionName1));
+
+        // remove the first one and it should now go inactive.
+        tracker.consumerRemoved(sub1consumer1);
+
+        // First sub should still be active
+        assertFalse(tracker.isActiveSharedVolatileSub(subscriptionName1));
+    }
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org