Package org.jboss.messaging.core.plugin.contract

Examples of org.jboss.messaging.core.plugin.contract.ClusteredPostOffice


        
   }
  
   public final void testClusteredBindUnbind() throws Throwable
   {
      ClusteredPostOffice office1 = null;
      ClusteredPostOffice office2 = null;
      ClusteredPostOffice office3 = null;
     
      try
      {        
         // Start one office
        
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
        
         log.info("Created office1");
        
         // Add a couple of bindings
        
         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "sub1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         Binding binding1 =
            office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);
        
         log.info("Added binding1");
        
         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office1, 1, "sub2", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         Binding binding2 =
            office1.bindClusteredQueue(new SimpleCondition("topic1"), queue2);
        
         log.info("Added binding2");
        
         // Start another office - make sure it picks up the bindings from the first node
        
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
        
         log.info("Created office 2");
        
         Collection bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         Iterator iter = bindings.iterator();
         assertEquivalent(binding1, (Binding)iter.next());
         assertEquivalent(binding2, (Binding)iter.next());        
        
         // Add another binding on node 2
        
         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office2, 2, "sub3", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         Binding binding3 =
            office2.bindClusteredQueue(new SimpleCondition("topic1"), queue3);
 
         // Make sure both nodes pick it up
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(3, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding1, (Binding)iter.next());
         assertEquivalent(binding2, (Binding)iter.next());
         assertEquivalent(binding3, (Binding)iter.next());

         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(3, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding1, (Binding)iter.next());
         assertEquivalent(binding2, (Binding)iter.next());
         assertEquivalent(binding3, (Binding)iter.next());

         // Add another binding on node 1
        
         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office2, 2, "sub4", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         Binding binding4 =
            office2.bindClusteredQueue(new SimpleCondition("topic1"), queue4);
        
         // Make sure both nodes pick it up
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(4, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding1, (Binding)iter.next());
         assertEquivalent(binding2, (Binding)iter.next());
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(4, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding1, (Binding)iter.next());
         assertEquivalent(binding2, (Binding)iter.next());
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
        
         // Unbind binding 1 and binding 2
         office1.unbindClusteredQueue("sub1");
         office1.unbindClusteredQueue("sub2");
        
         // Make sure bindings are not longer available on either node
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
  
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());

         // Add a third office
                 
         office3 = createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);
        
         // Maks sure it picks up the bindings
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
        
         // Add another binding on node 3
                 
         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office3, 3, "sub5", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         Binding binding5 =
            office3.bindClusteredQueue(new SimpleCondition("topic1"), queue5);
        
         // Make sure all nodes pick it up
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(3, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(3, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(3, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
        
         // Add a durable and a non durable binding on node 1
        
         LocalClusteredQueue queue6 =
            new LocalClusteredQueue(office1, 1, "sub6", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
        
         Binding binding6 =
            office1.bindClusteredQueue(new SimpleCondition("topic1"), queue6);
        
         LocalClusteredQueue queue7 =
            new LocalClusteredQueue(office1, 1, "sub7", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         Binding binding7 =
            office1.bindClusteredQueue(new SimpleCondition("topic1"), queue7);
        
         // Make sure all nodes pick them up
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(5, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
         assertEquivalent(binding7, (Binding)iter.next());
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(5, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
         assertEquivalent(binding7, (Binding)iter.next());
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(5, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
         assertEquivalent(binding7, (Binding)iter.next());
              
         // Stop office 1
         office1.stop();
 
         // Need to sleep since it may take some time for the view changed request to reach the
         // members which causes the bindings to be removed.
        
         Thread.sleep(1000);
        
         // All it's non durable bindings should be removed from the other nodes.
         // Durable bindings should remain.
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(4, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(4, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding3, (Binding)iter.next());
         assertEquivalent(binding4, (Binding)iter.next());
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         // Stop office 2
         office2.stop();
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         // Restart office 1 and office 2
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
        
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(2, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding5, (Binding)iter.next());
         assertEquivalent(binding6, (Binding)iter.next());
        
         // Stop all offices
        
         office1.stop();
         office2.stop();
         office3.stop();
        
         // Start them all
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
         office3 = createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);
        
         // Only the durable queue should survive
        
         bindings = office1.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(1, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding6, (Binding)iter.next());
        
         bindings = office2.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(1, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding6, (Binding)iter.next());
        
         bindings = office3.listAllBindingsForCondition(new SimpleCondition("topic1"));
         assertNotNull(bindings);
         assertEquals(1, bindings.size());
        
         iter = bindings.iterator();
         assertEquivalent(binding6, (Binding)iter.next());
                 
      }
      finally
      {
         if (office1 != null)
         {
            try
            {
               office1.unbindClusteredQueue("sub6");
            }
            catch (Exception ignore)
            {
              
            }
            office1.stop();
         }
        
         if (office2 != null)
         {
            office2.stop();
         }
        
         if (office3 != null)
         {
            office3.stop();
         }
        
         if (checkNoBindingData())
         {
            fail("data still in database");
View Full Code Here


    * We should allow the clustered bind of queues with the same queue name on different nodes of the
    * cluster
    */
   public void testClusteredNameUniqueness() throws Throwable
   {
      ClusteredPostOffice office1 = null;
     
      ClusteredPostOffice office2 = null;
         
      try
      {  
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
        
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
        
         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         try
         {
            office1.bindClusteredQueue(new SimpleCondition("queue1"), queue3);
            fail();
         }
         catch (Exception e)
         {
            //Ok
         }

         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         try
         {
            office2.bindClusteredQueue(new SimpleCondition("queue1"), queue4);
            fail();
         }
         catch (Exception e)
         {
            //Ok
         }
        
         office2.unbindClusteredQueue("queue1");

         office1.unbindClusteredQueue("queue1");

         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);
        
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue5);
        
         PagingFilteredQueue queue6 =
            new PagingFilteredQueue("queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null);
         try
         {
            office1.bindQueue(new SimpleCondition("queue1"), queue6);
            fail();
         }
         catch (Exception e)
         {
            //ok
         }
         
         office1.unbindClusteredQueue("queue1");
        
         // It should be possible to bind queues locally into a clustered post office
         LocalClusteredQueue queue7 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         office1.bindQueue(new SimpleCondition("queue1"), queue7);
        
         LocalClusteredQueue queue8 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         office2.bindQueue(new SimpleCondition("queue1"), queue8);
        
         LocalClusteredQueue queue9 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, false, -1, null, tr);

         try
         {
            office1.bindQueue(new SimpleCondition("queue1"), queue9);
            fail();
         }
         catch (Exception e)
         {
            //Ok
         }

      }
      finally
      {
         if (office1 != null)
         {           
            office1.stop();
         }
        
         if (office2 != null)
         {
            office2.stop();
         }
      }
   }
View Full Code Here

   // Protected ------------------------------------------------------------------------------------
  
   protected void clusteredRouteWithFilter(boolean persistentMessage, boolean recoverable)
      throws Throwable
   {
      ClusteredPostOffice office1 = null;
     
      ClusteredPostOffice office2 = null;
         
      try
      {  
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
        
         SimpleFilter filter1 = new SimpleFilter(2);
         SimpleFilter filter2 = new SimpleFilter(3);
     
         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, filter1, tr);

         office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);
        
         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue2", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, filter2, tr);

         office2.bindClusteredQueue(new SimpleCondition("topic1"), queue2);
        
         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office2, 2, "queue3", channelIDManager.getID(), ms, pm, true,
                                    recoverable, -1, null, tr);

         office2.bindClusteredQueue(new SimpleCondition("topic1"), queue3);
        
         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);

         queue1.add(receiver1);

         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);

         queue2.add(receiver2);

         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);

         queue3.add(receiver3);
        
         Message msg1 = CoreMessageFactory.createCoreMessage(1);     
         MessageReference ref1 = ms.reference(msg1)
         boolean routed = office1.route(ref1, new SimpleCondition("topic1"), null);  
         assertTrue(routed);
        
        
         Message msg2 = CoreMessageFactory.createCoreMessage(2);     
         MessageReference ref2 = ms.reference(msg2);        
         routed = office1.route(ref2, new SimpleCondition("topic1"), null);     
         assertTrue(routed);
        
         Message msg3 = CoreMessageFactory.createCoreMessage(3);     
         MessageReference ref3 = ms.reference(msg3);        
         routed = office1.route(ref3, new SimpleCondition("topic1"), null);     
         assertTrue(routed);
        
         Thread.sleep(2000);
        
         List msgs = receiver1.getMessages();
         assertNotNull(msgs);
         assertEquals(1, msgs.size());
         Message msgRec = (Message)msgs.get(0);
         assertTrue(msg2 == msgRec);
         receiver1.acknowledge(msgRec, null);
         msgs = queue1.browse();
         assertNotNull(msgs);
         assertTrue(msgs.isEmpty())
        
         msgs = receiver2.getMessages();
         assertNotNull(msgs);
         assertEquals(1, msgs.size());
         msgRec = (Message)msgs.get(0);
         assertTrue(msg3 == msgRec);
         receiver2.acknowledge(msgRec, null);
         msgs = queue2.browse();
         assertNotNull(msgs);
         assertTrue(msgs.isEmpty())
        
         msgs = receiver3.getMessages();
         assertNotNull(msgs);
         assertEquals(3, msgs.size());
         Message msgRec1 = (Message)msgs.get(0);
         assertTrue(msg1 == msgRec1);
         Message msgRec2 = (Message)msgs.get(1);
         assertTrue(msg2 == msgRec2);
         Message msgRec3 = (Message)msgs.get(2);
         assertTrue(msg3 == msgRec3);
         
         receiver3.acknowledge(msgRec1, null);
         receiver3.acknowledge(msgRec2, null);
         receiver3.acknowledge(msgRec3, null);
         msgs = queue3.browse();
         assertNotNull(msgs);
         assertTrue(msgs.isEmpty());
                 
         if (checkNoMessageData())
         {
            fail("Message data still in database");
         }
      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }
        
         if (office2 != null)
         {
            office2.stop();
         }
        
      }
   }
View Full Code Here

      }
   }
  
   protected void clusteredRoute(boolean persistentMessage) throws Throwable
   {
      ClusteredPostOffice office1 = null;
     
      ClusteredPostOffice office2 = null;
         
      try
      {  
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
     
         //Two topics with a mixture of durable and non durable subscriptions
        
         LocalClusteredQueue[] queues = new LocalClusteredQueue[16];
         Binding[] bindings = new Binding[16];
        
         queues[0] = new LocalClusteredQueue(office1, 1, "sub1", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[0] = office1.bindClusteredQueue(new SimpleCondition("topic1"), queues[0]);
        
         queues[1] = new LocalClusteredQueue(office1, 1, "sub2", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[1] = office1.bindClusteredQueue(new SimpleCondition("topic1"), queues[1]);
        
         queues[2] = new LocalClusteredQueue(office2, 2, "sub3", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[2] = office2.bindClusteredQueue(new SimpleCondition("topic1"), queues[2]);
        
         queues[3] = new LocalClusteredQueue(office2, 2, "sub4", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[3] = office2.bindClusteredQueue(new SimpleCondition("topic1"), queues[3]);
        
         queues[4] = new LocalClusteredQueue(office2, 2, "sub5", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[4] = office2.bindClusteredQueue(new SimpleCondition("topic1"), queues[4]);
        
         queues[5] = new LocalClusteredQueue(office1, 1, "sub6", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[5] = office1.bindClusteredQueue(new SimpleCondition("topic1"), queues[5]);
        
         queues[6] = new LocalClusteredQueue(office1, 1, "sub7", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[6] = office1.bindClusteredQueue(new SimpleCondition("topic1"), queues[6]);
        
         queues[7] = new LocalClusteredQueue(office1, 1, "sub8", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[7] = office1.bindClusteredQueue(new SimpleCondition("topic1"), queues[7]);
        
         queues[8] = new LocalClusteredQueue(office1, 1, "sub9", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[8] = office1.bindClusteredQueue(new SimpleCondition("topic2"), queues[8]);
        
         queues[9] = new LocalClusteredQueue(office1, 1, "sub10", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[9] = office1.bindClusteredQueue(new SimpleCondition("topic2"), queues[9]);
        
         queues[10] = new LocalClusteredQueue(office2, 2, "sub11", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[10] = office2.bindClusteredQueue(new SimpleCondition("topic2"), queues[10]);
        
         queues[11] = new LocalClusteredQueue(office2, 2, "sub12", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[11] = office2.bindClusteredQueue(new SimpleCondition("topic2"), queues[11]);
        
         queues[12] = new LocalClusteredQueue(office2, 2, "sub13", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[12] = office2.bindClusteredQueue(new SimpleCondition("topic2"), queues[12]);
        
         queues[13] = new LocalClusteredQueue(office1, 1, "sub14", channelIDManager.getID(), ms, pm, true, false, -1, null, tr);
         bindings[13] = office1.bindClusteredQueue(new SimpleCondition("topic2"), queues[13]);
        
         queues[14] = new LocalClusteredQueue(office1, 1, "sub15", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[14] = office1.bindClusteredQueue(new SimpleCondition("topic2"), queues[14]);
        
         queues[15] = new LocalClusteredQueue(office1, 1, "sub16", channelIDManager.getID(), ms, pm, true, true, -1, null, tr);
         bindings[15] = office1.bindClusteredQueue(new SimpleCondition("topic2"), queues[15]);
      
         SimpleReceiver[] receivers = new SimpleReceiver[16];
        
         for (int i = 0; i < 16; i++)
         {
            receivers[i] = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
            queues[i].add(receivers[i]);
         }
        
         Message msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         MessageReference ref = ms.reference(msg);        

         boolean routed = office1.route(ref, new SimpleCondition("topic1"), null);        
         assertTrue(routed);
        
         //Messages are sent asych so may take some finite time to arrive
         Thread.sleep(1000);
        
         for (int i = 0; i < 8; i++)
         {        
            List msgs = receivers[i].getMessages();
            assertNotNull(msgs);
            assertEquals(1, msgs.size());
            Message msgRec = (Message)msgs.get(0);
            assertEquals(msg.getMessageID(), msgRec.getMessageID());
            receivers[i].acknowledge(msgRec, null);
            msgs = queues[i].browse();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
            receivers[i].clear();
         }
        
         for (int i = 8; i < 16; i++)
         {
            List msgs = receivers[i].getMessages();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
            msgs = queues[i].browse();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
         }
                 
         //Now route to topic2
        
         msg = CoreMessageFactory.createCoreMessage(2, persistentMessage, null);;     
         ref = ms.reference(msg);        

         routed = office1.route(ref, new SimpleCondition("topic2"), null);        
         assertTrue(routed);
         //Messages are sent asych so may take some finite time to arrive
         Thread.sleep(1000);
        
         for (int i = 0; i < 8; i++)
         {
            List msgs = receivers[i].getMessages();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
            msgs = queues[i].browse();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
         }
        
         for (int i = 8; i < 16; i++)
         {        
            List msgs = receivers[i].getMessages();
            assertNotNull(msgs);
            assertEquals(1, msgs.size());
            Message msgRec = (Message)msgs.get(0);
            assertEquals(msg.getMessageID(), msgRec.getMessageID());
            receivers[i].acknowledge(msgRec, null);
            msgs = queues[i].browse();
            assertNotNull(msgs);
            assertTrue(msgs.isEmpty());
            receivers[i].clear();
         }
        
         if (checkNoMessageData())
         {
            fail("Message data still in database");
         }

      }
      finally
      {
         if (office1 != null)
         {
            try
            {             
               office1.unbindClusteredQueue("sub7");
               office1.unbindClusteredQueue("sub8");              
               office1.unbindClusteredQueue("sub15");
               office1.unbindClusteredQueue("sub16");
            }
            catch (Exception ignore)
            {
               ignore.printStackTrace();
            }
           
            office1.stop();
         }
        
         if (office2 != null)
         {
            try
            {
               office2.unbindClusteredQueue("sub5");
               office2.unbindClusteredQueue("sub13");
            }
            catch (Exception ignore)
            {    
               ignore.printStackTrace();
            }
            office2.stop();
         }
       
      }
   }
View Full Code Here

      }
   }
  
   protected void routeSharedQueue(boolean persistentMessage, boolean recoverable) throws Throwable
   {
      ClusteredPostOffice office1 = null;
     
      ClusteredPostOffice office2 = null;
     
      ClusteredPostOffice office3 = null;
     
      ClusteredPostOffice office4 = null;
     
      ClusteredPostOffice office5 = null;
     
      ClusteredPostOffice office6 = null;
       
      try
      {  
         office1 = createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
         office2 = createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
         office3 = createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);
         office4 = createClusteredPostOffice(4, "testgroup", sc, ms, pm, tr);
         office5 = createClusteredPostOffice(5, "testgroup", sc, ms, pm, tr);
         office6 = createClusteredPostOffice(6, "testgroup", sc, ms, pm, tr);
   
         // We deploy the queue on nodes 1, 2, 3, 4 and 5
         // We don't deploy on node 6
        
         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm, true,
                                    recoverable, -1, null, tr);

         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue1.add(receiver1);
        
         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm, true,
                                    recoverable, -1, null, tr);

         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue2.add(receiver2);
        
         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm, true,
                                    recoverable, -1, null, tr);

         office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);

         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue3.add(receiver3);
        
         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);

         office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);

         SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue4.add(receiver4);
        
         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm, true,
                                    recoverable, -1, null, tr);

         office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);
         SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue5.add(receiver5);
       
         // We are using a AlwaysLocalRoutingPolicy so only the local queue should ever get the
         // message if the filter matches
                         
         Message msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         MessageReference ref = ms.reference(msg);        
         boolean routed = office1.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
         checkContainsAndAcknowledge(msg, receiver1, queue1);
         this.checkEmpty(receiver2);
         this.checkEmpty(receiver3);
         this.checkEmpty(receiver4);
         this.checkEmpty(receiver5);
        
         msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         ref = ms.reference(msg);        
         routed = office2.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
         this.checkEmpty(receiver1);
         checkContainsAndAcknowledge(msg, receiver2, queue2);
         this.checkEmpty(receiver3);
         this.checkEmpty(receiver4);
         this.checkEmpty(receiver5);
        
         msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         ref = ms.reference(msg);        
         routed = office3.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
         this.checkEmpty(receiver1);
         this.checkEmpty(receiver2);
         checkContainsAndAcknowledge(msg, receiver3, queue3);
         this.checkEmpty(receiver4);
         this.checkEmpty(receiver5);
        
         msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         ref = ms.reference(msg);        
         routed = office4.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
         this.checkEmpty(receiver1);
         this.checkEmpty(receiver2);
         this.checkEmpty(receiver3);
         checkContainsAndAcknowledge(msg, receiver4, queue3);
         this.checkEmpty(receiver5);
        
         msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         ref = ms.reference(msg);        
         routed = office5.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
         this.checkEmpty(receiver1);
         this.checkEmpty(receiver2);        
         this.checkEmpty(receiver3);
         this.checkEmpty(receiver4);
         checkContainsAndAcknowledge(msg, receiver5, queue5);
        
         msg = CoreMessageFactory.createCoreMessage(1, persistentMessage, null);     
         ref = ms.reference(msg);        
         routed = office6.route(ref, new SimpleCondition("queue1"), null);        
         assertTrue(routed);
        
         //The actual queue that receives the mesage is determined by the routing policy
         //The default uses round robin for the nodes (this is tested more thoroughly in
         //its own test)
        
         Thread.sleep(1000);
        
         checkContainsAndAcknowledge(msg, receiver1, queue1);
         this.checkEmpty(receiver1);
         this.checkEmpty(receiver2);        
         this.checkEmpty(receiver3);
         this.checkEmpty(receiver4);
         this.checkEmpty(receiver5);
                
      }
      finally
      {
         if (office1 != null)
         {           
            office1.stop();
         }
        
         if (office2 != null)
         {
            office2.stop();
         }
        
         if (office3 != null)
         {           
            office3.stop();
         }
        
         if (office4 != null)
         {
            office4.stop();
         }
        
         if (office5 != null)
         {           
            office5.stop();
         }
        
         if (office6 != null)
         {           
            office6.stop();
         }
        
         if (checkNoMessageData())
         {
            fail("Message data still in database");
View Full Code Here

TOP

Related Classes of org.jboss.messaging.core.plugin.contract.ClusteredPostOffice

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.