Search in sources :

Example 11 with IMessage

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

the class JmsMomImplementorTest method testQueuePublishFirst.

@Test
// regression
@Times(10)
public void testQueuePublishFirst() throws InterruptedException {
    IDestination<String> queue = MOM.newDestination("test/mom/testQueuePublishFirst", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    // Publish a message
    MOM.publish(JmsTestMom.class, queue, "hello world");
    // Subscribe for the destination
    final CountDownLatch latch = new CountDownLatch(1);
    m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<String>() {

        @Override
        public void onMessage(IMessage<String> message) {
            latch.countDown();
        }
    }));
    // Verify
    assertTrue(latch.await(200, TimeUnit.MILLISECONDS));
}
Also used : IMessage(org.eclipse.scout.rt.mom.api.IMessage) CountDownLatch(java.util.concurrent.CountDownLatch) BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) IMessageListener(org.eclipse.scout.rt.mom.api.IMessageListener) Test(org.junit.Test) Times(org.eclipse.scout.rt.testing.platform.runner.Times)

Example 12 with IMessage

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

the class JmsMomImplementorTest method testTopicRequestReplyMultipleSubscriptions.

@Test(timeout = 200_000)
public void testTopicRequestReplyMultipleSubscriptions() throws InterruptedException {
    IBiDestination<String, String> topic = MOM.newBiDestination("test/mom/testTopicRequestReplyMultipleSubscriptions", DestinationType.TOPIC, ResolveMethod.DEFINE, null);
    final CountDownLatch msgLatch = new CountDownLatch(2);
    // Subscribe for the destination
    m_disposables.add(MOM.reply(JmsTestMom.class, topic, new IRequestListener<String, String>() {

        @Override
        public String onRequest(IMessage<String> request) {
            msgLatch.countDown();
            return request.getTransferObject().toUpperCase();
        }
    }));
    // Subscribe for the destination
    m_disposables.add(MOM.reply(JmsTestMom.class, topic, new IRequestListener<String, String>() {

        @Override
        public String onRequest(IMessage<String> request) {
            msgLatch.countDown();
            return request.getTransferObject().toUpperCase();
        }
    }));
    // Initiate 'request-reply' communication
    String testee = MOM.request(JmsTestMom.class, topic, "hello world");
    // Verify
    assertEquals("HELLO WORLD", testee);
    assertTrue(msgLatch.await(5, TimeUnit.SECONDS));
}
Also used : IRequestListener(org.eclipse.scout.rt.mom.api.IRequestListener) IMessage(org.eclipse.scout.rt.mom.api.IMessage) CountDownLatch(java.util.concurrent.CountDownLatch) BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Test(org.junit.Test)

Example 13 with IMessage

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

the class JmsMomImplementorTest method testRequestReplyCancellationInternal.

private void testRequestReplyCancellationInternal(final IBiDestination<String, String> destination) throws InterruptedException {
    final CountDownLatch neverLatch = new CountDownLatch(1);
    final CountDownLatch setupLatch = new CountDownLatch(1);
    final CountDownLatch verifyLatch = new CountDownLatch(2);
    final AtomicBoolean requestorInterrupted = new AtomicBoolean();
    final AtomicBoolean replierInterrupted = new AtomicBoolean();
    final AtomicBoolean replierCancelled = new AtomicBoolean();
    // Subscribe for the destination
    m_disposables.add(MOM.reply(JmsTestMom.class, destination, new IRequestListener<String, String>() {

        @Override
        public String onRequest(IMessage<String> request) {
            setupLatch.countDown();
            try {
                neverLatch.await();
            } catch (InterruptedException e) {
                replierInterrupted.set(true);
            } finally {
                replierCancelled.set(RunMonitor.CURRENT.get().isCancelled());
                verifyLatch.countDown();
            }
            return request.getTransferObject().toUpperCase();
        }
    }));
    // Initiate 'request-reply' communication
    final FinalValue<String> testee = new FinalValue<>();
    IFuture<Void> requestFuture = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            try {
                String result = MOM.request(JmsTestMom.class, destination, "hello world");
                testee.set(result);
            } catch (ThreadInterruptedError e) {
                requestorInterrupted.set(true);
            } finally {
                verifyLatch.countDown();
            }
        }
    }, Jobs.newInput().withName("initiator").withExecutionHint(m_testJobExecutionHint));
    // Wait until reply message processing started
    setupLatch.await();
    // Cancel the publishing thread
    requestFuture.cancel(true);
    // wait for request / reply interrupted
    verifyLatch.await();
    // Verify
    assertTrue(requestorInterrupted.get());
    assertTrue(replierInterrupted.get());
    assertTrue(replierCancelled.get());
    assertFalse(testee.isSet());
}
Also used : FinalValue(org.eclipse.scout.rt.platform.util.FinalValue) IRequestListener(org.eclipse.scout.rt.mom.api.IRequestListener) IMessage(org.eclipse.scout.rt.mom.api.IMessage) ThreadInterruptedError(org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) CountDownLatch(java.util.concurrent.CountDownLatch) BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) VetoException(org.eclipse.scout.rt.platform.exception.VetoException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 14 with IMessage

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

the class JmsMomImplementorTest method testPublishTransactional.

@Test
public void testPublishTransactional() throws InterruptedException {
    final Capturer<Person> capturer = new Capturer<>();
    Person person = new Person();
    person.setLastname("smith");
    person.setFirstname("anna");
    ITransaction tx = BEANS.get(ITransaction.class);
    ITransaction.CURRENT.set(tx);
    IDestination<Person> queue = MOM.newDestination("test/mom/testPublishTransactional", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    m_disposables.add(MOM.registerMarshaller(JmsTestMom.class, queue, BEANS.get(ObjectMarshaller.class)));
    MOM.publish(JmsTestMom.class, queue, person, MOM.newPublishInput().withTransactional(true));
    m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<Person>() {

        @Override
        public void onMessage(IMessage<Person> message) {
            capturer.set(message.getTransferObject());
        }
    }));
    try {
        capturer.get(2, TimeUnit.SECONDS);
        fail();
    } catch (TimedOutError e) {
    // expected
    }
    tx.commitPhase1();
    tx.commitPhase2();
    try {
        capturer.get(5, TimeUnit.SECONDS);
    } catch (TimedOutError e) {
        fail();
    } finally {
        tx.release();
    }
    // Verify
    Person testee = capturer.get();
    assertEquals("smith", testee.getLastname());
    assertEquals("anna", testee.getFirstname());
}
Also used : ITransaction(org.eclipse.scout.rt.platform.transaction.ITransaction) IMessage(org.eclipse.scout.rt.mom.api.IMessage) TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError) IMessageListener(org.eclipse.scout.rt.mom.api.IMessageListener) Test(org.junit.Test)

Example 15 with IMessage

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

the class JmsMomImplementorTest method testRequestReplyTimeoutInternal.

private void testRequestReplyTimeoutInternal(final IBiDestination<String, String> destination) throws InterruptedException {
    final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
    final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(2);
    final AtomicBoolean requestorTimedOut = new AtomicBoolean();
    final AtomicBoolean replierInterrupted = new AtomicBoolean();
    // Subscribe for the destination
    m_disposables.add(MOM.reply(JmsTestMom.class, destination, new IRequestListener<String, String>() {

        @Override
        public String onRequest(IMessage<String> request) {
            try {
                setupLatch.countDownAndBlock();
            } catch (InterruptedException e) {
                replierInterrupted.set(true);
            } finally {
                verifyLatch.countDown();
            }
            return request.getTransferObject().toUpperCase();
        }
    }));
    // Initiate 'request-reply' communication
    try {
        MOM.request(JmsTestMom.class, destination, "hello world", MOM.newPublishInput().withRequestReplyTimeout(1, TimeUnit.SECONDS));
    } catch (TimedOutError e) {
        requestorTimedOut.set(true);
    } finally {
        verifyLatch.countDown();
    }
    assertTrue(verifyLatch.await());
    // Verify
    assertTrue(requestorTimedOut.get());
    assertTrue(replierInterrupted.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) IRequestListener(org.eclipse.scout.rt.mom.api.IRequestListener) IMessage(org.eclipse.scout.rt.mom.api.IMessage) TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)

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