use of org.eclipse.scout.rt.testing.platform.runner.Times in project scout.rt by eclipse.
the class JmsMomImplementorTest method testQueuePublishSubscribeMultipleSubscriptions.
@Test
// regression
@Times(10)
public void testQueuePublishSubscribeMultipleSubscriptions() throws InterruptedException {
IDestination<String> queue = MOM.newDestination("test/mom/testQueuePublishSubscribeMultipleSubscriptions", DestinationType.QUEUE, ResolveMethod.DEFINE, null);
final AtomicInteger msgCounter = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(1);
// Subscribe for the destination
m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
msgCounter.incrementAndGet();
latch.countDown();
}
}));
// Subscribe for the destination
m_disposables.add(MOM.subscribe(JmsTestMom.class, queue, new IMessageListener<String>() {
@Override
public void onMessage(IMessage<String> message) {
msgCounter.incrementAndGet();
latch.countDown();
}
}));
// Publish a message
MOM.publish(JmsTestMom.class, queue, "hello world");
// Verify
latch.await(5, TimeUnit.SECONDS);
Thread.sleep(50);
assertEquals(1, msgCounter.get());
}
use of org.eclipse.scout.rt.testing.platform.runner.Times 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.testing.platform.runner.Times 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.testing.platform.runner.Times in project scout.rt by eclipse.
the class JobStateTest method testBlockedAndInterrupted.
@Test
// regression
@Times(100)
public void testBlockedAndInterrupted() throws ThreadInterruptedError, java.lang.InterruptedException {
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(captureListener);
final IExecutionSemaphore mutex = Jobs.newExecutionSemaphore(1);
final IBlockingCondition condition = Jobs.newBlockingCondition(true);
final AtomicReference<Thread> workerThread = new AtomicReference<>();
final IFuture<Void> future1 = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
workerThread.set(Thread.currentThread());
assertSame(JobState.RUNNING, IFuture.CURRENT.get().getState());
try {
condition.waitFor("ABC");
fail("interruption expected");
} catch (ThreadInterruptedError e) {
assertTrue(Thread.interrupted());
// Restore interrupted status
Thread.currentThread().interrupt();
assertTrue(mutex.isPermitOwner(IFuture.CURRENT.get()));
assertSame(JobState.RUNNING, IFuture.CURRENT.get().getState());
}
}
}, Jobs.newInput().withName("job-1").withExecutionSemaphore(mutex));
// Wait until job-1 is running
JobTestUtil.waitForState(future1, JobState.WAITING_FOR_BLOCKING_CONDITION);
// Interrupt worker thread
workerThread.get().interrupt();
future1.awaitDoneAndGet();
assertTrue(future1.isDone());
assertFalse(future1.isCancelled());
// wait because permit is released just after done (max 30s)
JobTestUtil.waitForPermitCompetitors(mutex, 0);
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future1, JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertHintChangedEvent(JobEventType.JOB_EXECUTION_HINT_ADDED, future1, "ABC", capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertBlockedStateEvent(future1, condition, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_BLOCKING_CONDITION, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
assertHintChangedEvent(JobEventType.JOB_EXECUTION_HINT_REMOVED, future1, "ABC", capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
// due to interruption
assertStateChangedEvent(future1, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
use of org.eclipse.scout.rt.testing.platform.runner.Times in project scout.rt by eclipse.
the class JobStateTest method testBlockedAndTimeout.
@Test
// regression
@Times(100)
public void testBlockedAndTimeout() throws ThreadInterruptedError, java.lang.InterruptedException {
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(captureListener);
final IExecutionSemaphore mutex = Jobs.newExecutionSemaphore(1);
final IBlockingCondition condition = Jobs.newBlockingCondition(true);
final AtomicReference<Thread> workerThread = new AtomicReference<>();
final IFuture<Void> future1 = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
workerThread.set(Thread.currentThread());
assertSame(JobState.RUNNING, IFuture.CURRENT.get().getState());
try {
condition.waitFor(1, TimeUnit.MILLISECONDS, "ABC");
fail("timeout expected");
} catch (TimedOutError e) {
assertTrue(mutex.isPermitOwner(IFuture.CURRENT.get()));
assertSame(JobState.RUNNING, IFuture.CURRENT.get().getState());
}
}
}, Jobs.newInput().withName("job-1").withExecutionSemaphore(mutex));
// Wait until job-1 completed
future1.awaitDoneAndGet(10, TimeUnit.SECONDS);
assertTrue(future1.isDone());
assertFalse(future1.isCancelled());
// wait because permit is released just after done (max 30s)
JobTestUtil.waitForPermitCompetitors(mutex, 0);
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future1, JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertHintChangedEvent(JobEventType.JOB_EXECUTION_HINT_ADDED, future1, "ABC", capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertBlockedStateEvent(future1, condition, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_BLOCKING_CONDITION, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.WAITING_FOR_PERMIT, capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
assertHintChangedEvent(JobEventType.JOB_EXECUTION_HINT_REMOVED, future1, "ABC", capturedEvents.get(i));
assertEquals(JobState.WAITING_FOR_PERMIT, capturedFutureStates.get(i));
i++;
// due to timeout
assertStateChangedEvent(future1, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future1, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
Aggregations