public void testRunStepsWithOverrunAllowed() { StepTask t1 = task(100, 500, 30, null, new MyMockStepper(15, -10)); t1.setOverrunAllowed(true); StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10)); newTr( new MyMockTaskRunner( new TaskRunner.SchedulerFactory() { public Scheduler createScheduler() { return new SortScheduler(); } })); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); TimeBase.setSimulated(101); assertTrue(tr.findTaskToRun()); Interrupter intr = null; try { intr = interruptMeIn(TIMEOUT_SHOULDNT, true); while (tr.findTaskToRun()) { tr.runSteps(new MutableBoolean(true), null); } intr.cancel(); } catch (Exception e) { log.error("runSteps threw:", e); } finally { if (intr.did()) { fail("runSteps looped"); } } assertNull(t1.e); assertTrue(t1.hasOverrun()); }
// 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()); }
// test resched with overrun task doesn't lose task. public void testRunStepsWithOverrunAllowedPlusResched() { StepTask t1 = task(100, 500, 30, null, new MyMockStepper(15, -10)); t1.setOverrunAllowed(true); StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10)); newTr( new MyMockTaskRunner( new TaskRunner.SchedulerFactory() { public Scheduler createScheduler() { return new SortScheduler(); } })); assertTrue(tr.addToSchedule(t1)); assertEmpty(tr.getOverrunTasks()); TimeBase.setSimulated(101); assertTrue(tr.findTaskToRun()); t1.timeUsed = 1000; assertTrue(t1.hasOverrun()); assertEmpty(tr.getOverrunTasks()); assertTrue(tr.addToSchedule(t2)); assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getOverrunTasks())); }