Package org.hornetq.core.server.impl

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


      FakeConsumer consumer = new FakeConsumer(filter);
   }

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

      final int numMessages = 20;

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

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

         queue.addLast(ref);

         refs.add(ref);
      }

      Assert.assertEquals(numMessages, queue.getMessageCount());

      Iterator<MessageReference> iterator = queue.iterator();     
      List<MessageReference> list = new ArrayList<MessageReference>();
      while (iterator.hasNext())
      {
         list.add(iterator.next());
      }
View Full Code Here


   }

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

      Filter filter = new FakeFilter("fruit", "orange");

      FakeConsumer consumer = new FakeConsumer(filter);

      queue.addConsumer(consumer);

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

      MessageReference ref1 = generateReference(queue, 1);

      ref1.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));

      queue.addLast(ref1);

      MessageReference ref2 = generateReference(queue, 2);

      ref2.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));

      queue.addLast(ref2);

      refs.add(ref2);

      Assert.assertEquals(2, queue.getMessageCount());
     
      awaitExecution();;

      Assert.assertEquals(1, consumer.getReferences().size());

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

      assertRefListsIdenticalRefs(refs, consumer.getReferences());

      queue.acknowledge(ref2);

      queue.removeConsumer(consumer);

      queue.addConsumer(consumer);

      queue.deliverNow();

      refs.clear();

      consumer.clearReferences();

      MessageReference ref3 = generateReference(queue, 3);

      ref3.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));

      queue.addLast(ref3);

      MessageReference ref4 = generateReference(queue, 4);

      ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));

      queue.addLast(ref4);

      refs.add(ref4);

      Assert.assertEquals(3, queue.getMessageCount());
     
      awaitExecution();;

      Assert.assertEquals(1, consumer.getReferences().size());

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

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

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

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

      FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));

      consumer.setStatusImmediate(HandleStatus.BUSY);

      queue.addConsumer(consumer);

      final int numMessages = 10;

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

      for (int i = 0; i < numMessages; i++)
      {
         MessageReference ref = generateReference(queue, i);
         ref.getMessage().putStringProperty("color", "green");
         refs.add(ref);

         queue.addLast(ref);
      }

      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());

      queue.deliverNow();

      consumer.setStatusImmediate(null);

      queue.deliverNow();

      List<MessageReference> receeivedRefs = consumer.getReferences();
      int currId = 0;
      for (MessageReference receeivedRef : receeivedRefs)
      {
View Full Code Here

      }
   }

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

      FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));

      consumer.setStatusImmediate(HandleStatus.BUSY);

      queue.addConsumer(consumer);

      final int numMessages = 10;

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

      for (int i = 0; i < numMessages; i++)
      {
         MessageReference ref = generateReference(queue, i);
         ref.getMessage().putStringProperty("color", "red");
         refs.add(ref);

         queue.addLast(ref);
      }

      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());

      queue.deliverNow();

      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());
      Assert.assertTrue(consumer.getReferences().isEmpty());

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

         refs.add(ref);
         ref.getMessage().putStringProperty("color", "green");
         queue.addLast(ref);
      }

      Assert.assertEquals(20, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());
      Assert.assertTrue(consumer.getReferences().isEmpty());

      consumer.setStatusImmediate(null);

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

         refs.add(ref);

         queue.addLast(ref);
      }

      queue.deliverNow();

      Assert.assertEquals(numMessages, consumer.getReferences().size());
      Assert.assertEquals(30, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(10, queue.getDeliveringCount());

      List<MessageReference> receeivedRefs = consumer.getReferences();
      int currId = 10;
      for (MessageReference receeivedRef : receeivedRefs)
      {
View Full Code Here

      }
   }

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

      final int numMessages = 10;
      List<MessageReference> refs = new ArrayList<MessageReference>();

      for (int i = 0; i < numMessages; i++)
      {
         MessageReference ref = generateReference(queue, i);
         ref.getMessage().putStringProperty("color", "red");
         refs.add(ref);

         queue.addLast(ref);
      }

      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());

      queue.deliverNow();

      Assert.assertEquals(10, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(0, queue.getDeliveringCount());

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

         refs.add(ref);
         ref.getMessage().putStringProperty("color", "green");
         queue.addLast(ref);
      }

      FakeConsumer consumer = new FakeConsumer(FilterImpl.createFilter("color = 'green'"));

      queue.addConsumer(consumer);

      queue.deliverNow();

      Assert.assertEquals(20, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(10, queue.getDeliveringCount());

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

         refs.add(ref);
         ref.getMessage().putStringProperty("color", "green");
         queue.addLast(ref);
      }

      queue.deliverNow();

      Assert.assertEquals(20, consumer.getReferences().size());
      Assert.assertEquals(30, queue.getMessageCount());
      Assert.assertEquals(0, queue.getScheduledCount());
      Assert.assertEquals(20, queue.getDeliveringCount());
   }
View Full Code Here

   // Private ------------------------------------------------------------------------------

   private void testConsumerWithFilters(final boolean direct) throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      new FakePostOffice(),
                                      null,
                                      null,
                                      executor);

      Filter filter = new FakeFilter("fruit", "orange");

      FakeConsumer consumer = new FakeConsumer(filter);

      if (direct)
      {
         queue.addConsumer(consumer);
      }

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

      MessageReference ref1 = generateReference(queue, 1);

      ref1.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("banana"));

      queue.addLast(ref1);

      MessageReference ref2 = generateReference(queue, 2);

      ref2.getMessage().putStringProperty(new SimpleString("cheese"), new SimpleString("stilton"));

      queue.addLast(ref2);

      MessageReference ref3 = generateReference(queue, 3);

      ref3.getMessage().putStringProperty(new SimpleString("cake"), new SimpleString("sponge"));

      queue.addLast(ref3);

      MessageReference ref4 = generateReference(queue, 4);

      ref4.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));

      refs.add(ref4);

      queue.addLast(ref4);

      MessageReference ref5 = generateReference(queue, 5);

      ref5.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("apple"));

      queue.addLast(ref5);

      MessageReference ref6 = generateReference(queue, 6);

      ref6.getMessage().putStringProperty(new SimpleString("fruit"), new SimpleString("orange"));

      refs.add(ref6);

      queue.addLast(ref6);

      if (!direct)
      {
         queue.addConsumer(consumer);

         queue.deliverNow();
      }

      Assert.assertEquals(6, queue.getMessageCount());
     
      awaitExecution();;

      Assert.assertEquals(2, consumer.getReferences().size());

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

      assertRefListsIdenticalRefs(refs, consumer.getReferences());

      queue.acknowledge(ref5);
      queue.acknowledge(ref6);

      queue.removeConsumer(consumer);

      consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      queue.deliverNow();

      Assert.assertEquals(4, queue.getMessageCount());

      Assert.assertEquals(4, consumer.getReferences().size());

      Assert.assertEquals(4, queue.getDeliveringCount());
   }
View Full Code Here

   }

   public void testMessageOrder() throws Exception
   {
      FakeConsumer consumer = new FakeConsumer();
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);
      MessageReference messageReference = generateReference(queue, 1);
      MessageReference messageReference2 = generateReference(queue, 2);
      MessageReference messageReference3 = generateReference(queue, 3);
      queue.addFirst(messageReference);
      queue.addLast(messageReference2);
      queue.addFirst(messageReference3);

      Assert.assertEquals(0, consumer.getReferences().size());
      queue.addConsumer(consumer);
      queue.deliverNow();

      Assert.assertEquals(3, consumer.getReferences().size());
      Assert.assertEquals(messageReference3, consumer.getReferences().get(0));
      Assert.assertEquals(messageReference, consumer.getReferences().get(1));
      Assert.assertEquals(messageReference2, consumer.getReferences().get(2));
View Full Code Here

      Assert.assertEquals(messageReference2, consumer.getReferences().get(2));
   }

   public void testMessagesAdded() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);
      MessageReference messageReference = generateReference(queue, 1);
      MessageReference messageReference2 = generateReference(queue, 2);
      MessageReference messageReference3 = generateReference(queue, 3);
      queue.addLast(messageReference);
      queue.addLast(messageReference2);
      queue.addLast(messageReference3);
      Assert.assertEquals(queue.getMessagesAdded(), 3);
   }
View Full Code Here

      Assert.assertEquals(queue.getMessagesAdded(), 3);
   }

   public void testGetReference() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);
      MessageReference messageReference = generateReference(queue, 1);
      MessageReference messageReference2 = generateReference(queue, 2);
      MessageReference messageReference3 = generateReference(queue, 3);
      queue.addFirst(messageReference);
      queue.addFirst(messageReference2);
      queue.addFirst(messageReference3);
      Assert.assertEquals(queue.getReference(2), messageReference2);

   }
View Full Code Here

   }

   public void testGetNonExistentReference() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);
      MessageReference messageReference = generateReference(queue, 1);
      MessageReference messageReference2 = generateReference(queue, 2);
      MessageReference messageReference3 = generateReference(queue, 3);
      queue.addFirst(messageReference);
      queue.addFirst(messageReference2);
      queue.addFirst(messageReference3);
      Assert.assertNull(queue.getReference(5));

   }
View Full Code Here

TOP

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

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.