public void testIsTaskSchedulable() { fact.setResult(null); StepTask t1 = task(100, 200, 50); assertFalse(tr.isTaskSchedulable(t1)); fact.setResult(sched(ListUtil.list(t1))); assertTrue(tr.isTaskSchedulable(t1)); }
public void testStepperThrows() { final List finished = new ArrayList(); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { if (event == Schedule.EventType.FINISH) { finished.add(task); } } }; MyMockStepper stepper = new MyMockStepper(10, -10); stepper.setWhenToThrow(5); StepTask t1 = task(100, 200, 100, cb, stepper); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); TimeBase.setSimulated(101); assertTrue(tr.findTaskToRun()); Interrupter intr = null; try { intr = interruptMeIn(TIMEOUT_SHOULDNT, true); tr.runSteps(new MutableBoolean(true), null); intr.cancel(); } catch (Exception e) { log.error("runSteps threw:", e); } finally { if (intr.did()) { fail("runSteps looped"); } } assertSame(t1, finished.get(0)); assertTrue(t1.e instanceof ExpectedRuntimeException); assertEquals(5, stepper.nSteps); }
// remove overrunnable task-ending chunk, before deadline, public void testRemoveChunkTaskEndOver() { final List finished = new ArrayList(); StepTask t1 = task( 100, 200, 100, new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { if (log.isDebug2()) { log.debug2("testRemoveChunkTaskEndOver callback"); } if (event == Schedule.EventType.FINISH) { finished.add(task); } } }); t1.setOverrunAllowed(true); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); Schedule.Chunk chunk = (Schedule.Chunk) s.getEvents().get(0); assertTrue(tr.getCurrentSchedule().getEvents().contains(chunk)); chunk.setTaskEnd(); tr.removeChunk(chunk); assertFalse(tr.getCurrentSchedule().getEvents().contains(chunk)); assertEmpty(finished); assertIsomorphic(ListUtil.list(t1), tr.getAcceptedTasks()); assertIsomorphic(SetUtil.set(t1), tr.getOverrunTasks()); }
// remove task-ending chunk, past task deadline, s.b. Timeout error. public void testRemoveChunkTaskEndTimeout() { final List finished = new ArrayList(); StepTask t1 = task( 100, 200, 100, new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { if (log.isDebug2()) { log.debug2("testRemoveChunkTaskEndTimeout callback"); } if (event == Schedule.EventType.FINISH) { finished.add(task); } } }); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); Schedule.Chunk chunk = (Schedule.Chunk) s.getEvents().get(0); assertTrue(tr.getCurrentSchedule().getEvents().contains(chunk)); chunk.setTaskEnd(); TimeBase.setSimulated(201); tr.removeChunk(chunk); assertFalse(tr.getCurrentSchedule().getEvents().contains(chunk)); assertSame(t1, finished.get(0)); assertNotNull(t1.e); assertTrue(t1.e.toString(), t1.e instanceof SchedService.Timeout); assertEmpty(tr.getAcceptedTasks()); }
// one task to drop, two failed schedule tries public void testAddToScheduleFailNoCleanup() { ConfigurationUtil.addFromArgs( TaskRunner.PARAM_DROP_TASK_MAX, "10", TaskRunner.PARAM_MIN_CLEANUP_INTERVAL, "0"); StepTask t1 = task(100, 200, 50); StepTask t2 = task(100, 200, 100); Schedule sched = sched(ListUtil.list(t1)); fact.setResult(sched); assertTrue(tr.addToSchedule(t1)); assertIsomorphic(ListUtil.list(t1), fact.scheduler.tasks); assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getAcceptedTasks())); assertForegroundStat(1, TaskRunner.STAT_ACCEPTED); assertForegroundStat(0, TaskRunner.STAT_REFUSED); assertForegroundStat(1, TaskRunner.STAT_WAITING); assertForegroundStat(0, TaskRunner.STAT_DROPPED); assertFalse(tr.addToSchedule(t2)); assertEquals( ListUtil.list(ListUtil.list(t1), ListUtil.list(t1, t2), ListUtil.list(t1)), fact.createArgs); assertEquals(SetUtil.set(t1), SetUtil.theSet(fact.scheduler.tasks)); assertEquals(sched, tr.getCurrentSchedule()); assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getAcceptedTasks())); assertForegroundStat(1, TaskRunner.STAT_ACCEPTED); assertForegroundStat(1, TaskRunner.STAT_REFUSED); assertForegroundStat(1, TaskRunner.STAT_WAITING); assertForegroundStat(0, TaskRunner.STAT_DROPPED); }
// ensure addToSchedule returns false if (Mock)Scheduler returns false public void testAddToScheduleFail() { fact.setResult(null); StepTask t1 = task(100, 200, 50); assertFalse(tr.addToSchedule(t1)); assertEmpty(tr.getAcceptedTasks()); assertForegroundStat(0, TaskRunner.STAT_ACCEPTED); assertForegroundStat(1, TaskRunner.STAT_REFUSED); }
// ensure addToSchedule updates structures if (Mock)Scheduler returns true public void testAddToScheduleOk() { StepTask t1 = task(100, 200, 50); StepTask t2 = task(100, 200, 100); Schedule sched = sched(ListUtil.list(t1, t2)); fact.setResult(sched); assertTrue(tr.addToSchedule(t1)); assertIsomorphic(ListUtil.list(t1), fact.scheduler.tasks); assertForegroundStat(1, TaskRunner.STAT_ACCEPTED); assertForegroundStat(0, TaskRunner.STAT_REFUSED); fact.setResult(sched); assertTrue(tr.addToSchedule(t2)); assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(fact.scheduler.tasks)); assertEquals(sched, tr.getCurrentSchedule()); assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(tr.getAcceptedTasks())); assertForegroundStat(2, TaskRunner.STAT_ACCEPTED); assertForegroundStat(2, TaskRunner.STAT_WAITING); assertForegroundStat(0, TaskRunner.STAT_REFUSED); }
// only one try, because no tasks to drop public void testAddToScheduleFailNothingToDrop() { ConfigurationUtil.addFromArgs(TaskRunner.PARAM_DROP_TASK_MAX, "2"); fact.setResult(null); StepTask t1 = task(100, 200, 50); assertFalse(tr.addToSchedule(t1)); assertEmpty(tr.getAcceptedTasks()); assertEquals(1, fact.createArgs.size()); assertForegroundStat(1, TaskRunner.STAT_REFUSED); assertForegroundStat(0, TaskRunner.STAT_WAITING); assertForegroundStat(0, TaskRunner.STAT_DROPPED); }
public void testRemoveChunk() { StepTask t1 = task(100, 200, 100); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); assertIsomorphic(ListUtil.list(t1), tr.getAcceptedTasks()); Schedule.Chunk chunk = (Schedule.Chunk) s.getEvents().get(0); assertTrue(tr.getCurrentSchedule().getEvents().contains(chunk)); tr.removeChunk(chunk); assertFalse(tr.getCurrentSchedule().getEvents().contains(chunk)); }
public void testFindOverrunTaskToRun() { assertFalse(tr.findTaskToRun()); StepTask t1 = task(100, 200, 100); Schedule s = sched(ListUtil.list(t1)); fact.setResult(s); assertTrue(tr.addToSchedule(t1)); assertFalse(tr.findTaskToRun()); assertEquals(Deadline.at(100), tr.runningDeadline); StepTask t2 = task(0, 300, 50); tr.addOverrunner(t2); assertTrue(tr.findTaskToRun()); assertEquals(t2, tr.runningTask); assertEquals(Deadline.at(100), tr.runningDeadline); assertNull(tr.runningChunk); }