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