Package org.hornetq.core.server.impl

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


    * 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.addTail(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.addTail(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

                            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

      ClientSessionFactory sf = locator.createSessionFactory();
      session = sf.createSession(false, true, false);
      session.start();
      session.createQueue(address, address, true);

      QueueImpl serverQueue = (QueueImpl)server.locateQueue(address);

      ClientProducer producer = session.createProducer(address);

      for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++)
      {
         ClientMessage msg = session.createMessage(true);
         msg.getBodyBuffer().writeBytes(new byte[512]);
         producer.send(msg);
      }
      session.commit();

      AddressControl addressControl = createManagementControl(address);
      Assert.assertEquals(0, addressControl.getNumberOfPages());

      ClientMessage msg = session.createMessage(true);
      msg.getBodyBuffer().writeBytes(new byte[512]);
      producer.send(msg);

      session.commit();
      Assert.assertEquals(1, addressControl.getNumberOfPages());

      msg = session.createMessage(true);
      msg.getBodyBuffer().writeBytes(new byte[512]);
      producer.send(msg);

      session.commit();
      Assert.assertEquals(1, addressControl.getNumberOfPages());

      msg = session.createMessage(true);
      msg.getBodyBuffer().writeBytes(new byte[512]);
      producer.send(msg);

      session.commit();

      Assert.assertEquals("# of pages is 2", 2, addressControl.getNumberOfPages());

      System.out.println("Address size=" + addressControl.getAddressSize());

      Assert.assertEquals(serverQueue.getPageSubscription().getPagingStore().getAddressSize(), addressControl.getAddressSize());
   }
View Full Code Here

        
         for (int i = 0 ; i < 100; i++)
         {
            long txid = storage.generateUniqueID();
           
            final Queue queue = new QueueImpl(storage.generateUniqueID(), SimpleString.toSimpleString("jms.topic.topic"), SimpleString.toSimpleString("jms.topic.topic"), FilterImpl.createFilter(HornetQServerImpl.GENERIC_IGNORED_FILTER), true, false, server.getScheduledPool(), server.getPostOffice(),
                                              storage, server.getAddressSettingsRepository(), server.getExecutorFactory().getExecutor());
           
            LocalQueueBinding binding = new LocalQueueBinding(queue.getAddress(), queue, server.getNodeID());
  
            storage.addQueueBinding(txid, binding);
           
            storage.commitBindings(txid);
         }
View Full Code Here

      long queueID = server.getStorageManager().generateUniqueID();
      long txID = server.getStorageManager().generateUniqueID();
     

      // Forcing a situation where the server would unexpectedly create a duplicated queue. The server should still start normally
      LocalQueueBinding newBinding = new LocalQueueBinding(QUEUE, new QueueImpl(queueID, QUEUE, QUEUE, null, true, false, null, null, null, null, null), server.getNodeID());
      server.getStorageManager().addQueueBinding(txID, newBinding);
      server.getStorageManager().commitBindings(txID);

      server.stop();
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

         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         QueueImpl queue = (QueueImpl)server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];
View Full Code Here

TOP

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

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.