use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testErrorWithRunnable.
@Test()
public void testErrorWithRunnable() {
final Error error = new Error("expected JUnit test exception");
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
throw error;
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
try {
// test with timeout in case the error is not propagated
future.awaitDoneAndGet(5, TimeUnit.SECONDS);
fail("Exception expected");
} catch (Error e) {
assertSame(e, e);
assertTrue(future.isDone());
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testProcessingExceptionWithCallable.
@Test
public void testProcessingExceptionWithCallable() {
final ProcessingException exception = new ProcessingException("expected JUnit test exception");
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
throw exception;
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
try {
future.awaitDoneAndGet();
fail("Exception expected");
} catch (Exception e) {
assertSame(exception, e);
assertTrue(future.isDone());
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testExceptionExceptionWithCallable.
@Test
public void testExceptionExceptionWithCallable() {
final Exception exception = new Exception("expected JUnit test exception");
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
throw exception;
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
try {
future.awaitDoneAndGet();
fail("PlatformException expected");
} catch (PlatformException e) {
assertSame(exception, e.getCause());
assertTrue(future.isDone());
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testParallelExecution.
@Test
public void testParallelExecution() throws Exception {
final BlockingCountDownLatch barrier = new BlockingCountDownLatch(3);
IFuture<Void> future1 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
barrier.countDownAndBlock();
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
IFuture<Void> future2 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
barrier.countDownAndBlock();
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
IFuture<Void> future3 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
barrier.countDownAndBlock();
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
assertTrue(barrier.await());
barrier.unblock();
// wait for all jobs to complete
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future1, future2, future3).toFilter(), 10, TimeUnit.SECONDS);
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testExpired.
@Test
public void testExpired() {
final AtomicBoolean executed = new AtomicBoolean(false);
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
executed.set(true);
}
}, Jobs.newInput().withExpirationTime(500, TimeUnit.MILLISECONDS).withRunContext(RunContexts.empty()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
future.awaitDone();
assertTrue(future.isCancelled());
assertFalse(executed.get());
}
Aggregations