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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations