Search in sources :

Example 11 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project ignite by apache.

the class IgniteJmsStreamerTest method testTransactedSessionNoBatching.

/**
     * @throws Exception If failed.
     */
public void testTransactedSessionNoBatching() 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.setTransacted(true);
        jmsStreamer.setDestination(dest);
        // 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();
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage)

Example 12 with ActiveMQQueue

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

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

use of org.apache.activemq.command.ActiveMQQueue 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)

Example 15 with ActiveMQQueue

use of org.apache.activemq.command.ActiveMQQueue in project ignite by apache.

the class IgniteJmsStreamerTest method testGenerateNoEntries.

/**
     * @throws Exception If failed.
     */
public void testGenerateNoEntries() 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);
        // override the transformer with one that generates no cache entries
        jmsStreamer.setTransformer(TestTransformers.generateNoEntries());
        jmsStreamer.setDestination(dest);
        // subscribe to cache PUT events and return a countdown latch starting at CACHE_ENTRY_COUNT
        CountDownLatch latch = subscribeToPutEvents(1);
        jmsStreamer.start();
        // no cache PUT events were received in 3 seconds, i.e. CountDownLatch does not fire
        assertFalse(latch.await(3, TimeUnit.SECONDS));
        jmsStreamer.stop();
    }
}
Also used : Destination(javax.jms.Destination) ActiveMQQueue(org.apache.activemq.command.ActiveMQQueue) CountDownLatch(java.util.concurrent.CountDownLatch) TextMessage(javax.jms.TextMessage)

Aggregations

ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)16 Destination (javax.jms.Destination)10 CountDownLatch (java.util.concurrent.CountDownLatch)9 TextMessage (javax.jms.TextMessage)8 Test (org.junit.Test)6 ObjectMessage (javax.jms.ObjectMessage)3 DestinationStatistics (org.apache.activemq.broker.region.DestinationStatistics)3 JMSException (javax.jms.JMSException)2 Message (javax.jms.Message)2 MessageConsumer (javax.jms.MessageConsumer)2 MessageProducer (javax.jms.MessageProducer)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ActiveMQSession (org.apache.activemq.ActiveMQSession)2 Subscription (org.apache.activemq.broker.region.Subscription)2 AssertTextMessageListener (com.navercorp.pinpoint.plugin.jdk7.activemq.client.util.AssertTextMessageListener)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Session (javax.jms.Session)1 ConnectionContext (org.apache.activemq.broker.ConnectionContext)1 Destination (org.apache.activemq.broker.region.Destination)1 PolicyEntry (org.apache.activemq.broker.region.policy.PolicyEntry)1