use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobExceptionTranslationTest method testWithExplicitExceptionTranslator.
@Test
public void testWithExplicitExceptionTranslator() {
final Exception error = new Exception("expected JUnit test exception");
IFuture<Void> future = Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
throw error;
}
}, Jobs.newInput());
try {
future.awaitDoneAndGet(DefaultExceptionTranslator.class);
fail("Exception expected");
} catch (Exception e) {
assertSame(error, e);
}
try {
future.awaitDoneAndGet(DefaultRuntimeExceptionTranslator.class);
fail("PlatformException expected");
} catch (PlatformException e) {
assertSame(error, e.getCause());
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobListenerTest method testLocalListener5.
@Test
public void testLocalListener5() throws InterruptedException {
final BlockingCountDownLatch jobRunningLatch = new BlockingCountDownLatch(1);
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
jobRunningLatch.countDownAndBlock();
}
}, Jobs.newInput());
assertTrue(jobRunningLatch.await());
JobEventCaptureListener captureListener = new JobEventCaptureListener();
future.addListener(Jobs.newEventFilterBuilder().andMatchEventType(JobEventType.JOB_STATE_CHANGED).andMatchState(JobState.DONE).toFilter(), captureListener);
jobRunningLatch.unblock();
future.awaitDone();
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobListenerTest method testLocalListener3.
@Test
public void testLocalListener3() throws InterruptedException {
IFuture<Void> future1 = Jobs.getJobManager().schedule(mock(IRunnable.class), Jobs.newInput());
future1.awaitDone();
final BlockingCountDownLatch job2RunningLatch = new BlockingCountDownLatch(1);
IFuture<Void> future2 = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
job2RunningLatch.countDownAndBlock();
}
}, Jobs.newInput());
assertTrue(job2RunningLatch.await());
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(Jobs.newEventFilterBuilder().andMatchNotFuture(future2).toFilter(), captureListener);
job2RunningLatch.unblock();
future2.awaitDone();
// verify events
assertTrue(captureListener.getCapturedEvents().isEmpty());
assertTrue(captureListener.getCapturedFutureStates().isEmpty());
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobManagerLoadTest method testDelayedExecuting.
@Test(timeout = 20_000)
public void testDelayedExecuting() {
IFilter<IFuture<?>> filter = Jobs.newFutureFilterBuilder().andMatchExecutionHint(JOB_IDENTIFIER).toFilter();
Date startDate = new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3));
final AtomicLong counter = new AtomicLong();
for (int i = 0; i < JOB_COUNT; i++) {
Jobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
counter.incrementAndGet();
}
}, Jobs.newInput().withExecutionHint(JOB_IDENTIFIER).withExecutionTrigger(Jobs.newExecutionTrigger().withStartAt(startDate)));
}
try {
Jobs.getJobManager().awaitDone(filter, 10, TimeUnit.SECONDS);
assertEquals(JOB_COUNT, counter.get());
} catch (TimedOutError e) {
Jobs.getJobManager().cancel(filter, true);
fail("Scheduling 25'000 took longer than 10s");
}
}
use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.
the class JobManagerTest method testShutdown.
@Test
public void testShutdown() throws Exception {
// synchronized because modified/read by different threads.
final Set<String> protocol = Collections.synchronizedSet(new HashSet<String>());
final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(3);
final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(3);
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-1");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-2");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
try {
setupLatch.countDownAndBlock();
} catch (InterruptedException e) {
protocol.add("interrupted-3");
} finally {
verifyLatch.countDown();
}
}
}, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExceptionHandling(null, false));
assertTrue(setupLatch.await());
// RUN THE TEST
Jobs.getJobManager().shutdown();
// VERIFY
assertTrue(verifyLatch.await());
assertEquals(CollectionUtility.hashSet("interrupted-1", "interrupted-2", "interrupted-3"), protocol);
try {
Jobs.schedule(mock(IRunnable.class), Jobs.newInput());
fail("AssertionError expected");
} catch (AssertionException e) {
// NOOP
}
}
Aggregations