public boolean equals(Object obj) { if (obj instanceof BERec) { BERec o = (BERec) obj; return when.equals(o.when) && task.equals(o.task) && event == o.event; } return false; }
// make a BackgroundEvent for the task Schedule.BackgroundEvent bEvent(BackgroundTask task, Schedule.EventType event) { return new Schedule.BackgroundEvent( task, (event == Schedule.EventType.START ? task.getStart() : task.getFinish()), event); }
public void testBackground() { final List rec = new ArrayList(); TaskCallback cb = new TaskCallback() { public void taskEvent(SchedulableTask task, Schedule.EventType event) { rec.add(new BERec(Deadline.in(0), (BackgroundTask) task, event)); } }; assertFalse(tr.findTaskToRun()); BackgroundTask t1 = btask(100, 200, .1, cb); BackgroundTask t2 = btask(100, 300, .2, cb); BackgroundTask t3 = btask(150, 200, .4, cb); Schedule s = sched( ListUtil.list( bEvent(t1, Schedule.EventType.START), bEvent(t2, Schedule.EventType.START), bEvent(t3, Schedule.EventType.START), bEvent(t1, Schedule.EventType.FINISH), bEvent(t3, Schedule.EventType.FINISH), bEvent(t2, Schedule.EventType.FINISH))); fact.setResults(ListUtil.list(s, s, s)); assertTrue(tr.addToSchedule(t1)); assertTrue(tr.addToSchedule(t2)); assertTrue(tr.addToSchedule(t3)); assertEquals(3, tr.getAcceptedTasks().size()); assertIsomorphic(ListUtil.list(t1, t2, t3), tr.getAcceptedTasks()); assertFalse(tr.findTaskToRun()); assertEquals(0, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(Deadline.at(100), tr.runningDeadline); TimeBase.setSimulated(101); assertFalse(tr.findTaskToRun()); assertEquals(2, rec.size()); assertEquals(.3, tr.getBackgroundLoadFactor(), .005); TimeBase.setSimulated(151); assertFalse(tr.findTaskToRun()); assertEquals(3, rec.size()); assertEquals(.7, tr.getBackgroundLoadFactor(), .005); assertEquals(3, tr.getAcceptedTasks().size()); TimeBase.setSimulated(201); assertFalse(tr.findTaskToRun()); assertEquals(5, rec.size()); assertEquals(.2, tr.getBackgroundLoadFactor(), .005); assertEquals(1, tr.getAcceptedTasks().size()); t2.taskIsFinished(); TimeBase.setSimulated(202); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); assertEquals(0, tr.getAcceptedTasks().size()); TimeBase.setSimulated(301); assertFalse(tr.findTaskToRun()); assertEquals(6, rec.size()); assertEquals(0, tr.getBackgroundLoadFactor(), .005); List exp = ListUtil.list( new BERec(101, t1, Schedule.EventType.START), new BERec(101, t2, Schedule.EventType.START), new BERec(151, t3, Schedule.EventType.START), new BERec(201, t1, Schedule.EventType.FINISH), new BERec(201, t3, Schedule.EventType.FINISH), new BERec(201, t2, Schedule.EventType.FINISH)); assertEquals(exp, rec); }