Esempio n. 1
0
  /**
   * Tests if the Message Size alert gets thrown when message of higher than threshold limit is sent
   *
   * @throws Exception
   */
  public void testMessageSizeAlert() throws Exception {
    setSession(new InternalTestProtocolSession(getVirtualHost()));
    AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore());
    getSession().addChannel(channel);

    setQueue(
        AMQQueueFactory.createAMQQueueImpl(
            new AMQShortString("testQueue2"),
            false,
            new AMQShortString("AMQueueAlertTest"),
            false,
            false,
            getVirtualHost(),
            null));
    _queueMBean = (AMQQueueMBean) getQueue().getManagedObject();
    _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT);
    _queueMBean.setMaximumMessageSize(MAX_MESSAGE_SIZE);

    sendMessages(channel, 1, MAX_MESSAGE_SIZE * 2);
    assertTrue(_queueMBean.getMessageCount() == 1);

    Notification lastNotification = _queueMBean.getLastNotification();
    assertNotNull(lastNotification);

    String notificationMsg = lastNotification.getMessage();
    assertTrue(notificationMsg.startsWith(NotificationCheck.MESSAGE_SIZE_ALERT.name()));
  }
Esempio n. 2
0
  public void testMessageCountPersistent() throws Exception {
    int messageCount = 10;
    sendMessages(messageCount, true);
    assertEquals("", messageCount, _queueMBean.getMessageCount().intValue());
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);
    long queueDepth = (messageCount * MESSAGE_SIZE);
    assertTrue(_queueMBean.getQueueDepth() == queueDepth);

    _queueMBean.deleteMessageFromTop();
    assertTrue(_queueMBean.getMessageCount() == (messageCount - 1));
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);

    _queueMBean.clearQueue();
    assertTrue(_queueMBean.getMessageCount() == 0);
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);

    // Ensure that the data has been removed from the Store
    verifyBrokerState();
  }
Esempio n. 3
0
  public void testConsumerCount() throws AMQException {

    assertTrue(getQueue().getActiveConsumerCount() == 0);
    assertTrue(_queueMBean.getActiveConsumerCount() == 0);

    InternalTestProtocolSession protocolSession = new InternalTestProtocolSession(getVirtualHost());

    AMQChannel channel = new AMQChannel(protocolSession, 1, getMessageStore());
    protocolSession.addChannel(channel);

    Subscription subscription =
        SUBSCRIPTION_FACTORY.createSubscription(
            channel.getChannelId(),
            protocolSession,
            new AMQShortString("test"),
            false,
            null,
            false,
            channel.getCreditManager());

    getQueue().registerSubscription(subscription, false);
    assertEquals(1, (int) _queueMBean.getActiveConsumerCount());

    SubscriptionFactory subscriptionFactory = SUBSCRIPTION_FACTORY;
    Subscription s1 =
        subscriptionFactory.createSubscription(
            channel.getChannelId(),
            protocolSession,
            new AMQShortString("S1"),
            false,
            null,
            true,
            channel.getCreditManager());

    Subscription s2 =
        subscriptionFactory.createSubscription(
            channel.getChannelId(),
            protocolSession,
            new AMQShortString("S2"),
            false,
            null,
            true,
            channel.getCreditManager());
    getQueue().registerSubscription(s1, false);
    getQueue().registerSubscription(s2, false);
    assertTrue(_queueMBean.getActiveConsumerCount() == 3);
    assertTrue(_queueMBean.getConsumerCount() == 3);

    s1.close();
    assertEquals(2, (int) _queueMBean.getActiveConsumerCount());
    assertTrue(_queueMBean.getConsumerCount() == 3);
  }
Esempio n. 4
0
  public void testDeleteMessages() throws Exception {
    int messageCount = 10;
    sendMessages(messageCount, true);
    assertEquals("", messageCount, _queueMBean.getMessageCount().intValue());
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);
    long queueDepth = (messageCount * MESSAGE_SIZE);
    assertTrue(_queueMBean.getQueueDepth() == queueDepth);

    // delete first message
    _queueMBean.deleteMessages(1L, 1L);
    assertTrue(_queueMBean.getMessageCount() == (messageCount - 1));
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);
    try {
      _queueMBean.viewMessageContent(1L);
      fail("Message should no longer be on the queue");
    } catch (Exception e) {

    }

    // delete last message, leaving 2nd to 9th
    _queueMBean.deleteMessages(10L, 10L);
    assertTrue(_queueMBean.getMessageCount() == (messageCount - 2));
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);
    try {
      _queueMBean.viewMessageContent(10L);
      fail("Message should no longer be on the queue");
    } catch (Exception e) {

    }

    // delete remaining messages, leaving none
    _queueMBean.deleteMessages(2L, 9L);
    assertTrue(_queueMBean.getMessageCount() == (0));
    assertTrue(_queueMBean.getReceivedMessageCount() == messageCount);

    // Ensure that the data has been removed from the Store
    verifyBrokerState();
  }
Esempio n. 5
0
  public void testFlowControlProperties() throws Exception {
    assertTrue(_queueMBean.getCapacity() == 0);
    assertTrue(_queueMBean.getFlowResumeCapacity() == 0);
    assertFalse(_queueMBean.isFlowOverfull());

    // capacity currently 0, try setting FlowResumeCapacity above this
    try {
      _queueMBean.setFlowResumeCapacity(1L);
      fail("Should have failed to allow setting FlowResumeCapacity above Capacity");
    } catch (IllegalArgumentException ex) {
      // expected exception
      assertTrue(_queueMBean.getFlowResumeCapacity() == 0);
    }

    // add a message to the queue
    sendMessages(1, true);

    // (FlowResume)Capacity currently 0, set both to 2
    _queueMBean.setCapacity(2L);
    assertTrue(_queueMBean.getCapacity() == 2L);
    _queueMBean.setFlowResumeCapacity(2L);
    assertTrue(_queueMBean.getFlowResumeCapacity() == 2L);

    // Try setting Capacity below FlowResumeCapacity
    try {
      _queueMBean.setCapacity(1L);
      fail("Should have failed to allow setting Capacity below FlowResumeCapacity");
    } catch (IllegalArgumentException ex) {
      // expected exception
      assertTrue(_queueMBean.getCapacity() == 2);
    }

    // create a channel and use it to exercise the capacity check mechanism
    AMQChannel channel = new AMQChannel(getSession(), 1, getMessageStore());
    getQueue().checkCapacity(channel);

    assertTrue(_queueMBean.isFlowOverfull());
    assertTrue(channel.getBlocking());

    // set FlowResumeCapacity to MESSAGE_SIZE and check queue is now underfull and channel unblocked
    _queueMBean.setCapacity(MESSAGE_SIZE); // must increase capacity too
    _queueMBean.setFlowResumeCapacity(MESSAGE_SIZE);

    assertFalse(_queueMBean.isFlowOverfull());
    assertFalse(channel.getBlocking());
  }
Esempio n. 6
0
  public void testExceptions() throws Exception {
    try {
      _queueMBean.viewMessages(0L, 3L);
      fail();
    } catch (JMException ex) {

    }

    try {
      _queueMBean.viewMessages(2L, 1L);
      fail();
    } catch (JMException ex) {

    }

    try {
      _queueMBean.viewMessages(-1L, 1L);
      fail();
    } catch (JMException ex) {

    }

    try {
      long end = Integer.MAX_VALUE;
      end += 2;
      _queueMBean.viewMessages(1L, end);
      fail("Expected Exception due to oversized(> 2^31) message range");
    } catch (JMException ex) {

    }

    IncomingMessage msg = message(false, false);
    getQueue().clearQueue();
    ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>();
    qs.add(getQueue());
    msg.enqueue(qs);
    MessageMetaData mmd = msg.headersReceived();
    msg.setStoredMessage(getMessageStore().addMessage(mmd));
    long id = msg.getMessageNumber();

    msg.addContentBodyFrame(
        new ContentChunk() {
          ByteBuffer _data = ByteBuffer.allocate((int) MESSAGE_SIZE);

          {
            _data.limit((int) MESSAGE_SIZE);
          }

          public int getSize() {
            return (int) MESSAGE_SIZE;
          }

          public ByteBuffer getData() {
            return _data;
          }

          public void reduceToFit() {}
        });

    AMQMessage m = new AMQMessage(msg.getStoredMessage());
    for (BaseQueue q : msg.getDestinationQueues()) {
      q.enqueue(m);
    }
    //        _queue.process(_storeContext, new QueueEntry(_queue, msg), false);
    _queueMBean.viewMessageContent(id);
    try {
      _queueMBean.viewMessageContent(id + 1);
      fail();
    } catch (JMException ex) {

    }
  }
Esempio n. 7
0
  public void testGeneralProperties() throws Exception {
    long maxQueueDepth = 1000; // in bytes
    _queueMBean.setMaximumMessageCount(50000l);
    _queueMBean.setMaximumMessageSize(2000l);
    _queueMBean.setMaximumQueueDepth(maxQueueDepth);

    assertEquals(
        "Max MessageCount not set", 50000, _queueMBean.getMaximumMessageCount().longValue());
    assertEquals("Max MessageSize not set", 2000, _queueMBean.getMaximumMessageSize().longValue());
    assertEquals(
        "Max QueueDepth not set", maxQueueDepth, _queueMBean.getMaximumQueueDepth().longValue());

    assertEquals("Queue Name does not match", new AMQShortString(getName()), _queueMBean.getName());
    assertFalse("AutoDelete should not be set.", _queueMBean.isAutoDelete());
    assertFalse("Queue should not be durable.", _queueMBean.isDurable());

    // set+get exclusivity using the mbean, and also verify it is actually updated in the queue
    _queueMBean.setExclusive(true);
    assertTrue("Exclusive property should be true.", _queueMBean.isExclusive());
    assertTrue("Exclusive property should be true.", getQueue().isExclusive());
    _queueMBean.setExclusive(false);
    assertFalse("Exclusive property should be false.", _queueMBean.isExclusive());
    assertFalse("Exclusive property should be false.", getQueue().isExclusive());
  }
Esempio n. 8
0
  /*
   This test sends some messages to the queue with subscribers needing message to be acknowledged.
   The messages will not be acknowledged and will be required twice. Why we are checking this is because
   the bug reported said that the queueDepth keeps increasing when messages are requeued.
   // TODO - queue depth now includes unacknowledged messages so does not go down when messages are delivered

   The QueueDepth should decrease when messages are delivered from the queue (QPID-408)
  */
  public void testQueueDepthAlertWithSubscribers() throws Exception {
    AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore());
    getSession().addChannel(channel);

    // Create queue
    setQueue(getNewQueue());
    Subscription subscription =
        SUBSCRIPTION_FACTORY.createSubscription(
            channel.getChannelId(),
            getSession(),
            new AMQShortString("consumer_tag"),
            true,
            null,
            false,
            channel.getCreditManager());

    getQueue().registerSubscription(subscription, false);

    _queueMBean = (AMQQueueMBean) getQueue().getManagedObject();
    _queueMBean.setMaximumMessageCount(9999l); // Set a high value, because this is not being tested
    _queueMBean.setMaximumQueueDepth(MAX_QUEUE_DEPTH);

    // Send messages(no of message to be little more than what can cause a Queue_Depth alert)
    int messageCount = Math.round(MAX_QUEUE_DEPTH / MAX_MESSAGE_SIZE) + 10;
    long totalSize = (messageCount * MAX_MESSAGE_SIZE);
    sendMessages(channel, messageCount, MAX_MESSAGE_SIZE);

    // Check queueDepth. There should be no messages on the queue and as the subscriber is listening
    // so there should be no Queue_Deoth alert raised
    assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth()));
    Notification lastNotification = _queueMBean.getLastNotification();
    //        assertNull(lastNotification);

    // Kill the subscriber and check for the queue depth values.
    // Messages are unacknowledged, so those should get requeued. All messages should be on the
    // Queue
    getQueue().unregisterSubscription(subscription);
    channel.requeue();

    assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth()));

    lastNotification = _queueMBean.getLastNotification();
    assertNotNull(lastNotification);
    String notificationMsg = lastNotification.getMessage();
    assertTrue(notificationMsg.startsWith(NotificationCheck.QUEUE_DEPTH_ALERT.name()));

    // Connect a consumer again and check QueueDepth values. The queue should get emptied.
    // Messages will get delivered but still are unacknowledged.
    Subscription subscription2 =
        SUBSCRIPTION_FACTORY.createSubscription(
            channel.getChannelId(),
            getSession(),
            new AMQShortString("consumer_tag"),
            true,
            null,
            false,
            channel.getCreditManager());

    getQueue().registerSubscription(subscription2, false);

    while (getQueue().getUndeliveredMessageCount() != 0) {
      Thread.sleep(100);
    }
    //        assertEquals(new Long(0), new Long(_queueMBean.getQueueDepth()));

    // Kill the subscriber again. Now those messages should get requeued again. Check if the queue
    // depth
    // value is correct.
    getQueue().unregisterSubscription(subscription2);
    channel.requeue();

    assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth()));
    getSession().closeSession();

    // Check the clear queue
    _queueMBean.clearQueue();
    assertEquals(new Long(0), new Long(_queueMBean.getQueueDepth()));
  }