Package org.hornetq.core.server.impl

Examples of org.hornetq.core.server.impl.QueueImpl$DelayedAddRedistributor


    * Test the paused and resumed states with async deliveries.
    * @throws Exception
    */
   public void testPauseAndResumeWithAsync() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      // pauses the queue
      queue.pause();

      final int numMessages = 10;

      List<MessageReference> refs = new ArrayList<MessageReference>();

      for (int i = 0; i < numMessages; i++)
      {
         MessageReference ref = generateReference(queue, i);

         refs.add(ref);

         queue.addLast(ref);
      }
      // even as this queue is paused, it will receive the messages anyway
      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());

      // Now add a consumer
      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      Assert.assertTrue(consumer.getReferences().isEmpty());
      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      // explicit order of delivery
      queue.deliverNow();
      // As the queue is paused, even an explicit order of delivery will not work.
      Assert.assertEquals(0, consumer.getReferences().size());
      Assert.assertEquals(numMessages, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());
      // resuming work
      queue.resume();
     
      awaitExecution();;

      // after resuming the delivery begins.
      assertRefListsIdenticalRefs(refs, consumer.getReferences());
      Assert.assertEquals(numMessages, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(numMessages, queue.getDeliveringCount());

   }
View Full Code Here


    * @throws Exception
    */

   public void testPauseAndResumeWithDirect() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      // Now add a consumer
      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      // brings to queue to paused state
      queue.pause();

      final int numMessages = 10;

      List<MessageReference> refs = new ArrayList<MessageReference>();

      for (int i = 0; i < numMessages; i++)
      {
         MessageReference ref = generateReference(queue, i);
         refs.add(ref);
         queue.addLast(ref);
      }

      // the queue even if it's paused will receive the message but won't forward
      // directly to the consumer until resumed.
      Assert.assertEquals(numMessages, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());
      Assert.assertTrue(consumer.getReferences().isEmpty());

      // brings the queue to resumed state.
      queue.resume();
     
     
      awaitExecution();;
     
      // resuming delivery of messages
      assertRefListsIdenticalRefs(refs, consumer.getReferences());
      Assert.assertEquals(numMessages, queue.getMessageCount());
      Assert.assertEquals(numMessages, queue.getDeliveringCount());

   }
View Full Code Here

   // The tests ----------------------------------------------------------------

   public void testScheduledNoConsumer() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  new SimpleString("queue1"),
                                  null,
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());

      // Send one scheduled

      long now = System.currentTimeMillis();

      MessageReference ref1 = generateReference(queue, 1);
      ref1.setScheduledDeliveryTime(now + 7000);
      queue.addTail(ref1);

      // Send some non scheduled messages

      MessageReference ref2 = generateReference(queue, 2);
      queue.addTail(ref2);
      MessageReference ref3 = generateReference(queue, 3);
      queue.addTail(ref3);
      MessageReference ref4 = generateReference(queue, 4);
      queue.addTail(ref4);

      // Now send some more scheduled messages

      MessageReference ref5 = generateReference(queue, 5);
      ref5.setScheduledDeliveryTime(now + 5000);
      queue.addTail(ref5);

      MessageReference ref6 = generateReference(queue, 6);
      ref6.setScheduledDeliveryTime(now + 4000);
      queue.addTail(ref6);

      MessageReference ref7 = generateReference(queue, 7);
      ref7.setScheduledDeliveryTime(now + 3000);
      queue.addTail(ref7);

      MessageReference ref8 = generateReference(queue, 8);
      ref8.setScheduledDeliveryTime(now + 6000);
      queue.addTail(ref8);

      List<MessageReference> refs = new ArrayList<MessageReference>();

      // Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
      // They may get stranded behind a big backlog

      refs.add(ref1);
      refs.add(ref8);
      refs.add(ref5);
      refs.add(ref6);
      refs.add(ref7);

      refs.add(ref2);
      refs.add(ref3);
      refs.add(ref4);

      Thread.sleep(7500);

      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      queue.deliverNow();

      assertRefListsIdenticalRefs(refs, consumer.getReferences());
   }
View Full Code Here

      assertRefListsIdenticalRefs(refs, consumer.getReferences());
   }

   public void testScheduled() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  new SimpleString("queue1"),
                                  null,
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());

      FakeConsumer consumer = null;

   
      // Send one scheduled

      long now = System.currentTimeMillis();

      MessageReference ref1 = generateReference(queue, 1);
      ref1.setScheduledDeliveryTime(now + 7000);
      queue.addTail(ref1);

      // Send some non scheduled messages

      MessageReference ref2 = generateReference(queue, 2);
      queue.addTail(ref2);
      MessageReference ref3 = generateReference(queue, 3);
      queue.addTail(ref3);
      MessageReference ref4 = generateReference(queue, 4);
      queue.addTail(ref4);

      // Now send some more scheduled messages

      MessageReference ref5 = generateReference(queue, 5);
      ref5.setScheduledDeliveryTime(now + 5000);
      queue.addTail(ref5);

      MessageReference ref6 = generateReference(queue, 6);
      ref6.setScheduledDeliveryTime(now + 4000);
      queue.addTail(ref6);

      MessageReference ref7 = generateReference(queue, 7);
      ref7.setScheduledDeliveryTime(now + 3000);
      queue.addTail(ref7);

      MessageReference ref8 = generateReference(queue, 8);
      ref8.setScheduledDeliveryTime(now + 6000);
      queue.addTail(ref8);

      consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      queue.deliverNow();
     

      List<MessageReference> refs = new ArrayList<MessageReference>();

      refs.add(ref2);
View Full Code Here

         {
            countDownLatch.countDown();
            return HandleStatus.HANDLED;
         }
      };
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  QueueImplTest.queue1,
                                  null,
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());
      MessageReference messageReference = generateReference(queue, 1);
      queue.addConsumer(consumer);
      messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 2000);
      queue.addHead(messageReference);

      boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
      Assert.assertTrue(gotLatch);
   }
View Full Code Here

   /*
    * Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
    */
   public void testConcurrentAddsDeliver() throws Exception
   {
      QueueImpl queue = (QueueImpl)queueFactory.createQueue(1,
                                             new SimpleString("address1"),
                                             new SimpleString("queue1"),
                                             null,
                                             null,
                                             false,
                                             false);

      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      final long testTime = 5000;

      Sender sender = new Sender(queue, testTime);

      Toggler toggler = new Toggler(queue, consumer, testTime);

      sender.start();

      toggler.start();

      sender.join();

      toggler.join();

      consumer.setStatusImmediate(HandleStatus.HANDLED);

      queue.deliverNow();

      if (sender.getException() != null)
      {
         throw sender.getException();
      }
View Full Code Here

   public void testName()
   {
      final SimpleString name = new SimpleString("oobblle");

      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      name,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertEquals(name, queue.getName());
   }
View Full Code Here

      Assert.assertEquals(name, queue.getName());
   }

   public void testDurable()
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      false,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertFalse(queue.isDurable());

      queue = new QueueImpl(1,
                            QueueImplTest.address1,
                            QueueImplTest.queue1,
                            null,
                            true,
                            false,
                            scheduledExecutor,
                            null,
                            null,
                            null,
                            executor);

      Assert.assertTrue(queue.isDurable());
   }
View Full Code Here

      Consumer cons2 = new FakeConsumer();

      Consumer cons3 = new FakeConsumer();

      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.addConsumer(cons1);

      Assert.assertEquals(1, queue.getConsumerCount());

      queue.removeConsumer(cons1);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.addConsumer(cons1);

      queue.addConsumer(cons2);

      queue.addConsumer(cons3);

      Assert.assertEquals(3, queue.getConsumerCount());

      queue.removeConsumer(new FakeConsumer());

      Assert.assertEquals(3, queue.getConsumerCount());

      queue.removeConsumer(cons1);

      Assert.assertEquals(2, queue.getConsumerCount());

      queue.removeConsumer(cons2);

      Assert.assertEquals(1, queue.getConsumerCount());

      queue.removeConsumer(cons3);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.removeConsumer(cons3);
   }
View Full Code Here

                            final Filter filter,
                            final PageSubscription subscription,
                            final boolean durable,
                            final boolean temporary)
   {
      return new QueueImpl(persistenceID,
                           address,
                           name,
                           filter,
                           subscription,
                           durable,
View Full Code Here

TOP

Related Classes of org.hornetq.core.server.impl.QueueImpl$DelayedAddRedistributor

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.