use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testScheduleJobWithCancelledRunMonitor.
@Test
public void testScheduleJobWithCancelledRunMonitor() {
// setup run context with already cancelled run monitor
RunContext runContext = RunContexts.empty();
runContext.getRunMonitor().cancel(true);
// schedule job
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
fail("job must not be executed");
}
}, Jobs.newInput().withRunContext(runContext));
future.awaitDone();
assertTrue(future.isCancelled());
// future must not be referenced by job manager
assertEquals(0, Jobs.getJobManager().getFutures(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter()).size());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testExpireNever.
@Test
public void testExpireNever() {
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().withRunContext(RunContexts.empty()).withExpirationTime(JobInput.EXPIRE_NEVER, TimeUnit.MILLISECONDS).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
future.awaitDoneAndGet();
assertTrue(executed.get());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testExceptionExceptionWithRunnable.
@Test
public void testExceptionExceptionWithRunnable() {
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 testWithRunnable.
@Test
public void testWithRunnable() {
// synchronized because modified/read by different threads.
final Set<String> protocol = Collections.synchronizedSet(new HashSet<String>());
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
protocol.add("running");
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
// VERIFY
assertNull(future.awaitDoneAndGet());
assertEquals(CollectionUtility.hashSet("running"), protocol);
assertTrue(future.isDone());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobScheduleTest method testRuntimeExceptionWithRunnable.
@Test
public void testRuntimeExceptionWithRunnable() {
final RuntimeException exception = new RuntimeException("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 (RuntimeException e) {
assertSame(exception, e);
assertTrue(future.isDone());
}
}
Aggregations