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()); }
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); }
public void testRunStepsWithOverrunDisallowed() { StepTask t1 = task(100, 300, 100, null, new MyMockStepper(15, -10)); // t1.setOverrunAllowed(true); StepTask t2 = task(150, 250, 100, null, new MyMockStepper(10, -10)); Schedule s = sched(ListUtil.list(t1, t2)); fact.setResults(s, s); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); TimeBase.setSimulated(101); 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"); } } assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(removedTasks)); assertTrue(t1.e.toString(), t1.e instanceof SchedService.Overrun); }