RebalanceTaskInfo partitionsInfo = new RebalanceTaskInfo(stealerId,
donorId,
(HashMap<String, List<Integer>>) outerMap,
zzCurrent);
StealerBasedRebalanceTask sbTask = new StealerBasedRebalanceTask(0,
0,
partitionsInfo,
donorPermit,
adminClient,
progressBar,
mockedScheduler);
sbTaskList.add(sbTask);
sbTaskList.add(sbTask);
sbTaskList.add(sbTask);
sbTaskList.add(sbTask);
sbTaskList.add(sbTask);
mockedScheduler.initializeLatch(sbTaskList.size());
mockedScheduler.populateTasksByStealer(sbTaskList);
// In the beginning both stealer and donor are idle so scheduler should
// return the scheduled
// task
StealerBasedRebalanceTask scheduledTask = mockedScheduler.scheduleNextTask(false);
org.junit.Assert.assertNotNull(sbTask);
org.junit.Assert.assertEquals(sbTask, scheduledTask);
mockedScheduler.removeNodesFromWorkerList(Arrays.asList(stealerId, donorId));
// Now lets remove the donor from the worker list so that the donor is
// idle and add the
// stealer to the worker list. The scheduler should return null as it
// won't be able to
// schedule the task.
mockedScheduler.addNodesToWorkerList(Arrays.asList(stealerId));
mockedScheduler.removeNodesFromWorkerList(Arrays.asList(donorId));
org.junit.Assert.assertEquals(mockedScheduler.scheduleNextTask(false), null);
// This time stealer doesn't have any work but donor does
mockedScheduler.addNodesToWorkerList(Arrays.asList(donorId));
mockedScheduler.removeNodesFromWorkerList(Arrays.asList(stealerId));
org.junit.Assert.assertEquals(mockedScheduler.scheduleNextTask(false), null);
// And now both stealer and donor have work to do
mockedScheduler.addNodesToWorkerList(Arrays.asList(donorId));
mockedScheduler.addNodesToWorkerList(Arrays.asList(stealerId));
org.junit.Assert.assertEquals(mockedScheduler.scheduleNextTask(false), null);
// And stealer and donor are idle again
mockedScheduler.removeNodesFromWorkerList(Arrays.asList(stealerId, donorId));
StealerBasedRebalanceTask nextscheduledTask = mockedScheduler.scheduleNextTask(false);
org.junit.Assert.assertNotNull(sbTask);
org.junit.Assert.assertEquals(sbTask, nextscheduledTask);
}