Search in sources :

Example 1 with DestinationStatistics

use of org.apache.activemq.broker.region.DestinationStatistics in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueMessagesConsumedInBatchesCompletionSizeBased.

/**
     * @throws Exception If failed.
     */
public void testQueueMessagesConsumedInBatchesCompletionSizeBased() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce multiple messages into the queue
    produceStringMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<TextMessage, String, String> jmsStreamer = newJmsStreamer(TextMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        jmsStreamer.setBatched(true);
        jmsStreamer.setBatchClosureSize(99);
        // disable time-based session commits
        jmsStreamer.setBatchClosureMillis(0);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        jmsStreamer.start();
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        // we expect all entries to be loaded, but still one (uncommitted) message should remain in the queue
        // as observed by the broker
        DestinationStatistics qStats = broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics();
        assertEquals(1, qStats.getMessages().getCount());
        assertEquals(1, qStats.getInflight().getCount());
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage)

Example 2 with DestinationStatistics

use of org.apache.activemq.broker.region.DestinationStatistics in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueMessagesConsumedInBatchesCompletionTimeBased.

/**
     * @throws Exception If failed.
     */
public void testQueueMessagesConsumedInBatchesCompletionTimeBased() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce multiple messages into the queue
    produceStringMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<TextMessage, String, String> jmsStreamer = newJmsStreamer(TextMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        jmsStreamer.setBatched(true);
        jmsStreamer.setBatchClosureMillis(2000);
        // disable size-based session commits
        jmsStreamer.setBatchClosureSize(0);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        DestinationStatistics qStats = broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics();
        jmsStreamer.start();
        // all messages are still inflight
        assertEquals(CACHE_ENTRY_COUNT, qStats.getMessages().getCount());
        assertEquals(0, qStats.getDequeues().getCount());
        // wait a little bit
        Thread.sleep(100);
        // all messages are still inflight
        assertEquals(CACHE_ENTRY_COUNT, qStats.getMessages().getCount());
        assertEquals(0, qStats.getDequeues().getCount());
        // now let the scheduler execute
        Thread.sleep(2100);
        // all messages are committed
        assertEquals(0, qStats.getMessages().getCount());
        assertEquals(CACHE_ENTRY_COUNT, qStats.getDequeues().getCount());
        latch.await(5, TimeUnit.SECONDS);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage)

Example 3 with DestinationStatistics

use of org.apache.activemq.broker.region.DestinationStatistics in project ignite by apache.

the class IgniteJmsStreamerTest method testQueueMultipleThreads.

/**
     * @throws Exception If failed.
     */
public void testQueueMultipleThreads() throws Exception {
    Destination dest = new ActiveMQQueue(QUEUE_NAME);
    // produce messages into the queue
    produceObjectMessages(dest, false);
    try (IgniteDataStreamer<String, String> dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME)) {
        JmsStreamer<ObjectMessage, String, String> jmsStreamer = newJmsStreamer(ObjectMessage.class, dataStreamer);
        jmsStreamer.setDestination(dest);
        jmsStreamer.setThreads(5);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(CACHE_ENTRY_COUNT);
        // start the streamer
        jmsStreamer.start();
        DestinationStatistics qStats = broker.getBroker().getDestinationMap().get(dest).getDestinationStatistics();
        assertEquals(5, qStats.getConsumers().getCount());
        // all cache PUT events received in 10 seconds
        latch.await(10, TimeUnit.SECONDS);
        // assert that all consumers received messages - given that the prefetch is 1
        for (Subscription subscription : broker.getBroker().getDestinationMap().get(dest).getConsumers()) assertTrue(subscription.getDequeueCounter() > 0);
        assertAllCacheEntriesLoaded();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) DestinationStatistics(org.apache.activemq.broker.region.DestinationStatistics) ObjectMessage(javax.jms.ObjectMessage) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(org.apache.activemq.broker.region.Subscription)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)3 Destination (javax.jms.Destination)3 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)3 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)3 TextMessage (javax.jms.TextMessage)2 ObjectMessage (javax.jms.ObjectMessage)1 Subscription (org.apache.activemq.broker.region.Subscription)1