Search in sources :

Example 1 with IMessage

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

the class JmsMomImplementorTest method testTopicPublishFirst.

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

        @Override
        public void onMessage(IMessage<String> message) {
            latch.countDown();
        }
    }));
    // Verify
    assertFalse(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 2 with IMessage

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

the class JmsMomImplementorTest method testMomEnvironmentWithCustomDefaultMarshaller.

@Test
public void testMomEnvironmentWithCustomDefaultMarshaller() throws InterruptedException {
    installTestMom(JmsTestMomWithTextMarshaller.class);
    final Capturer<String> capturer1 = new Capturer<>();
    final Capturer<Object> capturer2 = new Capturer<>();
    IDestination<String> queueString = MOM.newDestination("test/mom/testPublishStringData", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    IDestination<Object> queueObject = MOM.newDestination("test/mom/testPublishObjectData", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    m_disposables.add(MOM.registerMarshaller(JmsTestMom.class, queueObject, BEANS.get(ObjectMarshaller.class)));
    MOM.publish(JmsTestMom.class, queueString, "Hello MOM!");
    MOM.publish(JmsTestMom.class, queueObject, new StringHolder("Hello MOM! (holder)"));
    m_disposables.add(MOM.subscribe(JmsTestMom.class, queueString, new IMessageListener<String>() {

        @Override
        public void onMessage(IMessage<String> message) {
            capturer1.set(message.getTransferObject());
        }
    }));
    m_disposables.add(MOM.subscribe(JmsTestMom.class, queueObject, new IMessageListener<Object>() {

        @Override
        public void onMessage(IMessage<Object> message) {
            capturer2.set(message.getTransferObject());
        }
    }));
    // Verify
    String received1 = capturer1.get();
    Object received2 = capturer2.get();
    assertEquals("Hello MOM!", received1);
    assertEquals("Hello MOM! (holder)", Objects.toString(received2));
}
Also used : StringHolder(org.eclipse.scout.rt.platform.holders.StringHolder) IMessage(org.eclipse.scout.rt.mom.api.IMessage) IMessageListener(org.eclipse.scout.rt.mom.api.IMessageListener) Test(org.junit.Test)

Example 3 with IMessage

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

the class JmsMomImplementorTest method testPublishSubscribeCorrelationIdInternal.

private void testPublishSubscribeCorrelationIdInternal(final IDestination<String> destination) throws InterruptedException {
    final Capturer<String> cid = new Capturer<>();
    m_disposables.add(MOM.subscribe(JmsTestMom.class, destination, new IMessageListener<String>() {

        @Override
        public void onMessage(IMessage<String> message) {
            cid.set(CorrelationId.CURRENT.get());
        }
    }, MOM.newSubscribeInput().withRunContext(RunContexts.copyCurrent().withCorrelationId("cid:xyz"))));
    RunContexts.copyCurrent().withCorrelationId("cid:abc").run(new IRunnable() {

        @Override
        public void run() throws Exception {
            MOM.publish(JmsTestMom.class, destination, "hello world");
        }
    });
    assertEquals("cid:abc", cid.get());
}
Also used : IMessage(org.eclipse.scout.rt.mom.api.IMessage) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IMessageListener(org.eclipse.scout.rt.mom.api.IMessageListener) 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)

Example 4 with IMessage

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

the class JmsMomImplementorTest method testRequestReplyCorrelationIdInternal.

private void testRequestReplyCorrelationIdInternal(final IBiDestination<String, String> destination) throws InterruptedException {
    m_disposables.add(MOM.reply(JmsTestMom.class, destination, new IRequestListener<String, String>() {

        @Override
        public String onRequest(IMessage<String> request) {
            return CorrelationId.CURRENT.get();
        }
    }, MOM.newSubscribeInput().withRunContext(RunContexts.copyCurrent().withCorrelationId("cid:xyz"))));
    // Initiate 'request-reply' communication
    RunContexts.empty().withCorrelationId("cid:abc").run(new IRunnable() {

        @Override
        public void run() throws Exception {
            String testee = MOM.request(JmsTestMom.class, destination, "hello world");
            // Verify
            assertEquals("cid:abc", testee);
        }
    });
}
Also used : IRequestListener(org.eclipse.scout.rt.mom.api.IRequestListener) IMessage(org.eclipse.scout.rt.mom.api.IMessage) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) 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)

Example 5 with IMessage

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

the class JmsMomImplementorTest method testTopicPublishSubscribeMultipleSubscriptions.

@Test
public void testTopicPublishSubscribeMultipleSubscriptions() throws InterruptedException {
    IDestination<String> topic = MOM.newDestination("test/mom/testTopicPublishSubscribeMultipleSubscriptions", DestinationType.TOPIC, ResolveMethod.DEFINE, null);
    final CountDownLatch latch = new CountDownLatch(2);
    // Subscribe for the destination
    m_disposables.add(MOM.subscribe(JmsTestMom.class, topic, new IMessageListener<String>() {

        @Override
        public void onMessage(IMessage<String> message) {
            latch.countDown();
        }
    }));
    // Subscribe for the destination
    m_disposables.add(MOM.subscribe(JmsTestMom.class, topic, new IMessageListener<String>() {

        @Override
        public void onMessage(IMessage<String> message) {
            latch.countDown();
        }
    }));
    // Publish a message
    MOM.publish(JmsTestMom.class, topic, "hello world");
    // Verify
    assertTrue(latch.await(5, TimeUnit.SECONDS));
}
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)

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