Beispiel #1
0
  @Test
  public void testTaskDeletedBeforeEvaluating() {
    final IScheduledTask task = makeTask(TASK_A_ID);
    expect(rateLimiter.acquire()).andReturn(0D);
    expect(taskScheduler.schedule(Tasks.id(task)))
        .andAnswer(
            new IAnswer<Boolean>() {
              @Override
              public Boolean answer() {
                // Test a corner case where a task is deleted while it is being evaluated by the
                // task
                // scheduler.  If not handled carefully, this could result in the scheduler trying
                // again
                // later to satisfy the deleted task.
                taskGroups.tasksDeleted(new TasksDeleted(ImmutableSet.of(task)));

                return false;
              }
            });
    expect(backoffStrategy.calculateBackoffMs(FIRST_SCHEDULE_DELAY.as(Time.MILLISECONDS)))
        .andReturn(0L);

    control.replay();

    taskGroups.taskChangedState(TaskStateChange.transition(makeTask(Tasks.id(task)), INIT));
    clock.advance(FIRST_SCHEDULE_DELAY);
  }
Beispiel #2
0
  @Test
  public void testResistStarvation() {
    expect(rateLimiter.acquire()).andReturn(0D).times(2);
    expect(taskScheduler.schedule("a0")).andReturn(true);
    expect(taskScheduler.schedule("b0")).andReturn(true);

    control.replay();

    taskGroups.taskChangedState(TaskStateChange.transition(makeTask(JOB_A, "a0", 0), INIT));
    taskGroups.taskChangedState(TaskStateChange.transition(makeTask(JOB_A, "a1", 1), INIT));
    taskGroups.taskChangedState(TaskStateChange.transition(makeTask(JOB_A, "a2", 2), INIT));
    taskGroups.taskChangedState(
        TaskStateChange.transition(
            makeTask(IJobKey.build(JOB_A.newBuilder().setName("jobB")), "b0", 0), INIT));

    clock.advance(FIRST_SCHEDULE_DELAY);
  }
Beispiel #3
0
  @Test
  public void testNonPendingIgnored() {
    control.replay();

    IScheduledTask task =
        IScheduledTask.build(makeTask(TASK_A_ID).newBuilder().setStatus(ASSIGNED));
    taskGroups.taskChangedState(TaskStateChange.initialized(task));
  }
Beispiel #4
0
  @Test
  public void testEvaluatedAfterFirstSchedulePenalty() {
    expect(rateLimiter.acquire()).andReturn(0D);
    expect(taskScheduler.schedule(TASK_A_ID)).andReturn(true);

    control.replay();

    taskGroups.taskChangedState(TaskStateChange.transition(makeTask(TASK_A_ID), INIT));
    clock.advance(FIRST_SCHEDULE_DELAY);
  }
Beispiel #5
0
  @Test
  public void testEvaluatedOnStartup() {
    expect(rateLimiter.acquire()).andReturn(0D);
    expect(rescheduleCalculator.getStartupScheduleDelayMs(makeTask(TASK_A_ID))).andReturn(1L);
    expect(taskScheduler.schedule(TASK_A_ID)).andReturn(true);

    control.replay();

    taskGroups.taskChangedState(TaskStateChange.initialized(makeTask(TASK_A_ID)));
    clock.advance(FIRST_SCHEDULE_DELAY);
    clock.advance(RESCHEDULE_DELAY);
  }