[jboss-cvs] jboss-jms/tests/src/org/jboss/test/messaging/jms/selector ...

Ovidiu Feodorov ovidiu.feodorov at jboss.com
Mon Jul 24 14:41:44 EDT 2006


  User: ovidiu  
  Date: 06/07/24 14:41:44

  Modified:    tests/src/org/jboss/test/messaging/jms/selector 
                        SelectorTest.java
  Log:
  added failing test for http://jira.jboss.com/jira/browse/JBMESSAGING-275
  
  Revision  Changes    Path
  1.13      +230 -122  jboss-jms/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: SelectorTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-jms/tests/src/org/jboss/test/messaging/jms/selector/SelectorTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -b -r1.12 -r1.13
  --- SelectorTest.java	17 Jul 2006 17:14:52 -0000	1.12
  +++ SelectorTest.java	24 Jul 2006 18:41:44 -0000	1.13
  @@ -34,12 +34,17 @@
   import javax.jms.Message;
   import javax.jms.Topic;
   import javax.naming.InitialContext;
  +import java.util.List;
  +import java.util.ArrayList;
  +import java.util.Iterator;
  +
  +import EDU.oswego.cs.dl.util.concurrent.Latch;
   
   /**
    * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
  - * @version <tt>$Revision: 1.12 $</tt>
  + * @version <tt>$Revision: 1.13 $</tt>
    *
  - * $Id: SelectorTest.java,v 1.12 2006/07/17 17:14:52 timfox Exp $
  + * $Id: SelectorTest.java,v 1.13 2006/07/24 18:41:44 ovidiu Exp $
    */
   public class SelectorTest extends MessagingTestCase
   {
  @@ -397,6 +402,109 @@
               
      }
   
  +   public void testManyConsumersWithDifferentSelectors() throws Exception
  +   {
  +      Connection conn = cf.createConnection();
  +      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  +      MessageProducer p = sess.createProducer(queue);
  +
  +      Session cs = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  +      final MessageConsumer c = cs.createConsumer(queue, "weight = 1");
  +
  +      Session cs2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  +      final MessageConsumer c2 = cs2.createConsumer(queue, "weight = 2");
  +
  +      for(int i = 0; i < 10; i++)
  +      {
  +         Message m = sess.createTextMessage("message" + i);
  +         m.setIntProperty("weight", i % 2 + 1);
  +         p.send(m);
  +      }
  +
  +      conn.start();
  +
  +      final List received = new ArrayList();
  +      final List received2 = new ArrayList();
  +      final Latch latch = new Latch();
  +      final Latch latch2 = new Latch();
  +
  +      new Thread(new Runnable()
  +      {
  +         public void run()
  +         {
  +            try
  +            {
  +               while(true)
  +               {
  +                  Message m = c.receive(1000);
  +                  if (m != null)
  +                  {
  +                     received.add(m);
  +                  }
  +                  else
  +                  {
  +                     latch.release();
  +                     return;
  +                  }
  +               }
  +            }
  +            catch(Exception e)
  +            {
  +               log.error("receive failed", e);
  +            }
  +         }
  +      }, "consumer thread 1").start();
  +
  +      new Thread(new Runnable()
  +      {
  +         public void run()
  +         {
  +            try
  +            {
  +               while(true)
  +               {
  +                  Message m = c2.receive(1000);
  +                  if (m != null)
  +                  {
  +                     received2.add(m);
  +                  }
  +                  else
  +                  {
  +                     latch2.release();
  +                     return;
  +                  }
  +               }
  +            }
  +            catch(Exception e)
  +            {
  +               log.error("receive failed", e);
  +            }
  +         }
  +      }, "consumer thread 2").start();
  +
  +      latch.acquire();
  +      latch2.acquire();
  +
  +      assertEquals(5, received.size());
  +      for(Iterator i = received.iterator(); i.hasNext(); )
  +      {
  +         Message m = (Message)i.next();
  +         int value = m.getIntProperty("weight");
  +         assertEquals(value, 1);
  +      }
  +
  +      assertEquals(5, received2.size());
  +      for(Iterator i = received2.iterator(); i.hasNext(); )
  +      {
  +         Message m = (Message)i.next();
  +         int value = m.getIntProperty("weight");
  +         assertEquals(value, 2);
  +      }
  +
  +
  +      conn.close();
  +   }
  +
      // Package protected ---------------------------------------------
      
      // Protected -----------------------------------------------------
  
  
  



More information about the jboss-cvs-commits mailing list