[jboss-cvs] JBoss Messaging SVN: r3490 - branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 12 17:20:31 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-12-12 17:20:31 -0500 (Wed, 12 Dec 2007)
New Revision: 3490

Modified:
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
Log:
changing the test to use latch instead of wait..notify

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2007-12-12 19:59:59 UTC (rev 3489)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2007-12-12 22:20:31 UTC (rev 3490)
@@ -21,6 +21,8 @@
   */
 package org.jboss.test.messaging.jms;
 
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
 import javax.jms.JMSException;
@@ -332,6 +334,7 @@
    
    public void testSlowConsumers() throws Exception
    {
+      log.info("Running testSlowConsumers");
       ObjectName cf1 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactorySlowConsumers",
       		                                   ServiceContainer.REMOTING_OBJECT_NAME.getCanonicalName(), "/TestSlowConsumersCF", null, true);
 
@@ -347,17 +350,19 @@
          
          Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
          
-         final Object waitLock = new Object();
-         
          final int numMessages = 500;
                
+         final CountDownLatch latch = new CountDownLatch(numMessages);
+
          class FastListener implements MessageListener
          {
          	volatile int processed;
          	
          	public void onMessage(Message msg)
 				{
-         		processed++;
+
+               latch.countDown();
+               processed++;
          		
          		TextMessage tm = (TextMessage)msg;
          		
@@ -369,14 +374,6 @@
                {               	
                }
                
-         		if (processed == numMessages - 1)
-         		{
-         			synchronized (waitLock)
-         			{
-         				log.info("Notifying");
-         				waitLock.notifyAll();
-         			}
-         		}
 				}
          }
          
@@ -387,6 +384,7 @@
 
 				public void onMessage(Message msg)
 				{
+               latch.countDown();
                TextMessage tm = (TextMessage)msg;
          		
                try
@@ -396,26 +394,19 @@
                catch (JMSException e)
                {               	
                }
-					
-               synchronized (waitLock)
+
+               try
                {
-               	//Should really cope with spurious wakeups
-               	while (fast.processed != numMessages - 1)
-               	{
-               		log.info("Waiting");
-               		try
-               		{
-               			waitLock.wait(20000);
-               		}
-               		catch (InterruptedException e)
-               		{               			
-               		}
-               		log.info("Waited");
-               	}
+                  latch.await(30, TimeUnit.SECONDS);
                }
-				}         	
+               catch (InterruptedException ie)
+               {
+                  
+               }
+					
+            }
          }
-         
+                                                                                                               
 
          MessageConsumer cons1 = session1.createConsumer(queue1);
          
@@ -440,18 +431,10 @@
          }
          
          //All the messages bar one should be consumed by the fast listener  - since the slow listener shouldn't buffer any.
-         
-         synchronized (waitLock)
-         {
-         	//Should really cope with spurious wakeups
-         	while (fast.processed != numMessages - 1)
-         	{
-         		log.info("Waiting");
-         		waitLock.wait(20000);
-         		log.info("Waited");
-         	}
-         }
-         
+
+
+         latch.await(30, TimeUnit.SECONDS);
+
          assertTrue(fast.processed == numMessages - 1);
          
       }




More information about the jboss-cvs-commits mailing list