[jboss-cvs] JBoss Messaging SVN: r1403 - in branches/Branch_1_0: src/main/org/jboss/jms/server/endpoint tests/src/org/jboss/test/messaging/jms

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Sep 29 17:07:13 EDT 2006


Author: ovidiu.feodorov at jboss.com
Date: 2006-09-29 17:07:09 -0400 (Fri, 29 Sep 2006)
New Revision: 1403

Modified:
   branches/Branch_1_0/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
   branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
Log:
changes related to http://jira.jboss.org/jira/browse/JBMESSAGING-564. Introduced a new consistency check (that the durable subscription cannot be removed if there are active consumers for it) and adjusted tests accordingly

Modified: branches/Branch_1_0/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- branches/Branch_1_0/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2006-09-29 21:04:19 UTC (rev 1402)
+++ branches/Branch_1_0/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2006-09-29 21:07:09 UTC (rev 1403)
@@ -578,6 +578,8 @@
    
    public void unsubscribe(String subscriptionName) throws JMSException
    {
+      log.debug(this + " unsubscribing " + subscriptionName);
+
       try
       {
          if (closed)
@@ -604,7 +606,18 @@
             throw new InvalidDestinationException("Cannot find durable subscription with name " +
                                                   subscriptionName + " to unsubscribe");
          }
-         
+
+         // Section 6.11. JMS 1.1.
+         // "It is erroneous for a client to delete a durable subscription while it has an active
+         // TopicSubscriber for it or while a message received by it is part of a current
+         // transaction or has not been acknowledged in the session."
+
+         if (subscription.iterator().hasNext())
+         {
+            throw new IllegalStateException("Cannot unsubscribe durable subscription " +
+                                            subscriptionName + " since it has active subscribers");
+         }
+
          boolean removed =
             cm.removeDurableSubscription(connectionEndpoint.getClientID(), subscriptionName);
          

Modified: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java	2006-09-29 21:04:19 UTC (rev 1402)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java	2006-09-29 21:07:09 UTC (rev 1403)
@@ -39,6 +39,7 @@
 import javax.jms.JMSException;
 import javax.jms.InvalidSelectorException;
 import javax.jms.TopicSubscriber;
+import javax.jms.IllegalStateException;
 import java.util.Set;
 
 
@@ -47,6 +48,7 @@
  * MessageConsumerTest.
  *
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
  *
  * $Id$
  */
@@ -429,7 +431,7 @@
       conn.setClientID("ak47");
 
       Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      s.createDurableSubscriber(topic, "uzzi");
+      MessageConsumer cons = s.createDurableSubscriber(topic, "uzzi");
       MessageProducer prod = s.createProducer(topic);
       prod.setDeliveryMode(DeliveryMode.PERSISTENT);
 
@@ -437,6 +439,7 @@
 
       log.debug("unsubscribing ...");
 
+      cons.close();
       s.unsubscribe("uzzi");
 
       log.debug("resubscribing ...");
@@ -468,10 +471,8 @@
       }
    }
 
-   /**
-    * See http://jira.jboss.org/jira/browse/JBMESSAGING-564
-    */
-   public void testUnsubscribe() throws Exception
+   //See JMS 1.1. spec sec 6.11
+   public void testUnsubscribeWithActiveConsumer() throws Exception
    {
       ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
       Topic topic = (Topic)ic.lookup("/topic/Topic");
@@ -483,11 +484,16 @@
 
       TopicSubscriber dursub = s.createDurableSubscriber(topic, "dursub0");
 
-      s.unsubscribe("dursub0");
+      try
+      {
+         s.unsubscribe("dursub0");
+         fail();
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok - it is illegal to ubscribe a subscription if it has active consumers
+      }
 
-      // TODO - what happens with dursub? It is not closed, but its associated subscriber does
-      //        not exist anymore.
-
       dursub.close();
 
       conn.close();

Modified: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java	2006-09-29 21:04:19 UTC (rev 1402)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/MessageConsumerTest.java	2006-09-29 21:07:09 UTC (rev 1403)
@@ -53,7 +53,6 @@
 
 import EDU.oswego.cs.dl.util.concurrent.Latch;
 
-
 /**
  * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -2037,15 +2036,10 @@
       consumerConnection.close();
    }
 
-
-
-
    //
    // NoLocal
    //
-
-
-
+   
    public void testNoLocal() throws Exception
    {
       if (log.isTraceEnabled()) log.trace("testNoLocal");
@@ -2069,7 +2063,7 @@
          assertEquals(Session.AUTO_ACKNOWLEDGE, sess2.getAcknowledgeMode());
          MessageConsumer consumer2 = sess2.createConsumer(topic, null, true);
 
-         // we need different session because we cannot access the same session from two different
+         // we need different session because we cannot access the same session from different
          // threads
          Session sess3 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
          assertEquals(Session.AUTO_ACKNOWLEDGE, sess3.getAcknowledgeMode());
@@ -2400,13 +2394,10 @@
 
       try
       {
-
          conn1 = cf.createConnection();
 
-
          conn1.setClientID(CLIENT_ID1);
 
-
          Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageProducer prod = sess1.createProducer(topic);
          prod.setDeliveryMode(DeliveryMode.PERSISTENT);
@@ -2435,6 +2426,8 @@
          }
 
          assertEquals(NUM_MESSAGES, count);
+         
+         durable.close();
 
          sess1.unsubscribe("mySubscription");
       }
@@ -2631,6 +2624,8 @@
          }
 
          log.debug("unsubscribing mySubscription");
+         
+         durable.close();
          sess5.unsubscribe("mySubscription");
          log.debug("unsubscribing done");
          conn5.close();
@@ -2644,6 +2639,8 @@
 
          TextMessage tm3 = (TextMessage)durable.receive(1000);
          assertNull(tm3);
+         
+         durable.close();
       }
       finally
       {
@@ -2668,7 +2665,7 @@
             conn5.close();
          }
          if (sess6 != null)
-         {
+         {            
             sess6.unsubscribe("mySubscription");
          }
          if (conn6 != null)
@@ -2689,16 +2686,13 @@
 
       try
       {
-
          conn1 = cf.createConnection();
          conn1.setClientID(CLIENT_ID1);
 
-
          Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageProducer prod = sess1.createProducer(topic);
          prod.setDeliveryMode(DeliveryMode.PERSISTENT);
 
-
          log.debug("creating durable subscription");
          MessageConsumer durable = sess1.createDurableSubscriber(topic, "mySubscription");
          log.debug("durable subscription created");
@@ -2758,6 +2752,8 @@
          log.trace("Received " + count  + " messages");
 
          assertEquals(NUM_MESSAGES - NUM_TO_RECEIVE, count);
+         
+         durable2.close();
 
          sess2.unsubscribe("mySubscription");
       }
@@ -2786,13 +2782,10 @@
 
       try
       {
-
          conn1 = cf.createConnection();
 
-
          conn1.setClientID(CLIENT_ID1);
 
-
          Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
          MessageProducer prod = sess1.createProducer(topic);
          prod.setDeliveryMode(DeliveryMode.PERSISTENT);
@@ -2848,6 +2841,8 @@
          }
 
          assertEquals(0, count);
+         
+         durable2.close();
 
          sess2.unsubscribe("mySubscription");
       }

Modified: branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/SecurityTest.java
===================================================================
--- branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2006-09-29 21:04:19 UTC (rev 1402)
+++ branches/Branch_1_0/tests/src/org/jboss/test/messaging/jms/SecurityTest.java	2006-09-29 21:07:09 UTC (rev 1403)
@@ -832,7 +832,8 @@
 
       try
       {
-         sess.createDurableSubscriber(topic, subName);
+         MessageConsumer cons = sess.createDurableSubscriber(topic, subName);
+         cons.close();
          sess.unsubscribe(subName);
          log.trace("Successfully created and unsubscribed subscription");
          return true;




More information about the jboss-cvs-commits mailing list