Search in sources :

Example 6 with MessageReference

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

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

the class OrderPendingListTest method testAddAll.

@Test
public void testAddAll() throws Exception {
    OrderedPendingList list = new OrderedPendingList();
    TestPendingList source = new TestPendingList();
    source.addMessageFirst(new TestMessageReference(1));
    source.addMessageFirst(new TestMessageReference(2));
    source.addMessageFirst(new TestMessageReference(3));
    source.addMessageFirst(new TestMessageReference(4));
    source.addMessageFirst(new TestMessageReference(5));
    assertTrue(list.isEmpty());
    assertEquals(5, source.size());
    list.addAll(source);
    assertEquals(5, list.size());
    for (MessageReference message : source) {
        assertTrue(list.contains(message));
    }
    list.addAll(null);
}
Also used : MessageReference(org.apache.activemq.broker.region.MessageReference) Test(org.junit.Test)

Example 8 with MessageReference

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

the class StoreQueueCursorNoDuplicateTest method testNoDuplicateAfterCacheFullAndReadPast.

public void testNoDuplicateAfterCacheFullAndReadPast() throws Exception {
    final PersistenceAdapter persistenceAdapter = brokerService.getPersistenceAdapter();
    final MessageStore queueMessageStore = persistenceAdapter.createQueueMessageStore(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 * (count + 2));
    underTest.setSystemUsage(systemUsage);
    underTest.setEnableAudit(false);
    underTest.start();
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    final ConnectionContext contextNotInTx = new ConnectionContext();
    for (int i = 0; i < count; i++) {
        ActiveMQTextMessage msg = getMessage(i);
        msg.setMemoryUsage(systemUsage.getMemoryUsage());
        queueMessageStore.addMessage(contextNotInTx, msg);
        underTest.addMessageLast(msg);
    }
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    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 : MessageStore(org.apache.activemq.store.MessageStore) ConsumerInfo(org.apache.activemq.command.ConsumerInfo) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) SystemUsage(org.apache.activemq.usage.SystemUsage) ConnectionContext(org.apache.activemq.broker.ConnectionContext) MessageReference(org.apache.activemq.broker.region.MessageReference) Queue(org.apache.activemq.broker.region.Queue) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage)

Example 9 with MessageReference

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

the class StoreQueueCursorOrderTest method testNoSetBatchWithUnOrderedFutureCurrentSync.

@Test
public void testNoSetBatchWithUnOrderedFutureCurrentSync() 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[1] = 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(1L);
        }
    }, 1L) {
    };
    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[0] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.getMessageId().setFutureOrSequenceLong(1L);
    underTest.addMessageLast(msg);
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    assertEquals("setBatch unset", 0L, 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 10 with MessageReference

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

the class OrderPendingListTest method testValues.

@Test
public void testValues() throws Exception {
    OrderedPendingList list = new OrderedPendingList();
    TestMessageReference toRemove = new TestMessageReference(6);
    assertFalse(list.contains(toRemove));
    list.addMessageFirst(new TestMessageReference(1));
    list.addMessageFirst(new TestMessageReference(2));
    list.addMessageFirst(new TestMessageReference(3));
    list.addMessageFirst(new TestMessageReference(4));
    list.addMessageFirst(new TestMessageReference(5));
    Collection<MessageReference> values = list.values();
    assertEquals(5, values.size());
    for (MessageReference msg : values) {
        assertTrue(values.contains(msg));
    }
    assertFalse(values.contains(toRemove));
    list.addMessageLast(toRemove);
    values = list.values();
    assertEquals(6, values.size());
    for (MessageReference msg : values) {
        assertTrue(values.contains(msg));
    }
    assertTrue(values.contains(toRemove));
}
Also used : MessageReference(org.apache.activemq.broker.region.MessageReference) Test(org.junit.Test)

Aggregations

MessageReference (org.apache.activemq.broker.region.MessageReference)10 Test (org.junit.Test)7 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)6 Queue (org.apache.activemq.broker.region.Queue)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 FutureTask (java.util.concurrent.FutureTask)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 ArrayList (java.util.ArrayList)2 ActiveMQMessage (org.apache.activemq.command.ActiveMQMessage)2 MessageId (org.apache.activemq.command.MessageId)2 ProducerId (org.apache.activemq.command.ProducerId)2 ConnectionContext (org.apache.activemq.broker.ConnectionContext)1 MessageStore (org.apache.activemq.store.MessageStore)1 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)1