@Test public void suspendSuspend() { System.out.println("suspend-suspend"); final CountDownLatch barrier1 = new CountDownLatch(1); final CountDownLatch barrier2 = new CountDownLatch(2); SchedulerTask task = new SchedulerTask() { public void onSchedule(long timeStamp) { barrier1.countDown(); barrier2.countDown(); } }; final ScheduledTask scheduled = Scheduler.sharedInstance().schedule(task, Quantum.seconds(2), false); stasks.add(scheduled); try { if (!barrier1.await(3, TimeUnit.SECONDS)) { fail(); } scheduled.suspend(); if (barrier2.await(3, TimeUnit.SECONDS)) { fail(); } scheduled.suspend(); if (barrier2.await(3, TimeUnit.SECONDS)) { fail(); } } catch (InterruptedException e) { fail(e.getMessage()); } }
@Test public void dynamicRescheduleSuspended() { System.out.println("dynamicReschedule suspended"); final CountDownLatch barrier1 = new CountDownLatch(1); final CountDownLatch barrier2 = new CountDownLatch(5); SchedulerTask task = new SchedulerTask() { public void onSchedule(long timeStamp) { System.out.println("dynamicReschedule; executing periodic task"); barrier1.countDown(); barrier2.countDown(); } }; final ScheduledTask scheduled = Scheduler.sharedInstance().schedule(task, Quantum.SUSPENDED, false); stasks.add(scheduled); try { if (barrier1.await(5, TimeUnit.SECONDS)) { fail(); } scheduled.resume(); if (barrier2.await(2, TimeUnit.SECONDS)) { fail(); } scheduled.setInterval(Quantum.seconds(1)); if (!barrier2.await(8, TimeUnit.SECONDS)) { fail(); } } catch (InterruptedException e) { fail(e.getMessage()); } }
@Test public void getRecurringHandle() { assertNotNull(recurringTestTask.getRecurringTaskHandle()); }
@Test public void setRecurringHandleOnceOnly() { RecurringTaskHandleImpl handle = new RecurringTaskHandleImpl(scheduler, recurringTestTask); assertTrue(recurringTestTask.setRecurringTaskHandle(handle)); assertFalse(recurringTestTask.setRecurringTaskHandle(handle)); }
@Test public void setRecurringHandleNonRecurringTask() { RecurringTaskHandleImpl handle = new RecurringTaskHandleImpl(scheduler, recurringTestTask); assertFalse(testTask.setRecurringTaskHandle(handle)); }
@Test public void assertIsNotRecurring() { assertFalse(testTask.isRecurring()); }
@Test public void assertIsRecurring() { assertTrue(recurringTestTask.isRecurring()); }