use of org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch in project scout.rt by eclipse.
the class FutureFinishedTest method testNotifyWaitingThreads.
@Test
public void testNotifyWaitingThreads() throws Throwable {
final String jobIdentifier = UUID.randomUUID().toString();
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
IFuture<Void> controller = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDown();
try {
Jobs.getJobManager().awaitFinished(Jobs.newFutureFilterBuilder().andMatchExecutionHint(jobIdentifier).toFilter(), 10, TimeUnit.SECONDS);
} catch (TimedOutError e) {
fail("no timeout expected");
}
}
}, Jobs.newInput());
assertTrue(setupLatch.await());
// Wait some time, so that the listener in controller is installed
SleepUtil.sleepSafe(2, TimeUnit.SECONDS);
// Run the test
IFuture<Void> future = Jobs.schedule(mock(IRunnable.class), Jobs.newInput());
// verify
// no exception expected
future.awaitFinished(10, TimeUnit.SECONDS);
// no exception expected
controller.awaitDoneAndGet(10, TimeUnit.SECONDS);
}
use of org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch in project scout.rt by eclipse.
the class JobManagerTest method testUnregisterWhenCancelledDuringExecution.
@Test
public void testUnregisterWhenCancelledDuringExecution() throws InterruptedException {
final BlockingCountDownLatch latch = new BlockingCountDownLatch(1);
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
latch.countDownAndBlock();
}
}, Jobs.newInput());
latch.await();
future.cancel(false);
latch.unblock();
future.awaitFinished(10, TimeUnit.SECONDS);
// Assert no futures left
JobManager jobManager = (JobManager) Jobs.getJobManager();
assertEquals(0, jobManager.getFutures(null).size());
}
use of org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch in project scout.rt by eclipse.
the class JobCancelTest method testCancelledWithCurrentRunContext.
@Test
public void testCancelledWithCurrentRunContext() {
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
final BlockingCountDownLatch assertLatch = new BlockingCountDownLatch(1);
final AtomicBoolean cancelled = new AtomicBoolean();
// Run test within RunContext to ensure a current RunMonitor
RunContexts.empty().run(new IRunnable() {
@Override
public void run() throws Exception {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDownAndBlock();
cancelled.set(RunMonitor.CURRENT.get().isCancelled());
assertLatch.countDown();
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
setupLatch.await();
RunMonitor.CURRENT.get().cancel(false);
setupLatch.unblock();
assertLatch.await();
assertTrue("nested cancellation expected", cancelled.get());
}
});
}
use of org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch in project scout.rt by eclipse.
the class JobCancelTest method testCancelledWithEmptyRunContextAndCurrentMonitor.
@Test
public void testCancelledWithEmptyRunContextAndCurrentMonitor() {
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
final BlockingCountDownLatch assertLatch = new BlockingCountDownLatch(1);
final AtomicBoolean cancelled = new AtomicBoolean();
// Run test within RunContext to ensure a current RunMonitor
RunContexts.empty().run(new IRunnable() {
@Override
public void run() throws Exception {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
setupLatch.countDownAndBlock();
cancelled.set(RunMonitor.CURRENT.get().isCancelled());
assertLatch.countDown();
}
}, Jobs.newInput().withRunContext(RunContexts.empty().withRunMonitor(RunMonitor.CURRENT.get())));
setupLatch.await();
RunMonitor.CURRENT.get().cancel(false);
setupLatch.unblock();
assertLatch.await();
assertTrue("no nested cancellation expected", cancelled.get());
}
});
}
use of org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch in project scout.rt by eclipse.
the class JobCancelTest method testCancelPeriodicAction.
@Test
public void testCancelPeriodicAction() throws Exception {
final AtomicInteger count = new AtomicInteger();
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
final IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
if (count.incrementAndGet() == 3) {
setupLatch.countDown();
verifyLatch.await();
}
}
}, Jobs.newInput().withRunContext(RunContexts.empty()).withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInMilliseconds(10).repeatForever())));
assertTrue(setupLatch.await());
// RUN THE TEST
future.cancel(false);
verifyLatch.countDown();
// VERIFY
assertTrue(future.isCancelled());
assertEquals(3, count.get());
future.awaitDone(10, TimeUnit.SECONDS);
assertTrue(future.isCancelled());
}
Aggregations