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);
}
});
}
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));
}
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));
}
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());
}
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());
}
Aggregations