@Test
public void testAllExpectedJobMigrationsAreFound() {

    List<Task> tasksOfJob1 = jobOperations.getTasks("job1");
    dataGenerator.place("active1", tasksOfJob1.get(0), tasksOfJob1.get(1));
    dataGenerator.place("removable1", tasksOfJob1.get(2), tasksOfJob1.get(3));
    dataGenerator.setQuota("job1", 2);
    List<Task> tasksOfJob2 = jobOperations.getTasks("job2");
    dataGenerator.place("active1", tasksOfJob2.get(0), tasksOfJob2.get(1));
    dataGenerator.place("removable1", tasksOfJob2.get(2), tasksOfJob2.get(3));
    dataGenerator.setQuota("job2", 2);
    dataGenerator.addJobAttribute("jobImmediate", RelocationAttributes.RELOCATION_REQUIRED_BY_IMMEDIATELY, "" + (clock.wallTime() + 1));
    Task taskImmediate = jobOperations.getTasks("jobImmediate").get(0);
    dataGenerator.place("active1", taskImmediate);
    List<DeschedulingResult> results = deschedulerService.deschedule(Collections.emptyMap());
    assertThat(results).hasSize(5);
    for (DeschedulingResult result : results) {
        boolean isImmediateJobMigration = result.getTask().getId().equals(taskImmediate.getId());
        if (isImmediateJobMigration) {
            assertThat(result.getAgentInstance().getServerGroupId()).isEqualTo("active1");
        } else {
            assertThat(result.getAgentInstance().getServerGroupId()).isEqualTo("removable1");
        }
        TaskRelocationPlan plan = result.getTaskRelocationPlan();
        assertThat(plan.getReason()).isEqualTo(TaskRelocationReason.TaskMigration);
        if (isImmediateJobMigration) {
            assertThat(plan.getReasonMessage()).containsSequence("Job marked for immediate eviction");
        } else {
            assertThat(plan.getReasonMessage()).containsSequence("Enough quota to migrate the task");
        }
    }
}