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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 17 23:19:56 EST 2008


Author: clebert.suconic at jboss.com
Date: 2008-01-17 23:19:56 -0500 (Thu, 17 Jan 2008)
New Revision: 3589

Modified:
   branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/clustering/DistributedTopicTest.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-1216 - testcase

Modified: branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/clustering/DistributedTopicTest.java
===================================================================
--- branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/clustering/DistributedTopicTest.java	2008-01-18 02:06:34 UTC (rev 3588)
+++ branches/Branch_Stable/tests/src/org/jboss/test/messaging/jms/clustering/DistributedTopicTest.java	2008-01-18 04:19:56 UTC (rev 3589)
@@ -26,10 +26,13 @@
 import javax.jms.InvalidDestinationException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
 import javax.jms.MessageProducer;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.jms.Topic;
+import javax.jms.Destination;
+import javax.jms.JMSException;
 
 import org.jboss.test.messaging.tools.ServerManagement;
 import java.util.ArrayList;
@@ -247,55 +250,99 @@
       }
    }
 
+   
    // http://jira.jboss.org/jira/browse/JBMESSAGING-1216
    public void testDestinationTypeOnMessage() throws Exception
    {
+      Connection connection0 = null;
+      Connection connection1 = null;
       
-      Connection conn0 = this.createConnectionOnServer(cf, 0);
-      conn0.setClientID("aCustomer");
-      Connection conn1 = this.createConnectionOnServer(cf, 1);
-      conn1.setClientID("aCustomer");
-      
+      Session session0 = null;
+      Session session1 = null;
+
       try
       {
-         
-         Session session0 = conn0.createSession(true, Session.AUTO_ACKNOWLEDGE);
-         Session session1 = conn1.createSession(true, Session.AUTO_ACKNOWLEDGE);
-   
-         MessageConsumer subscriber0 = session0.createDurableSubscriber(topic[0], "sub");
-         MessageConsumer subscriber1 = session0.createDurableSubscriber(topic[1], "sub2");
-         
-         conn0.start();
-         conn1.start();
-         
+         connection0 = createConnectionOnServer(cf, 0);
+         connection1 = createConnectionOnServer(cf, 1);
+         connection0.setClientID("aCustomer");
+         connection1.setClientID("aCustomer");
+
+
+         session0 = connection0.createSession(true,
+               Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer subscriber0 = session0.createDurableSubscriber(
+               topic[0], "sub");
+         TestListener messageListener0 = new TestListener();
+         subscriber0.setMessageListener(messageListener0);
+
          MessageProducer publisher = session0.createProducer(topic[0]);
-         
-         publisher.send(session0.createTextMessage("Hello!"));
+
+         session1 = connection1.createSession(true,
+               Session.AUTO_ACKNOWLEDGE);
+
+         MessageConsumer subscriber1 = session1.createDurableSubscriber(
+               topic[0], "sub2");
+
+         TestListener messageListener1 = new TestListener();
+         subscriber1.setMessageListener(messageListener1);
+
+
+         connection0.start();
+         connection1.start();
+
+
+         TextMessage message = session0.createTextMessage("Hello!");
+         publisher.send(message);
          session0.commit();
+
+         Message m0 = messageListener0.waitForMessage();
+
+         message = (TextMessage) m0;
+         assertTrue(m0.getJMSDestination() instanceof Topic);
+         assertEquals("Hello!", message.getText());
+
+         Message m1 = messageListener1.waitForMessage();
+         message = (TextMessage) m1;
+         Destination d1 = m1.getJMSDestination();
+         assertTrue(m1.getJMSDestination() instanceof Topic);
+
+         assertEquals("Hello!", message.getText());
          
-         TextMessage msg0 = (TextMessage)subscriber0.receive(1000);
-         TextMessage msg1 = (TextMessage)subscriber1.receive(1000);
+         subscriber0.close();
+         subscriber1.close();
+         session0.unsubscribe("sub");
+         session1.unsubscribe("sub2");
          
-         assertNotNull(msg0);
-         assertNotNull(msg1);
-         
-         log.info("Type of msg0 - " + msg0.getJMSDestination().getClass().getName());
-         log.info("Type of msg1 - " + msg1.getJMSDestination().getClass().getName());
-         
-         assertTrue ("msg0 is type of " + msg0.getJMSDestination() + " instead of Topic" ,msg0.getJMSDestination() instanceof Topic);
-         assertTrue ("msg1 is type of " + msg0.getJMSDestination() + " instead of Topic", msg1.getJMSDestination() instanceof Topic);
-         
-         session0.commit();
-         session1.commit();
-      }
-      finally
+          
+
+      } finally
       {
-         try { conn0.close(); } catch (Throwable ignored) {}
-         try { conn1.close(); } catch (Throwable ignored) {}
+         try
+         {
+            if (connection0 != null)
+            {
+               connection0.close();
+            }
+         } catch (JMSException e)
+         {
+            throw e;
+         }
+
+         try
+         {
+            if (connection1 != null)
+            {
+               connection1.close();
+            }
+         } catch (JMSException e)
+         {
+            throw e;
+         }
+
       }
    }
    
-   
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -1732,5 +1779,63 @@
   
    // Inner classes -------------------------------------------------
    
+   public class TestListener implements MessageListener
+   {
+      // Constants -----------------------------------------------------
 
+      // Static --------------------------------------------------------
+
+      // Attributes ----------------------------------------------------
+
+      private Message message;
+
+      // Constructors --------------------------------------------------
+
+      public TestListener()
+      {
+      }
+
+      // MessageListener implementation --------------------------------
+
+      public synchronized void onMessage(Message message)
+      {
+         this.message = message;
+         notifyAll();
+      }
+
+      // Public --------------------------------------------------------
+
+      public synchronized Message waitForMessage()
+      {
+         if (message != null)
+         {
+            return message;
+         }
+         else
+         {
+   
+            try
+            {
+               wait(5000);
+            }
+            catch(InterruptedException e)
+            {
+               // OK
+            }
+   
+            return message;
+         }
+
+      }
+
+      // Package protected ---------------------------------------------
+
+      // Protected -----------------------------------------------------
+
+      // Private -------------------------------------------------------
+
+      // Inner classes -------------------------------------------------
+
+   }
+
 }




More information about the jboss-cvs-commits mailing list