List<InetSocketAddress> nodes = Lists.newArrayList(requests.keySet());
assertEquals(nodes.size(), expectedReservations);
Collections.shuffle(nodes);
Set<String> taskIdsCopy = Sets.newHashSet(taskIds);
for (int j = 0; j < expectedReservations; ++j) {
THostPort hostPort = new THostPort(nodes.get(j).getHostName(), nodes.get(j).getPort());
List<TTaskLaunchSpec> specs = taskPlacer.assignTask(hostPort);
assertTrue(specs != null);
if (j < NUM_TASKS) {
assertEquals(specs.size(), 1);
TTaskLaunchSpec spec = specs.get(0);
assertTrue("Expect to receive a task spec for task " + j + " at " +
hostPort.getHost() + ":" + hostPort.getPort(), spec != null);
assertTrue("Expect list of unlaunched tasks to contain " + spec.getTaskId(),
taskIdsCopy.contains(spec.getTaskId()));
taskIdsCopy.remove(spec.getTaskId());
} else {
assertEquals(specs.size(), 0);