Search in sources :

Example 16 with IMessage

use of org.eclipse.scout.rt.mom.api.IMessage in project scout.rt by eclipse.

the class JmsMomImplementorTest method testConcurrentMessageConsumption.

@Test
public void testConcurrentMessageConsumption() throws InterruptedException {
    IDestination<Object> queue = MOM.newDestination("test/mom/testConcurrentMessageConsumption", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    // 1. Publish some messages
    int msgCount = 10;
    for (int i = 0; i < msgCount; i++) {
        MOM.publish(JmsTestMom.class, queue, "hello");
    }
    // 1. Publish some messages
    final BlockingCountDownLatch latch = new BlockingCountDownLatch(msgCount, 3, TimeUnit.SECONDS);
    m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<Object>() {

        @Override
        public void onMessage(IMessage<Object> message) {
            try {
                // timeout must be greater than the default latch timeout
                latch.countDownAndBlock(1, TimeUnit.MINUTES);
            } catch (InterruptedException e) {
                throw BEANS.get(DefaultRuntimeExceptionTranslator.class).translate(e);
            }
        }
    }));
    try {
        assertTrue("messages expected to be consumed concurrently", latch.await());
    } finally {
        latch.unblock();
    }
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) IMessage(org.eclipse.scout.rt.mom.api.IMessage) IMessageListener(org.eclipse.scout.rt.mom.api.IMessageListener) Test(org.junit.Test)

Aggregations

IMessage (org.eclipse.scout.rt.mom.api.IMessage)16 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)12 Test (org.junit.Test)12 IMessageListener (org.eclipse.scout.rt.mom.api.IMessageListener)11 CountDownLatch (java.util.concurrent.CountDownLatch)8 IRequestListener (org.eclipse.scout.rt.mom.api.IRequestListener)5 Times (org.eclipse.scout.rt.testing.platform.runner.Times)5 JMSException (javax.jms.JMSException)3 NamingException (javax.naming.NamingException)3 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)3 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)3 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)2 StringHolder (org.eclipse.scout.rt.platform.holders.StringHolder)1 ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)1 FinalValue (org.eclipse.scout.rt.platform.util.FinalValue)1