Exemplo n.º 1
0
  private void sendMessages(int messageCount, boolean persistent) throws AMQException {
    for (int i = 0; i < messageCount; i++) {
      IncomingMessage currentMessage = message(false, persistent);
      ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>();
      qs.add(getQueue());
      currentMessage.enqueue(qs);

      // route header
      MessageMetaData mmd = currentMessage.headersReceived();
      currentMessage.setStoredMessage(getMessageStore().addMessage(mmd));

      // Add the body so we have somthing to test later
      currentMessage.addContentBodyFrame(
          getSession()
              .getMethodRegistry()
              .getProtocolVersionMethodConverter()
              .convertToContentChunk(
                  new ContentBody(ByteBuffer.allocate((int) MESSAGE_SIZE), MESSAGE_SIZE)));

      AMQMessage m = new AMQMessage(currentMessage.getStoredMessage());
      for (BaseQueue q : currentMessage.getDestinationQueues()) {
        q.enqueue(m);
      }
    }
  }
Exemplo n.º 2
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) {

    }
  }