コード例 #1
0
  // 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());
  }
コード例 #2
0
 // 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()));
 }
コード例 #3
0
  // one task to drop, succeeds after dropping it
  public void testAddToScheduleOkAfterDrops() {
    log.debug("testAddToScheduleOkAfterDrops()");
    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 sched1 = sched(ListUtil.list(t1));
    Schedule sched2 = sched(ListUtil.list(t2));
    fact.setResults(ListUtil.list(sched1, null, null, sched2, sched2));
    TimeBase.step(101);
    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);

    assertTrue(tr.addToSchedule(t2));
    assertEquals(
        ListUtil.list(
            ListUtil.list(t1),
            ListUtil.list(t1, t2),
            ListUtil.list(t1),
            Collections.EMPTY_SET,
            ListUtil.list(t1, t2)),
        fact.createArgs);
    assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(fact.scheduler.tasks));
    assertTrue(t1.isDropped());
    assertEquals(sched2, tr.getCurrentSchedule());
    assertEquals(SetUtil.set(t1, t2), SetUtil.theSet(tr.getAcceptedTasks()));
    assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getOverrunTasks()));
    assertForegroundStat(2, TaskRunner.STAT_ACCEPTED);
    assertForegroundStat(0, TaskRunner.STAT_REFUSED);
    assertForegroundStat(1, TaskRunner.STAT_WAITING);
    assertForegroundStat(1, TaskRunner.STAT_DROPPED);

    t2.cancel();
    assertForegroundStat(2, TaskRunner.STAT_ACCEPTED);
    assertForegroundStat(0, TaskRunner.STAT_REFUSED);
    assertForegroundStat(0, TaskRunner.STAT_WAITING);
    assertForegroundStat(1, TaskRunner.STAT_DROPPED);
    assertForegroundStat(1, TaskRunner.STAT_CANCELLED);
  }
コード例 #4
0
  // one task not ready to start yet, so not droppable
  public void testAddToScheduleFailNoDroppable() {
    log.debug("testAddToScheduleOkAfterDrops()");
    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 sched1 = sched(ListUtil.list(t1));
    Schedule sched2 = sched(ListUtil.list(t2));
    fact.setResults(ListUtil.list(sched1, null, null, sched2, sched2));
    assertTrue(tr.addToSchedule(t1));
    assertIsomorphic(ListUtil.list(t1), fact.scheduler.tasks);
    assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getAcceptedTasks()));

    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));
    assertFalse(t1.isDropped());
    assertEquals(sched1, tr.getCurrentSchedule());
    assertEquals(SetUtil.set(t1), SetUtil.theSet(tr.getAcceptedTasks()));
    assertEmpty(SetUtil.theSet(tr.getOverrunTasks()));
  }
コード例 #5
0
  public void testFindTaskToRunRemovesExpiredOverrunners() {
    assertFalse(tr.findTaskToRun());
    StepTask t1 = task(100, 200, 100);
    StepTask t2 = task(100, 300, 50);
    StepTask texp1 = task(0, 0, 50);
    StepTask texp2 = task(0, 0, 49);

    Schedule s = sched(ListUtil.list(t1, t2));
    fact.setResults(s, s);
    assertTrue(tr.addToSchedule(t1));
    assertTrue(tr.addToSchedule(t2));
    tr.addOverrunner(texp1);
    tr.addOverrunner(texp2);

    // if this fails, it might be because the sorted list/set is treating
    // sort-order equivalence as object equality, which we don't want
    assertEquals(2, tr.getOverrunTasks().size());
    assertFalse(tr.findTaskToRun());
    assertEquals(0, removedChunks.size());
    assertEquals(2, removedTasks.size());
    assertEquals(
        SetUtil.set(texp1, texp2),
        SetUtil.set((StepTask) removedTasks.get(0), (StepTask) removedTasks.get(1)));
  }