@Test
public void testRackAntiAffinityAssignment()
    throws InvalidAllocationTagsQueryException {

  AllocationTagsManager tm = new AllocationTagsManager(rmContext);
  PlacementConstraintManagerService pcm =
      new MemoryPlacementConstraintManager();
  // Register App1 with anti-affinity constraint map
  pcm.registerApplication(appId1, constraintMap2);
  /**
   * Place container:
   * Node0:123 (Rack1):
   *    container_app1_1 (hbase-rs)
   */
  RMNode n0_r1 = rmNodes.get(0);
  RMNode n1_r1 = rmNodes.get(1);
  RMNode n2_r2 = rmNodes.get(2);
  RMNode n3_r2 = rmNodes.get(3);
  // 1 Containers on Node0-Rack1 with allocationTag 'hbase-rs'
  ContainerId hbase_m = ContainerId
      .newContainerId(ApplicationAttemptId.newInstance(appId1, 0), 0);
  tm.addContainer(n0_r1.getNodeID(), hbase_m, ImmutableSet.of("hbase-rs"));
  SchedulerNode schedulerNode0 =newSchedulerNode(n0_r1.getHostName(),
      n0_r1.getRackName(), n0_r1.getNodeID());
  SchedulerNode schedulerNode1 =newSchedulerNode(n1_r1.getHostName(),
      n1_r1.getRackName(), n1_r1.getNodeID());
  SchedulerNode schedulerNode2 =newSchedulerNode(n2_r2.getHostName(),
      n2_r2.getRackName(), n2_r2.getNodeID());
  SchedulerNode schedulerNode3 =newSchedulerNode(n3_r2.getHostName(),
      n3_r2.getRackName(), n3_r2.getNodeID());
  // 'zk' placement on Rack1 should FAIL
  Assert.assertFalse(PlacementConstraintsUtil.canSatisfyConstraints(appId1,
      createSchedulingRequest(sourceTag2), schedulerNode0, pcm, tm));
  Assert.assertFalse(PlacementConstraintsUtil.canSatisfyConstraints(appId1,
      createSchedulingRequest(sourceTag2), schedulerNode1, pcm, tm));
  // SUCCEED on the rest of the RACKs
  Assert.assertTrue(PlacementConstraintsUtil.canSatisfyConstraints(appId1,
      createSchedulingRequest(sourceTag2), schedulerNode2, pcm, tm));
  Assert.assertTrue(PlacementConstraintsUtil.canSatisfyConstraints(appId1,
      createSchedulingRequest(sourceTag2), schedulerNode3, pcm, tm));
}