Package org.jboss.messaging.core.local

Examples of org.jboss.messaging.core.local.RoundRobinPointToPointRouter


   // Public --------------------------------------------------------
  
   public void testAllAccepting()
   {
      Router router = new RoundRobinPointToPointRouter();
     
      final int numReceivers = 10;
     
      SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
     
      for (int i = 0; i < numReceivers; i++)
      {
         receivers[i] = new SimpleReceiver();
        
         router.add(receivers[i]);
      }
     
      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
           
      Delivery del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 2);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 3);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 4);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 5);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 6);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 7);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 8);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 9);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 2);
      resetReceivers(receivers);
     
   }
View Full Code Here


     
   }
  
   public void testSomeClosed()
   {
      Router router = new RoundRobinPointToPointRouter();
     
      final int numReceivers = 10;
     
      SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
     
      for (int i = 0; i < numReceivers; i++)
      {
         receivers[i] = new SimpleReceiver();
        
         router.add(receivers[i]);
      }
     
      receivers[2].closed = true;
     
      receivers[5].closed = true;
      receivers[6].closed = true;
     
      receivers[9].closed = true;
     
      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
     
      Delivery del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 3);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 4);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 7);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 8);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 3);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 4);
      resetReceivers(receivers);
     
     
View Full Code Here

     
   }
  
   public void testAllClosed()
   {
      Router router = new RoundRobinPointToPointRouter();
     
      final int numReceivers = 10;
     
      SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
     
      for (int i = 0; i < numReceivers; i++)
      {
         receivers[i] = new SimpleReceiver();
        
         receivers[i].closed = true;
        
         router.add(receivers[i]);
      }
     
     
      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
     
      Delivery del = router.handle(null, ref, null);
      assertNull(del);

      del = router.handle(null, ref, null);
      assertNull(del);
     
      del = router.handle(null, ref, null);
      assertNull(del);

     
     
   }
View Full Code Here

     
   }
  
   public void testSomeNoSelectorMatch()
   {
      Router router = new RoundRobinPointToPointRouter();
     
      final int numReceivers = 10;
     
      SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
     
      for (int i = 0; i < numReceivers; i++)
      {
         receivers[i] = new SimpleReceiver();
        
         router.add(receivers[i]);
      }
     
      receivers[2].selectorMatches = false;
     
      receivers[5].selectorMatches = false;
      receivers[6].selectorMatches = false;
     
      receivers[9].selectorMatches = false;
     
      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
     
      Delivery del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 3);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 4);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 7);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 8);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 0);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 1);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 3);
      resetReceivers(receivers);
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      checkReceiverGotRef(receivers, 4);
      resetReceivers(receivers);
     
   }
View Full Code Here

     
   }
  
   public void testAllNoSelectorMatch()
   {
      Router router = new RoundRobinPointToPointRouter();
     
      final int numReceivers = 10;
     
      SimpleReceiver[] receivers = new SimpleReceiver[numReceivers];
     
      for (int i = 0; i < numReceivers; i++)
      {
         receivers[i] = new SimpleReceiver();
        
         receivers[i].selectorMatches = false;
        
         router.add(receivers[i]);
      }
     
     
      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
     
      Delivery del = router.handle(null, ref, null);
      assertNotNull(del);
      assertFalse(del.isSelectorAccepted());
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      assertFalse(del.isSelectorAccepted());
     
      del = router.handle(null, ref, null);
      assertNotNull(del);
      assertFalse(del.isSelectorAccepted());
          
   }
View Full Code Here

          
   }
  
   public void testNoReceivers()
   {
      Router router = new RoundRobinPointToPointRouter();

      Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
     
      MessageReference ref = ms.reference(msg);
     
      Delivery del = router.handle(null, ref, null);
      assertNull(del);
     
      del = router.handle(null, ref, null);
      assertNull(del);
     
      del = router.handle(null, ref, null);
      assertNull(del);   
   }
View Full Code Here

   /**
    * http://jira.jboss.org/jira/browse/JBMESSAGING-491
    */
   public void testDeadlock() throws Exception
   {
      final Router router = new RoundRobinPointToPointRouter();

      LockingReceiver receiver = new LockingReceiver();
      router.add(receiver);

      final Thread t = new Thread(new Runnable()
      {
         public void run()
         {
            // sends the message to the router on a separate thread
           
            Message msg = CoreMessageFactory.createCoreMessage(123, true, null);
           
            MessageReference ref = ms.reference(msg);
           
            router.handle(null, ref, null);
         }
      }, "Message sending thread");

      // start the sending tread, which will immediately grab the router's "receivers" lock, and it
      // will sleep for 3 seconds before attempting to grab LockingReceiver's lock.
      t.start();


      // in the mean time, the main thread immediately grabs receiver's lock ...

      synchronized(receiver.getLock())
      {
         // ... sleeps for 500 ms to allow sender thread time to grab router's "receivers" lock
         Thread.sleep(500);

         // ... and try to remove the receiver form router
         router.remove(receiver);
      }

      // normally, receiver removal should be immediate, as the router releases receiver's lock
      // immediately, so test should complete. Pre-JBMESSAGING-491, the test deadlocks.
   }
View Full Code Here

TOP

Related Classes of org.jboss.messaging.core.local.RoundRobinPointToPointRouter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.