Search in sources :

Example 1 with NonCachedMessageEvaluationContext

use of org.apache.activemq.filter.NonCachedMessageEvaluationContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testMoveMessages.

/**
 * The test queue is filled with QUEUE_SIZE test messages, each with a
 * numeric id property beginning at 0. Once the queue is filled, the last
 * message (id = QUEUE_SIZE-1) is moved to another queue. The test succeeds
 * if the move completes within TEST_TIMEOUT milliseconds.
 *
 * @throws Exception
 */
public void testMoveMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
    final long TEST_TIMEOUT = 20000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.moveMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to move the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Moving the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Example 2 with NonCachedMessageEvaluationContext

use of org.apache.activemq.filter.NonCachedMessageEvaluationContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testRemoveMessages.

public void testRemoveMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final long TEST_TIMEOUT = 20000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.removeMatchingMessages("id=" + (QUEUE_SIZE - 1)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to remove the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Removing the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Example 3 with NonCachedMessageEvaluationContext

use of org.apache.activemq.filter.NonCachedMessageEvaluationContext in project activemq-artemis by apache.

the class LargeQueueSparseDeleteTest method testCopyMessages.

public void testCopyMessages() throws Exception {
    final int QUEUE_SIZE = 30000;
    final String MOVE_TO_DESTINATION_NAME = getDestinationString() + ".dest";
    final long TEST_TIMEOUT = 10000;
    // Populate a test queue with uniquely-identifiable messages.
    Connection conn = createConnection();
    try {
        conn.start();
        Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = session.createProducer(destination);
        for (int i = 0; i < QUEUE_SIZE; i++) {
            Message message = session.createMessage();
            message.setIntProperty("id", i);
            producer.send(message);
        }
        session.commit();
    } finally {
        conn.close();
    }
    // Access the implementation of the test queue and move the last message
    // to another queue. Verify that the move occurred within the limits of
    // the test.
    Queue queue = (Queue) broker.getRegionBroker().getDestinationMap().get(destination);
    ConnectionContext context = new ConnectionContext(new NonCachedMessageEvaluationContext());
    context.setBroker(broker.getBroker());
    context.getMessageEvaluationContext().setDestination(destination);
    long startTimeMillis = System.currentTimeMillis();
    Assert.assertEquals(1, queue.copyMatchingMessagesTo(context, "id=" + (QUEUE_SIZE - 1), createDestination(MOVE_TO_DESTINATION_NAME)));
    long durationMillis = System.currentTimeMillis() - startTimeMillis;
    LOG.info("It took " + durationMillis + "ms to copy the last message from a queue a " + QUEUE_SIZE + " messages.");
    Assert.assertTrue("Copying the message took too long: " + durationMillis + "ms", durationMillis < TEST_TIMEOUT);
}
Also used : Message(javax.jms.Message) NonCachedMessageEvaluationContext(org.apache.activemq.filter.NonCachedMessageEvaluationContext) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) ConnectionContext(org.apache.activemq.broker.ConnectionContext) Queue(org.apache.activemq.broker.region.Queue) Session(javax.jms.Session)

Aggregations

Connection (javax.jms.Connection)3 Message (javax.jms.Message)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 ConnectionContext (org.apache.activemq.broker.ConnectionContext)3 Queue (org.apache.activemq.broker.region.Queue)3 NonCachedMessageEvaluationContext (org.apache.activemq.filter.NonCachedMessageEvaluationContext)3