Search in sources :

Example 56 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.

the class StoreQueueCursorOrderTest method testSetBatch.

@Test
public void testSetBatch() throws Exception {
    final int count = 3;
    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 * 5);
    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.getMessageId().setFutureOrSequenceLong(0L);
    underTest.addMessageLast(msg);
    msg = getMessage(1);
    messages[1] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.getMessageId().setFutureOrSequenceLong(1L);
    underTest.addMessageLast(msg);
    assertTrue("cache enabled", underTest.isUseCache() && underTest.isCacheEnabled());
    msg = getMessage(2);
    messages[2] = msg;
    msg.setMemoryUsage(systemUsage.getMemoryUsage());
    msg.getMessageId().setFutureOrSequenceLong(2L);
    underTest.addMessageLast(msg);
    assertTrue("cache is disabled as limit reached", !underTest.isCacheEnabled());
    assertEquals("setBatch set", 2L, 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) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) Queue(org.apache.activemq.broker.region.Queue) ActiveMQTextMessage(org.apache.activemq.command.ActiveMQTextMessage) Test(org.junit.Test)

Example 57 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo 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 58 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.

the class PriorityNetworkDispatchPolicyTest method testRemoveLowerPriorityDup.

@Test
public void testRemoveLowerPriorityDup() throws Exception {
    List<Subscription> consumers = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ConsumerInfo instance = info.copy();
        instance.setPriority((byte) i);
        consumers.add(new TopicSubscription(brokerService.getBroker(), context, instance, usageManager));
    }
    underTest.dispatch(node, null, consumers);
    long count = 0;
    for (Subscription consumer : consumers) {
        count += consumer.getEnqueueCounter();
    }
    assertEquals("only one sub got message", 1, count);
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) TopicSubscription(org.apache.activemq.broker.region.TopicSubscription) ArrayList(java.util.ArrayList) Subscription(org.apache.activemq.broker.region.Subscription) TopicSubscription(org.apache.activemq.broker.region.TopicSubscription) Test(org.junit.Test)

Example 59 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.

the class RecoverExpiredMessagesTest method consumeExpected.

private void consumeExpected() throws Exception {
    // Setup the consumer and receive the message.
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.send(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull("Should have received message " + expected.get(0) + " by now!", m);
    assertEquals(expected.get(0), m.getMessageId().toString());
    MessageAck ack = createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE);
    connection.send(ack);
    assertNoMessagesLeft(connection);
    connection.request(closeConnectionInfo(connectionInfo));
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Message(org.apache.activemq.command.Message) StubConnection(org.apache.activemq.broker.StubConnection) SessionInfo(org.apache.activemq.command.SessionInfo) MessageAck(org.apache.activemq.command.MessageAck) ConnectionInfo(org.apache.activemq.command.ConnectionInfo)

Example 60 with ConsumerInfo

use of org.apache.activemq.command.ConsumerInfo in project activemq-artemis by apache.

the class UdpTestSupport method testSendingSmallMessage.

public void testSendingSmallMessage() throws Exception {
    ConsumerInfo expected = new ConsumerInfo();
    expected.setSelector("Cheese");
    expected.setExclusive(true);
    expected.setExclusive(true);
    expected.setPrefetchSize(3456);
    try {
        LOG.info("About to send: " + expected);
        producer.oneway(expected);
        Command received = assertCommandReceived();
        assertTrue("Should have received a ConsumerInfo but was: " + received, received instanceof ConsumerInfo);
        ConsumerInfo actual = (ConsumerInfo) received;
        assertEquals("Selector", expected.getSelector(), actual.getSelector());
        assertEquals("isExclusive", expected.isExclusive(), actual.isExclusive());
        assertEquals("getPrefetchSize", expected.getPrefetchSize(), actual.getPrefetchSize());
    } catch (Exception e) {
        LOG.info("Caught: " + e);
        e.printStackTrace();
        fail("Failed to send to transport: " + e);
    }
}
Also used : ConsumerInfo(org.apache.activemq.command.ConsumerInfo) Command(org.apache.activemq.command.Command) IOException(java.io.IOException) MessageNotWriteableException(javax.jms.MessageNotWriteableException)

Aggregations

ConsumerInfo (org.apache.activemq.command.ConsumerInfo)115 Message (org.apache.activemq.command.Message)77 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)76 SessionInfo (org.apache.activemq.command.SessionInfo)76 ProducerInfo (org.apache.activemq.command.ProducerInfo)72 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)45 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)25 StubConnection (org.apache.activemq.broker.StubConnection)17 MessageAck (org.apache.activemq.command.MessageAck)17 XATransactionId (org.apache.activemq.command.XATransactionId)15 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)12 Test (org.junit.Test)12 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)9 TransactionInfo (org.apache.activemq.command.TransactionInfo)9 ActiveMQTextMessage (org.apache.activemq.command.ActiveMQTextMessage)8 LocalTransactionId (org.apache.activemq.command.LocalTransactionId)8 RemoveInfo (org.apache.activemq.command.RemoveInfo)8 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)7 Response (org.apache.activemq.command.Response)7 MessageReference (org.apache.activemq.broker.region.MessageReference)6