[jboss-cvs] JBoss Messaging SVN: r2608 - in trunk: tests/src/org/jboss/test/messaging/jms/server/destination and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 25 10:25:23 EDT 2007


Author: sergeypk
Date: 2007-04-25 10:25:23 -0400 (Wed, 25 Apr 2007)
New Revision: 2608

Modified:
   trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
   trunk/tests/src/org/jboss/test/messaging/jms/server/destination/QueueManagementTest.java
Log:
JBMESSAGING-926 - Negative message count

Modified: trunk/src/main/org/jboss/messaging/core/ChannelSupport.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/ChannelSupport.java	2007-04-25 13:00:30 UTC (rev 2607)
+++ trunk/src/main/org/jboss/messaging/core/ChannelSupport.java	2007-04-25 14:25:23 UTC (rev 2608)
@@ -330,10 +330,15 @@
     */
    public void removeAllReferences() throws Throwable
    {
-      log.debug(this + " remnoving all references");
+      log.debug(this + " removing all references");
       
       synchronized (refLock)
-      {            
+      {
+         if (deliveringCount.get() > 0)
+         {
+            throw new IllegalStateException("Cannot remove references while deliveries are in progress");
+         }
+         
          //Now we consume the rest of the messages
          //This may take a while if we have a lot of messages including perhaps millions
          //paged in the database - but there's no obvious other way to do it.
@@ -350,9 +355,11 @@
             SimpleDelivery del = new SimpleDelivery(this, ref);
 
             del.acknowledge(null);
-         }         
-         
-         deliveringCount.set(0);
+
+            // Delivery#acknowledge decrements the deliveringCount without incrementing it first (because
+            // deliver has actually never been called), so increment it here to be accurate.  
+            deliveringCount.increment();
+         }
       }
       
       clearAllScheduledDeliveries();

Modified: trunk/tests/src/org/jboss/test/messaging/jms/server/destination/QueueManagementTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/server/destination/QueueManagementTest.java	2007-04-25 13:00:30 UTC (rev 2607)
+++ trunk/tests/src/org/jboss/test/messaging/jms/server/destination/QueueManagementTest.java	2007-04-25 14:25:23 UTC (rev 2608)
@@ -34,6 +34,7 @@
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.management.ObjectName;
+import javax.management.RuntimeMBeanException;
 import javax.naming.InitialContext;
 
 import org.jboss.jms.message.JBossMessage;
@@ -279,17 +280,20 @@
          Message message = cons.receive(500L);
          assertNotNull(message);
          assertEquals("Message #1", ((TextMessage) message).getText());
+
+         try
+         {
+            ServerManagement.invoke(destObjectName, "removeAllMessages", new Object[0], new String[0]);
+            fail("Should have thrown an exception");
+         }
+         catch (RuntimeMBeanException e)
+         {
+            if (!(e.getCause() instanceof IllegalStateException))
+            {
+               fail("Should have thrown a RuntimeMBeanException wrapping IllegalStateException");
+            }
+         }
          
-         ServerManagement.invoke(destObjectName, "removeAllMessages", new Object[0], new String[0]);
-         
-         // Assert that all messages were in fact removed.
-         message = cons.receive(500L);
-         assertNull(message);
-
-         // Check that the message count is 0.
-         Integer count = (Integer)ServerManagement.getAttribute(destObjectName, "MessageCount");
-         assertEquals(0, count.intValue());
-
          conn.close();
       }
       finally




More information about the jboss-cvs-commits mailing list