Search in sources :

Example 21 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class SimpleDispatchPolicyTest method assertOneConsumerReceivedAllMessages.

public void assertOneConsumerReceivedAllMessages(int messageCount) throws Exception {
    boolean found = false;
    for (Iterator<MessageConsumer> i = consumers.keySet().iterator(); i.hasNext(); ) {
        MessageIdList messageIdList = consumers.get(i.next());
        int count = messageIdList.getMessageCount();
        if (count > 0) {
            if (found) {
                fail("No other consumers should have received any messages");
            } else {
                assertEquals("Consumer should have received all messages.", messageCount, count);
                found = true;
            }
        }
    }
    if (!found) {
        fail("At least one consumer should have received all messages");
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 22 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class StrictOrderDispatchPolicyTest method assertReceivedMessagesAreOrdered.

public void assertReceivedMessagesAreOrdered() throws Exception {
    // If there is only one consumer, messages is definitely ordered
    if (consumers.size() <= 1) {
        return;
    }
    // Get basis of order
    Iterator<MessageConsumer> i = consumers.keySet().iterator();
    MessageIdList messageOrder = consumers.get(i.next());
    for (; i.hasNext(); ) {
        MessageIdList messageIdList = consumers.get(i.next());
        assertTrue("Messages are not ordered.", messageOrder.equals(messageIdList));
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 23 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class AbortSlowConsumer0Test method testAbortAlreadyClosingConsumers.

@Test
public void testAbortAlreadyClosingConsumers() throws Exception {
    consumerCount = 1;
    startConsumers(withPrefetch(2, destination));
    for (MessageIdList list : consumers.values()) {
        list.setProcessingDelay(6 * 1000);
    }
    for (Connection c : connections) {
        c.setExceptionListener(this);
    }
    startProducers(destination, 100);
    allMessagesList.waitForMessagesToArrive(consumerCount);
    for (MessageConsumer consumer : consumers.keySet()) {
        LOG.info("closing consumer: " + consumer);
        // / will block waiting for on message till 6secs expire
        consumer.close();
    }
}
Also used : ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) MessageIdList(org.apache.activemq.util.MessageIdList) Test(org.junit.Test)

Example 24 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class MultiBrokersMultiClientsTest method testQueueAllConnected.

public void testQueueAllConnected() throws Exception {
    bridgeAllBrokers();
    startAllBrokers();
    this.waitForBridgeFormation();
    // Setup topic destination
    Destination dest = createDestination("TEST.FOO", false);
    CountDownLatch latch = new CountDownLatch(BROKER_COUNT * PRODUCER_COUNT * MESSAGE_COUNT);
    // Setup consumers
    for (int i = 1; i <= BROKER_COUNT; i++) {
        for (int j = 0; j < CONSUMER_COUNT; j++) {
            consumerMap.put("Consumer:" + i + ":" + j, createConsumer("Broker" + i, dest, latch));
        }
    }
    // wait for consumers to get propagated
    for (int i = 1; i <= BROKER_COUNT; i++) {
        // all consumers on the remote brokers look like 1 consumer to the local broker.
        assertConsumersConnect("Broker" + i, dest, (BROKER_COUNT - 1) + CONSUMER_COUNT, 65000);
    }
    // Send messages
    for (int i = 1; i <= BROKER_COUNT; i++) {
        for (int j = 0; j < PRODUCER_COUNT; j++) {
            sendMessages("Broker" + i, dest, MESSAGE_COUNT);
        }
    }
    // Wait for messages to be delivered
    assertTrue("Missing " + latch.getCount() + " messages", latch.await(45, TimeUnit.SECONDS));
    // Get message count
    int totalMsg = 0;
    for (int i = 1; i <= BROKER_COUNT; i++) {
        for (int j = 0; j < CONSUMER_COUNT; j++) {
            MessageIdList msgs = getConsumerMessages("Broker" + i, consumerMap.get("Consumer:" + i + ":" + j));
            totalMsg += msgs.getMessageCount();
        }
    }
    assertEquals(BROKER_COUNT * PRODUCER_COUNT * MESSAGE_COUNT, totalMsg);
    assertNoUnhandeledExceptions();
}
Also used : Destination(javax.jms.Destination) CountDownLatch(java.util.concurrent.CountDownLatch) MessageIdList(org.apache.activemq.util.MessageIdList)

Example 25 with MessageIdList

use of org.apache.activemq.util.MessageIdList in project activemq-artemis by apache.

the class AbstractTwoBrokerNetworkConnectorWildcardIncludedDestinationTestSupport method sendReceive.

public void sendReceive(String broker1, String dest1, boolean topic1, String broker2, String dest2, boolean topic2, int send, int expected) throws Exception {
    MessageConsumer client = createConsumer(broker2, createDestination(dest2, topic2));
    Thread.sleep(2000);
    sendMessages(broker1, createDestination(dest1, topic1), send);
    MessageIdList msgs = getConsumerMessages(broker2, client);
    msgs.setMaximumDuration(10000);
    msgs.waitForMessagesToArrive(send);
    assertEquals(expected, msgs.getMessageCount());
    client.close();
    Thread.sleep(1000);
}
Also used : MessageConsumer(javax.jms.MessageConsumer) MessageIdList(org.apache.activemq.util.MessageIdList)

Aggregations

MessageIdList (org.apache.activemq.util.MessageIdList)63 MessageConsumer (javax.jms.MessageConsumer)58 Destination (javax.jms.Destination)34 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)31 CountDownLatch (java.util.concurrent.CountDownLatch)8 Connection (javax.jms.Connection)6 VirtualDestination (org.apache.activemq.broker.region.virtual.VirtualDestination)5 Test (org.junit.Test)5 URI (java.net.URI)4 BrokerService (org.apache.activemq.broker.BrokerService)4 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)4 NetworkConnector (org.apache.activemq.network.NetworkConnector)4 HashMap (java.util.HashMap)3 Session (javax.jms.Session)3 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)3 TestSupport.getDestination (org.apache.activemq.TestSupport.getDestination)3 Destination (org.apache.activemq.broker.region.Destination)3 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)3 PolicyMap (org.apache.activemq.broker.region.policy.PolicyMap)3 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)3