Search in sources :

Example 1 with IMessageListener

use of org.eclipse.scout.rt.mom.api.IMessageListener 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 IMessageListener

use of org.eclipse.scout.rt.mom.api.IMessageListener 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 IMessageListener

use of org.eclipse.scout.rt.mom.api.IMessageListener 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 IMessageListener

use of org.eclipse.scout.rt.mom.api.IMessageListener 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)

Example 5 with IMessageListener

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

the class JmsMomImplementorTest method testTimeToLive.

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

        @Override
        public void onMessage(IMessage<String> message) {
            latch.countDown();
        }
    }));
    // Verify
    // expect the message not to be received
    assertFalse(latch.await(50, 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)

Aggregations

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