Package org.jboss.messaging.core.plugin.postoffice.cluster

Examples of org.jboss.messaging.core.plugin.postoffice.cluster.DefaultClusteredPostOffice


         {
            log.debug(this + " uses XMLJChannelFactory");
            jChannelFactory = new XMLJChannelFactory(syncChannelConfig, asyncChannelConfig);
         }

         postOffice =  new DefaultClusteredPostOffice(ds, tm, sqlProperties,
                                                      createTablesOnStartup,
                                                      nodeId, officeName, ms,
                                                      pm, tr, ff, cf,
                                                      groupName,
                                                      jChannelFactory,
View Full Code Here


      super.tearDown();
   }

   public void testCrashBeforePersist() throws Exception
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;
      DefaultClusteredPostOffice office3 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);
         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);

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

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue3", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
            office3.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);

         //This will make it fail after casting but before persisting the message in the db
         office1.setFail(true, false, false);

         Transaction tx = tr.createTransaction();

         final int NUM_MESSAGES = 10;

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            Message msg = CoreMessageFactory.createCoreMessage(i, true, null);

            MessageReference ref = ms.reference(msg);

            office1.route(ref, new SimpleCondition("topic1"), tx);
         }

         Thread.sleep(1000);

         List msgs = receiver1.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver2.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver3.getMessages();
         assertTrue(msgs.isEmpty());

         try
         {
            //An exception should be thrown           
            tx.commit();
            fail();
         }
         catch (TransactionException e)
         {
            //Ok
         }

         Thread.sleep(1000);

         msgs = receiver1.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver2.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver3.getMessages();
         assertTrue(msgs.isEmpty());

         //Nodes 2 and 3 should have a held tx

         assertTrue(office1.getHoldingTransactions().isEmpty());

         assertEquals(1, office2.getHoldingTransactions().size());

         assertEquals(1, office3.getHoldingTransactions().size());

         //We now kill the office - this should make the other offices do their transaction check
         office1.stop();

         Thread.sleep(1000);

         //This should result in the held txs being rolled back

         assertTrue(office1.getHoldingTransactions().isEmpty());

         assertTrue(office2.getHoldingTransactions().isEmpty());

         assertTrue(office3.getHoldingTransactions().isEmpty());

         //The tx should be removed from the holding area and nothing should be received
         //remember node1 has now crashed so no point checking receiver1

         msgs = receiver2.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver3.getMessages();
         assertTrue(msgs.isEmpty());

      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }

         if (office2 != null)
         {
            office2.stop();
         }

         if (office3 != null)
         {
            office3.stop();
         }
      }
   }
View Full Code Here

      }
   }

   public void testCrashAfterPersist() throws Exception
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;
      DefaultClusteredPostOffice office3 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);

         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);

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

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue3", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office3.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);

         //This will make it fail after casting and persisting the message in the db
         office1.setFail(false, true, false);

         Transaction tx = tr.createTransaction();

         final int NUM_MESSAGES = 10;

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            Message msg = CoreMessageFactory.createCoreMessage(i, true, null);

            MessageReference ref = ms.reference(msg);

            office1.route(ref, new SimpleCondition("topic1"), tx);
         }

         Thread.sleep(1000);

         List msgs = receiver1.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver2.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver3.getMessages();
         assertTrue(msgs.isEmpty());

         try
         {
            //An exception should be thrown           
            tx.commit();
            fail();
         }
         catch (TransactionException e)
         {
            //Ok
         }

         Thread.sleep(1000);

         msgs = receiver1.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver2.getMessages();
         assertTrue(msgs.isEmpty());

         msgs = receiver3.getMessages();
         assertTrue(msgs.isEmpty());

         //There should be held tx in 2 and 3 but not in 1

         assertTrue(office1.getHoldingTransactions().isEmpty());

         assertEquals(1, office2.getHoldingTransactions().size());

         assertEquals(1, office3.getHoldingTransactions().size());

         //We now kill the office - this should make the other office do it's transaction check
         office1.stop();

         Thread.sleep(1000);

         assertTrue(office1.getHoldingTransactions().isEmpty());

         assertTrue(office2.getHoldingTransactions().isEmpty());

         assertTrue(office3.getHoldingTransactions().isEmpty());

         //The tx should be removed from the holding area and messages be received
         //no point checking receiver1 since node1 has crashed

         msgs = receiver2.getMessages();
View Full Code Here

      consumeBitByBit(true, true);
   }

   public void testSimpleMessagePull() throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);

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

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

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         // Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         // Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         // Pull from 1 to 2

         receiver2.setMaxRefs(1);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("r2 " + receiver2.getMessages().size());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(1, queue2.getDeliveringCount());

         this.acknowledgeAll(receiver2);

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }

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

      }
   }

   public void testSimpleMessagePullCrashBeforeCommit() throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

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

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         //Force a failure before commit
         office2.setFail(true, false, false);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertEquals(1, office1.getHoldingTransactions().size());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(1, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         //Now kill office 2 - this should cause office1 to remove the dead held transaction

         office2.stop();
         Thread.sleep(2000);

         assertTrue(office1.getHoldingTransactions().isEmpty());

         //The delivery should be cancelled back to the queue too

         assertEquals(1, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());


      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }

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

      }
   }

   public void testSimpleMessagePullCrashAfterCommit() throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

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

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         //Force a failure after commit the ack to storage
         office2.setFail(false, true, false);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertEquals(1, office1.getHoldingTransactions().size());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(1, queue1.getDeliveringCount());

         //Now kill office 2 - this should cause office1 to remove the dead held transaction

         office2.stop();
         Thread.sleep(2000);

         assertTrue(office1.getHoldingTransactions().isEmpty());

         //The delivery should be committed

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }

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

      }
   }

   public void testFailHandleMessagePullResult() throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

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

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         office2.setFail(false, false, true);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         //The delivery should be rolled back

         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(1, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());
      }
      finally
      {
         if (office1 != null)
         {
            office1.stop();
         }

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

      }
   }

   protected void consumeAll(boolean persistent, boolean recoverable) throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;
      DefaultClusteredPostOffice office3 = null;
      DefaultClusteredPostOffice office4 = null;
      DefaultClusteredPostOffice office5 = null;

      boolean readOK;

      try
      {
         log.trace("Creating post offices");

         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office4 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(4, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office5 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(5, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         log.trace("Created postoffices");

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

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

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);

         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);

         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);

         log.trace("Created and bound queues");

         final int NUM_MESSAGES = 100;

         log.trace("sending messages");
         this.sendMessages("queue1", persistent, office1, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office2, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office3, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office4, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office5, NUM_MESSAGES, null);

         log.trace("sent messages");

         Thread.sleep(2000);


         log.trace("Finished small sleep");

         //Check the sizes

         log.trace("Here are the sizes:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         log.trace("Creating receiver");

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

         log.trace("Created receiver");

         queue1.add(receiver);

         log.trace("Added receiver");

         queue1.deliver();

         log.trace("Called deliver");

         log.trace("Waiting for handleInvocations");
         long start = System.currentTimeMillis();
         readOK = receiver.waitForHandleInvocations(NUM_MESSAGES * 5, 60000);
         long end = System.currentTimeMillis();
         log.trace("I waited for " + (end - start) + " ms");

         assertTrue(readOK);

         Thread.sleep(2000);


         log.trace("Here are the sizes:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(NUM_MESSAGES * 5, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(0, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(0, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(0, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         List messages = receiver.getMessages();

         assertNotNull(messages);

         assertEquals(NUM_MESSAGES * 5, messages.size());

         Iterator iter = messages.iterator();

         log.trace("Acknowledging messages");

         while (iter.hasNext())
         {
            Message msg = (Message) iter.next();

            receiver.acknowledge(msg, null);
         }

         log.trace("Acknowledged messages");

         receiver.clear();

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         if (checkNoMessageData())
         {
            fail("Message data still in database");
         }
      }
      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();
         }
      }
   }
View Full Code Here

      JChannelFactory jChannelFactory =
         new ClusteredPersistenceServiceConfigFileJChannelFactory(configFilePath,
                                                                  ignoreMultiplexer,
                                                                  sc.getMBeanServer());

      DefaultClusteredPostOffice postOffice =
         new DefaultClusteredPostOffice(sc.getDataSource(), sc.getTransactionManager(),
                                        sc.getClusteredPostOfficeSQLProperties(), true, nodeID,
                                        "Clustered", ms, pm, tr, ff, cf,
                                        groupName, jChannelFactory,
                                        stateTimeout, castTimeout, pullPolicy, rf, mapper, 1000, 10);
     
      postOffice.start();

      return postOffice;
   }
View Full Code Here

      }
   }

   protected void consumeBitByBit(boolean persistent, boolean recoverable) throws Throwable
   {
      DefaultClusteredPostOffice office1 = null;
      DefaultClusteredPostOffice office2 = null;
      DefaultClusteredPostOffice office3 = null;
      DefaultClusteredPostOffice office4 = null;
      DefaultClusteredPostOffice office5 = null;

      boolean readOK;

      try
      {
         office1 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(1, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office4 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(4, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         office5 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(5, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

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

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);

         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);

         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);

         final int NUM_MESSAGES = 100;

         this.sendMessages("queue1", persistent, office1, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office2, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office3, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office4, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office5, NUM_MESSAGES, null);

         Thread.sleep(2000);

         // Check the sizes

         log.trace("Here are the sizes 1:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue2.add(receiver2);
         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue3.add(receiver3);
         SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue4.add(receiver4);
         SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue5.add(receiver5);

         receiver1.setMaxRefs(5);
         queue1.deliver();
         readOK = receiver1.waitForHandleInvocations(5, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 5, queue1.memoryRefCount());
         assertEquals(5, queue1.getDeliveringCount());

         acknowledgeAll(receiver1);
         assertEquals(0, queue1.getDeliveringCount());
         receiver1.setMaxRefs(0);

         receiver2.setMaxRefs(10);
         queue2.deliver();
         readOK = receiver2.waitForHandleInvocations(10, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(10, queue2.getDeliveringCount());
         acknowledgeAll(receiver2);
         receiver2.setMaxRefs(0);

         receiver3.setMaxRefs(15);
         queue3.deliver();
         readOK = receiver3.waitForHandleInvocations(15, 20000);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(15, queue3.getDeliveringCount());
         acknowledgeAll(receiver3);
         receiver3.setMaxRefs(0);

         receiver4.setMaxRefs(20);
         queue4.deliver();
         readOK = receiver4.waitForHandleInvocations(20, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(20, queue4.getDeliveringCount());
         acknowledgeAll(receiver4);
         receiver4.setMaxRefs(0);

         receiver5.setMaxRefs(25);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(25, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 25, queue5.memoryRefCount());
         assertEquals(25, queue5.getDeliveringCount());
         acknowledgeAll(receiver5);
         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         log.trace("Here are the sizes 2:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         // Consume the rest from queue 5
         receiver5.setMaxRefs(NUM_MESSAGES - 25);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(NUM_MESSAGES - 25, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("receiver5 msgs:" + receiver5.getMessages().size());

         log.trace("Here are the sizes 3:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         // This will result in an extra one being pulled from queue1 - we cannot avoid this. This
         // is because the channel does not know that the receiver is full unless it tries with a
         // ref so it needs to retrieve one

                                                                   // http://jira.jboss.org/jira/browse/JBMESSAGING-901                                                                         
         assertEquals(NUM_MESSAGES - 6, queue1.memoryRefCount())// <-  expected:<94> but was:<93>
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(NUM_MESSAGES - 25, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // Now consume 5 more from queue5, they should come from queue1 which has the most messages

         log.trace("Consume 5 more from queue 5");

         receiver5.setMaxRefs(5);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(5, 20000);
         assertTrue(readOK);

         Thread.sleep(4000);

         log.trace("Here are the sizes 4:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount()); // <--  expected:<89> but was:<88>

         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(5, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver1.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // Consume 1 more - should pull one from queue2

         receiver5.setMaxRefs(1);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(1, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("Here are the sizes 5:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(1, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // From queue 4 consume everything else

         int num = NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1;
         receiver4.setMaxRefs(num);
         queue4.deliver();
         readOK = receiver4.waitForHandleInvocations(num, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("Here are the sizes 6:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(0, queue3.memoryRefCount()); // <- sometimes, there is still 1 message left in this queue
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(0, queue4.memoryRefCount());
         assertEquals(NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1, queue4.getDeliveringCount());

         assertEquals(0, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         acknowledgeAll(receiver4);

         assertEquals(0, queue4.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         if (checkNoMessageData())
         {
            fail("Message data still in database");
         }
      }
      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();
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.messaging.core.plugin.postoffice.cluster.DefaultClusteredPostOffice

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.