Search in sources :

Example 1 with IRequestListener

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

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

the class JmsMomImplementorTest method testQueueRequestReplyMultipleSubscriptions.

@Test(timeout = 200_000)
// regression
@Times(10)
public void testQueueRequestReplyMultipleSubscriptions() throws InterruptedException {
    IBiDestination<String, String> queue = MOM.newBiDestination("test/mom/testQueueRequestReplyMultipleSubscriptions", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
    final CountDownLatch msgLatch = new CountDownLatch(2);
    // Subscribe for the destination
    m_disposables.add(MOM.reply(JmsTestMom.class, queue, 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, queue, 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, queue, "hello world");
    // Verify
    assertEquals("HELLO WORLD", testee);
    assertFalse(msgLatch.await(50, TimeUnit.MILLISECONDS));
}
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) Times(org.eclipse.scout.rt.testing.platform.runner.Times)

Example 3 with IRequestListener

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

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

use of org.eclipse.scout.rt.mom.api.IRequestListener 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)5 IRequestListener (org.eclipse.scout.rt.mom.api.IRequestListener)5 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 JMSException (javax.jms.JMSException)2 NamingException (javax.naming.NamingException)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)2 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)2 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 Test (org.junit.Test)2 FinalValue (org.eclipse.scout.rt.platform.util.FinalValue)1 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)1 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)1 Times (org.eclipse.scout.rt.testing.platform.runner.Times)1