use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.
the class JobListenerTest method testCancel.
@Test
public void testCancel() throws Exception {
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(captureListener);
final BooleanHolder hasStarted = new BooleanHolder(Boolean.FALSE);
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
hasStarted.setValue(Boolean.TRUE);
}
}, Jobs.newInput().withRunContext(RunContexts.empty()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.HOURS)));
future.cancel(true);
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter(), 10, TimeUnit.SECONDS);
Jobs.getJobManager().shutdown();
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future, JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future, JobState.PENDING, capturedEvents.get(i));
assertEquals(JobState.PENDING, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
i++;
assertJobManagerShutdownEvent(capturedEvents.get(i));
assertNull(capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.
the class JobListenerTest method testLocalListener2a.
@Test
public void testLocalListener2a() throws InterruptedException {
// Schedule job-1
IFuture<Void> future1 = Jobs.getJobManager().schedule(mock(IRunnable.class), Jobs.newInput());
future1.awaitDone();
// schedule job-2, and install listener once started running
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());
// install listener
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(Jobs.newEventFilterBuilder().andMatchFuture(future1, future2).toFilter(), captureListener);
job2RunningLatch.unblock();
future2.awaitDone();
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future2, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.
the class JobListenerTest method testLocalListener4.
@Test
public void testLocalListener4() 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(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.job.listener.JobEvent in project scout.rt by eclipse.
the class JobEventFilterBuilderTest method testFutureExclusion.
@Test
public void testFutureExclusion() {
IExecutionSemaphore mutex = Jobs.newExecutionSemaphore(1);
IFuture<?> future1 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future2 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future3 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future4 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future5 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future6 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionSemaphore(mutex).withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future7 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionSemaphore(mutex).withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future8 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionSemaphore(mutex).withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future9 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionSemaphore(mutex).withExecutionHint(JOB_IDENTIFIER));
IFuture<?> future10 = Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withExecutionSemaphore(mutex).withExecutionHint(JOB_IDENTIFIER));
// One future exclusion with no other criteria
IFilter<JobEvent> filter = Jobs.newEventFilterBuilder().andMatchNotFuture(future8).toFilter();
assertTrue(filter.accept(newJobStateChangedEvent(future1)));
assertTrue(filter.accept(newJobStateChangedEvent(future2)));
assertTrue(filter.accept(newJobStateChangedEvent(future3)));
assertTrue(filter.accept(newJobStateChangedEvent(future4)));
assertTrue(filter.accept(newJobStateChangedEvent(future5)));
assertTrue(filter.accept(newJobStateChangedEvent(future6)));
assertTrue(filter.accept(newJobStateChangedEvent(future7)));
assertFalse(filter.accept(newJobStateChangedEvent(future8)));
assertTrue(filter.accept(newJobStateChangedEvent(future9)));
assertTrue(filter.accept(newJobStateChangedEvent(future10)));
// Multiple future exclusions with no other criteria
filter = Jobs.newEventFilterBuilder().andMatchNotFuture(future8, future9).toFilter();
assertTrue(filter.accept(newJobStateChangedEvent(future1)));
assertTrue(filter.accept(newJobStateChangedEvent(future2)));
assertTrue(filter.accept(newJobStateChangedEvent(future3)));
assertTrue(filter.accept(newJobStateChangedEvent(future4)));
assertTrue(filter.accept(newJobStateChangedEvent(future5)));
assertTrue(filter.accept(newJobStateChangedEvent(future6)));
assertTrue(filter.accept(newJobStateChangedEvent(future7)));
assertFalse(filter.accept(newJobStateChangedEvent(future8)));
assertFalse(filter.accept(newJobStateChangedEvent(future9)));
assertTrue(filter.accept(newJobStateChangedEvent(future10)));
// One future exclusion with other criterion (mutex)
filter = Jobs.newEventFilterBuilder().andMatchExecutionSemaphore(mutex).andMatchNotFuture(future8).toFilter();
assertFalse(filter.accept(newJobStateChangedEvent(future1)));
assertFalse(filter.accept(newJobStateChangedEvent(future2)));
assertFalse(filter.accept(newJobStateChangedEvent(future3)));
assertFalse(filter.accept(newJobStateChangedEvent(future4)));
assertFalse(filter.accept(newJobStateChangedEvent(future5)));
assertTrue(filter.accept(newJobStateChangedEvent(future6)));
assertTrue(filter.accept(newJobStateChangedEvent(future7)));
assertFalse(filter.accept(newJobStateChangedEvent(future8)));
assertTrue(filter.accept(newJobStateChangedEvent(future9)));
assertTrue(filter.accept(newJobStateChangedEvent(future10)));
// Multiple future exclusion with other criterion (mutex)
filter = Jobs.newEventFilterBuilder().andMatchExecutionSemaphore(mutex).andMatchNotFuture(future8, future9).toFilter();
assertFalse(filter.accept(newJobStateChangedEvent(future1)));
assertFalse(filter.accept(newJobStateChangedEvent(future2)));
assertFalse(filter.accept(newJobStateChangedEvent(future3)));
assertFalse(filter.accept(newJobStateChangedEvent(future4)));
assertFalse(filter.accept(newJobStateChangedEvent(future5)));
assertTrue(filter.accept(newJobStateChangedEvent(future6)));
assertTrue(filter.accept(newJobStateChangedEvent(future7)));
assertFalse(filter.accept(newJobStateChangedEvent(future8)));
assertFalse(filter.accept(newJobStateChangedEvent(future9)));
assertTrue(filter.accept(newJobStateChangedEvent(future10)));
}
use of org.eclipse.scout.rt.platform.job.listener.JobEvent in project scout.rt by eclipse.
the class JobListenerBlockedFutureTest method testEvents.
@Test
public void testEvents() throws Exception {
JobEventCaptureListener captureListener = new JobEventCaptureListener();
Jobs.getJobManager().addListener(captureListener);
IClientSession clientSession = mock(IClientSession.class);
IFuture<Void> future = Jobs.getJobManager().schedule(new IRunnable() {
@Override
public void run() throws Exception {
// NOOP
}
}, Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(clientSession, true)));
Jobs.getJobManager().awaitDone(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter(), 1, TimeUnit.MINUTES);
Jobs.getJobManager().shutdown();
// verify events
int i = -1;
List<JobEvent> capturedEvents = captureListener.getCapturedEvents();
List<JobState> capturedFutureStates = captureListener.getCapturedFutureStates();
i++;
assertStateChangedEvent(future, JobState.SCHEDULED, capturedEvents.get(i));
assertEquals(JobState.SCHEDULED, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future, JobState.RUNNING, capturedEvents.get(i));
assertEquals(JobState.RUNNING, capturedFutureStates.get(i));
i++;
assertStateChangedEvent(future, JobState.DONE, capturedEvents.get(i));
assertEquals(JobState.DONE, capturedFutureStates.get(i));
i++;
assertJobManagerShutdownEvent(capturedEvents.get(i));
assertNull(capturedFutureStates.get(i));
assertEquals(i + 1, capturedEvents.size());
}
Aggregations