Esempio n. 1
0
  /**
   * Tests if MESSAGE AGE alert is thrown, when a message is in the queue for time higher than
   * threshold value of message age
   *
   * <p>Alternative test to FT-401 provided by client
   *
   * @throws Exception
   */
  public void testMessageAgeAlert() throws Exception {
    setSession(new InternalTestProtocolSession(getVirtualHost()));
    AMQChannel channel = new AMQChannel(getSession(), 2, getMessageStore());
    getSession().addChannel(channel);

    setQueue(
        AMQQueueFactory.createAMQQueueImpl(
            new AMQShortString("testQueue4"),
            false,
            new AMQShortString("AMQueueAlertTest"),
            false,
            false,
            getVirtualHost(),
            null));
    _queueMBean = (AMQQueueMBean) getQueue().getManagedObject();
    _queueMBean.setMaximumMessageCount(MAX_MESSAGE_COUNT);
    _queueMBean.setMaximumMessageAge(MAX_MESSAGE_AGE);

    sendMessages(channel, 1, MAX_MESSAGE_SIZE);

    // Ensure message sits on queue long enough to age.
    Thread.sleep(MAX_MESSAGE_AGE * 2);

    Notification lastNotification = _queueMBean.getLastNotification();
    assertNotNull("Last notification was null", lastNotification);

    String notificationMsg = lastNotification.getMessage();
    assertTrue(notificationMsg.startsWith(NotificationCheck.MESSAGE_AGE_ALERT.name()));
  }