Search in sources :

Example 6 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class StoreQueueCursorOrderTest method testSetBatchWithOrderedFutureCurrentFuture.

@Test
public void testSetBatchWithOrderedFutureCurrentFuture() throws Exception {
    final int count = 2;
    final Message[] messages = new Message[count];
    final TestMessageStore queueMessageStore = new TestMessageStore(messages, destination);
    final ConsumerInfo consumerInfo = new ConsumerInfo();
    final DestinationStatistics destinationStatistics = new DestinationStatistics();
    consumerInfo.setExclusive(true);
    final Queue queue = new Queue(brokerService, destination, queueMessageStore, destinationStatistics, null);
    queueMessageStore.start();
    queueMessageStore.registerIndexListener(null);
    QueueStorePrefetch underTest = new QueueStorePrefetch(queue, brokerService.getBroker());
    SystemUsage systemUsage = new SystemUsage();
    // ensure memory limit is reached
    systemUsage.getMemoryUsage().setLimit(messageBytesSize * 1);
    underTest.setSystemUsage(systemUsage);
    underTest.setEnableAudit(false);
    underTest.start();
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    ActiveMQTextMessage msg = getMessage(0);
    messages[0] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.setRecievedByDFBridge(true);
    final ActiveMQTextMessage msgRef = msg;
    FutureTask<Long> future = new FutureTask<Long>(new Runnable() {

        @Override
        public void run() {
            msgRef.getMessageId().setFutureOrSequenceLong(0L);
        }
    }, 0L) {
    };
    msg.getMessageId().setFutureOrSequenceLong(future);
    Executors.newSingleThreadExecutor().submit(future);
    underTest.addMessageLast(msg);
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    // second message will flip the cache but will be stored before the future task
    msg = getMessage(1);
    messages[1] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.setRecievedByDFBridge(true);
    final ActiveMQTextMessage msgRe2f = msg;
    FutureTask<Long> future2 = new FutureTask<Long>(new Runnable() {

        @Override
        public void run() {
            msgRe2f.getMessageId().setFutureOrSequenceLong(1L);
        }
    }, 1L) {
    };
    msg.getMessageId().setFutureOrSequenceLong(future2);
    Executors.newSingleThreadExecutor().submit(future2);
    underTest.addMessageLast(msg);
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    assertEquals("setBatch set", 1L, queueMessageStore.batch.get());
    int dequeueCount = 0;
    underTest.setMaxBatchSize(2);
    underTest.reset();
    while (underTest.hasNext() && dequeueCount < count) {
        MessageReference ref = underTest.next();
        ref.decrementReferenceCount();
        underTest.remove();
        LOG.info("Received message: {} with body: {}", ref.getMessageId(), ((ActiveMQTextMessage) ref.getMessage()).getText());
        assertEquals(dequeueCount++, ref.getMessageId().getProducerSequenceId());
    }
    underTest.release();
    assertEquals(count, dequeueCount);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Message(org.apache.activemq.command.Message) SystemUsage(org.apache.activemq.usage.SystemUsage) MessageReference(org.apache.activemq.broker.region.MessageReference) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) FutureTask(java.util.concurrent.FutureTask) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(org.apache.activemq.broker.region.Queue) Test(org.junit.Test)

Example 7 with Queue

use of org.apache.activemq.broker.region.Queue in project activemq-artemis by apache.

the class MessageGroupConfigTest method doTestGroupConfiguration.

public MessageGroupMap doTestGroupConfiguration(String type, Class classType) throws Exception {
    broker = new BrokerService();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMessageGroupMapFactoryType(type);
    PolicyMap policyMap = new PolicyMap();
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
    super.topic = false;
    ActiveMQDestination destination = (ActiveMQDestination) createDestination("org.apache.foo");
    Queue brokerDestination = (Queue) broker.getDestination(destination);
    assertNotNull(brokerDestination);
    MessageGroupMap messageGroupMap = brokerDestination.getMessageGroupOwners();
    assertNotNull(messageGroupMap);
    assertTrue(messageGroupMap.getClass().isAssignableFrom(classType));
    return messageGroupMap;
}
Also used : SimpleMessageGroupMap(org.apache.activemq.broker.region.group.SimpleMessageGroupMap) MessageGroupMap(org.apache.activemq.broker.region.group.MessageGroupMap) CachedMessageGroupMap(org.apache.activemq.broker.region.group.CachedMessageGroupMap) PolicyMap(org.apache.activemq.broker.region.policy.PolicyMap) BrokerService(org.apache.activemq.broker.BrokerService) PolicyEntry(org.apache.activemq.broker.region.policy.PolicyEntry) Queue(org.apache.activemq.broker.region.Queue) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination)

Example 8 with Queue

use of org.apache.activemq.broker.region.Queue 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 9 with Queue

use of org.apache.activemq.broker.region.Queue 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 10 with Queue

use of org.apache.activemq.broker.region.Queue 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

Queue (org.apache.activemq.broker.region.Queue)15 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 MessageReference (org.apache.activemq.broker.region.MessageReference)6 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)6 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)6 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)6 SystemUsage (org.apache.activemq.usage.SystemUsage)6 Message (org.apache.activemq.command.Message)5 Test (org.junit.Test)5 FutureTask (java.util.concurrent.FutureTask)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 ConnectionContext (org.apache.activemq.broker.ConnectionContext)4 RegionBroker (org.apache.activemq.broker.region.RegionBroker)4 Connection (javax.jms.Connection)3 Message (javax.jms.Message)3 MessageProducer (javax.jms.MessageProducer)3 Session (javax.jms.Session)3 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)3 NonCachedMessageEvaluationContext (org.apache.activemq.filter.NonCachedMessageEvaluationContext)3 BrokerService (org.apache.activemq.broker.BrokerService)2