scheduler.getNextTask();
assertEquals(0, scheduler.runnableTasks());
scheduler.submitTaskReservations(createTaskReservationRequest(1, scheduler, user2), address2);
assertEquals(1, scheduler.runnableTasks());
TaskSpec user2Task = scheduler.getNextTask();
assertEquals(0, scheduler.runnableTasks());
scheduler.submitTaskReservations(createTaskReservationRequest(1, scheduler, user3), address3);
assertEquals(1, scheduler.runnableTasks());
scheduler.getNextTask();
assertEquals(0, scheduler.runnableTasks());
scheduler.submitTaskReservations(createTaskReservationRequest(1, scheduler, user4), address4);
assertEquals(1, scheduler.runnableTasks());
scheduler.getNextTask();
assertEquals(0, scheduler.runnableTasks());
/* Create the following backlogs.
* user1: 2 tasks
* user2: 3 tasks
* user3: 4 tasks
*/
scheduler.submitTaskReservations(
createTaskReservationRequest(2, scheduler, user1), address1);
scheduler.submitTaskReservations(
createTaskReservationRequest(1, scheduler, user2), address2);
scheduler.submitTaskReservations(
createTaskReservationRequest(1, scheduler, user2), address2);
scheduler.submitTaskReservations(
createTaskReservationRequest(1, scheduler, user2), address2);
scheduler.submitTaskReservations(
createTaskReservationRequest(4, scheduler, user3), address3);
assertEquals(0, scheduler.runnableTasks());
// If the getTask() for user 2 fails, the scheduler should try to get another task
// for that user rather than using the usual round-robin ordering.
scheduler.noTaskForReservation(user2Task);
assertEquals(1, scheduler.runnableTasks());
user2Task = scheduler.getNextTask();
assertEquals(user2, user2Task.user.user);
assertEquals("6", user2Task.requestId);
assertEquals(0, scheduler.runnableTasks());
// The scheduler should resume round-robin from user 1 (and not start the round-robin
// again after user 2).
TFullTaskId fullTaskId = new TFullTaskId();
fullTaskId.taskId = "";
List<TFullTaskId> completedTasks = Lists.newArrayList();
completedTasks.add(fullTaskId);
fullTaskId.requestId = "1";
scheduler.tasksFinished(completedTasks);
assertEquals(1, scheduler.runnableTasks());
TaskSpec task = scheduler.getNextTask();
assertEquals(user1, task.user.user);
assertEquals("5", task.requestId);
assertEquals(0, scheduler.runnableTasks());
// If the scheduler eventually exhausts the queue of tasks for user 2, and cannot launch any,