@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); }
@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); }
@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); }