[jboss-cvs] JBoss Messaging SVN: r3491 - 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:46:19 EST 2007


Author: clebert.suconic at jboss.com
Date: 2007-12-12 17:46:18 -0500 (Wed, 12 Dec 2007)
New Revision: 3491

Modified:
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java
Log:
Revert to previous test

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 22:20:31 UTC (rev 3490)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/ConnectionFactoryTest.java	2007-12-12 22:46:18 UTC (rev 3491)
@@ -21,8 +21,6 @@
   */
 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;
@@ -56,7 +54,7 @@
    // Constants -----------------------------------------------------
 
    // Static --------------------------------------------------------
-   
+
    // Attributes ----------------------------------------------------
 
    // Constructors --------------------------------------------------
@@ -79,7 +77,7 @@
       QueueConnection qc = qcf.createQueueConnection();
       qc.close();
    }
-   
+
    /**
     * Test that ConnectionFactory can be cast to TopicConnectionFactory and TopicConnection can be
     * created.
@@ -131,9 +129,9 @@
       {
          // OK
       }
-      
+
       //Now try and deploy another one with the same client id
-      
+
       mbeanConfig =
          "<mbean code=\"org.jboss.jms.server.connectionfactory.ConnectionFactory\"\n" +
          "       name=\"jboss.messaging.connectionfactory:service=TestConnectionFactory2\"\n" +
@@ -149,16 +147,16 @@
          "          </bindings>\n" +
          "       </attribute>\n" +
          " </mbean>";
-      
+
       ObjectName on2 = ServerManagement.deploy(mbeanConfig);
-      ServerManagement.invoke(on2, "create", new Object[0], new String[0]);      
+      ServerManagement.invoke(on2, "create", new Object[0], new String[0]);
       ServerManagement.invoke(on2, "start", new Object[0], new String[0]);
-      
-      
+
+
       ServerManagement.invoke(on2, "stop", new Object[0], new String[0]);
       ServerManagement.invoke(on2, "destroy", new Object[0], new String[0]);
       ServerManagement.undeploy(on2);
-      
+
       cf = (ConnectionFactory)ic.lookup("/TestConnectionFactory");
       Connection c2 = null;
       try
@@ -169,53 +167,53 @@
       {
          //Ok
       }
-      
+
       if (c2 != null) c2.close();
-      
+
       c.close();
 
       ServerManagement.invoke(on, "stop", new Object[0], new String[0]);
       ServerManagement.invoke(on, "destroy", new Object[0], new String[0]);
       ServerManagement.undeploy(on);
    }
-         
+
    public void testAdministrativelyConfiguredConnectors() throws Exception
    {
       //Deploy a few connectors
       String name1 = "jboss.messaging:service=Connector1,transport=bisocket";
-      
+
       String name2 = "jboss.messaging:service=Connector2,transport=bisocket";
-      
+
       String name3 = "jboss.messaging:service=Connector3,transport=bisocket";
-      
+
       ObjectName c1 = deployConnector(1234, name1);
       ObjectName c2 = deployConnector(1235, name2);
       ObjectName c3 = deployConnector(1236, name3);
-      
+
       ObjectName cf1 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactory1", name1, "/TestConnectionFactory1", "clientid1", false);
       ObjectName cf2 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactory2", name2, "/TestConnectionFactory2", "clientid2", false);
       ObjectName cf3 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactory3", name3, "/TestConnectionFactory3", "clientid3", false);
       //Last one shares the same connector
       ObjectName cf4 = deployConnectionFactory("jboss.messaging.destination:service=TestConnectionFactory4", name3, "/TestConnectionFactory4", "clientid4", false);
-      
-      
-      JBossConnectionFactory f1 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory1");            
-      ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)f1.getDelegate();      
-      
+
+
+      JBossConnectionFactory f1 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory1");
+      ClientConnectionFactoryDelegate del1 = (ClientConnectionFactoryDelegate)f1.getDelegate();
+
       assertTrue(del1.getServerLocatorURI().startsWith("bisocket://localhost:1234"));
-      
-      JBossConnectionFactory f2 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory2");            
-      ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)f2.getDelegate();      
+
+      JBossConnectionFactory f2 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory2");
+      ClientConnectionFactoryDelegate del2 = (ClientConnectionFactoryDelegate)f2.getDelegate();
       assertTrue(del2.getServerLocatorURI().startsWith("bisocket://localhost:1235"));
-      
-      JBossConnectionFactory f3 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory3");            
-      ClientConnectionFactoryDelegate del3 = (ClientConnectionFactoryDelegate)f3.getDelegate();      
+
+      JBossConnectionFactory f3 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory3");
+      ClientConnectionFactoryDelegate del3 = (ClientConnectionFactoryDelegate)f3.getDelegate();
       assertTrue(del3.getServerLocatorURI().startsWith("bisocket://localhost:1236"));
-      
-      JBossConnectionFactory f4 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory4");            
-      ClientConnectionFactoryDelegate del4 = (ClientConnectionFactoryDelegate)f4.getDelegate();      
+
+      JBossConnectionFactory f4 = (JBossConnectionFactory)ic.lookup("/TestConnectionFactory4");
+      ClientConnectionFactoryDelegate del4 = (ClientConnectionFactoryDelegate)f4.getDelegate();
       assertTrue(del4.getServerLocatorURI().startsWith("bisocket://localhost:1236"));
-      
+
       Connection con1 = f1.createConnection();
       Connection con2 = f2.createConnection();
       Connection con3 = f3.createConnection();
@@ -224,22 +222,22 @@
       con2.close();
       con3.close();
       con4.close();
-      
+
       stopService(cf1);
       stopService(cf2);
       stopService(cf3);
-      
+
       //Check f4 is still ok
       Connection conn5 = f4.createConnection();
       conn5.close();
-      
+
       stopService(cf4);
-      
+
       stopService(c1);
       stopService(c2);
       stopService(c3);
    }
-   
+
    public void testNoClientIDConfigured_1() throws Exception
    {
       // the ConnectionFactories that ship with Messaging do not have their clientID
@@ -331,10 +329,9 @@
 
    }
 
-   
+
    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);
 
@@ -343,98 +340,118 @@
       try
       {
          ConnectionFactory cf = (ConnectionFactory) ic.lookup("/TestSlowConsumersCF");
-         
+
          conn = cf.createConnection();
 
          Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
+
          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;
-         		
+
          		try
          		{
          			log.info("Fast listener got message " + tm.getText());
          		}
                catch (JMSException e)
-               {               	
+               {
                }
-               
+
+         		if (processed == numMessages - 1)
+         		{
+         			synchronized (waitLock)
+         			{
+         				log.info("Notifying");
+         				waitLock.notifyAll();
+         			}
+         		}
 				}
          }
-         
+
          final FastListener fast = new FastListener();
-         
+
          class SlowListener implements MessageListener
          {
 
 				public void onMessage(Message msg)
 				{
-               latch.countDown();
                TextMessage tm = (TextMessage)msg;
-         		
+
                try
                {
                	log.info("Slow listener got message " + tm.getText());
                }
                catch (JMSException e)
-               {               	
+               {
                }
 
-               try
+               synchronized (waitLock)
                {
-                  latch.await(30, TimeUnit.SECONDS);
+               	//Should really cope with spurious wakeups
+               	while (fast.processed != numMessages - 1)
+               	{
+               		log.info("Waiting");
+               		try
+               		{
+               			waitLock.wait(20000);
+               		}
+               		catch (InterruptedException e)
+               		{
+               		}
+               		log.info("Waited");
+               	}
                }
-               catch (InterruptedException ie)
-               {
-                  
-               }
-					
-            }
+				}
          }
-                                                                                                               
 
+
          MessageConsumer cons1 = session1.createConsumer(queue1);
-         
+
          cons1.setMessageListener(new SlowListener());
-         
+
          MessageConsumer cons2 = session2.createConsumer(queue1);
-         
+
          cons2.setMessageListener(fast);
-         
-   
+
+
          Session sessSend = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         
+
          MessageProducer prod = sessSend.createProducer(queue1);
-         
+
          conn.start();
-         
+
          for (int i = 0; i < numMessages; i++)
          {
          	TextMessage tm = sessSend.createTextMessage("message" + i);
-         	
+
          	prod.send(tm);
          }
-         
+
          //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