@Test
public void testPendingResourceUpdatedAccordingToIncreaseRequestChanges()
    throws Exception {

  Configuration conf =
      TestUtils.getConfigurationWithQueueLabels(new Configuration(false));
  conf.setBoolean(YarnConfiguration.NODE_LABELS_ENABLED, true);
  final RMNodeLabelsManager mgr = new NullRMNodeLabelsManager();
  mgr.init(conf);
  MockRM rm = new MockRM(conf) {
    protected RMNodeLabelsManager createNodeLabelManager() {
      return mgr;
    }
  };
  rm.start();
  MockNM nm1 = // label = ""
      new MockNM("h1:1234", 200 * GB, rm.getResourceTrackerService());
  nm1.registerNode();
  // Launch app1 in queue=a1
  MockRMAppSubmissionData data =
      MockRMAppSubmissionData.Builder.createWithMemory(1 * GB, rm)
          .withAppName("app")
          .withUser("user")
          .withAcls(null)
          .withQueue("a1")
          .withUnmanagedAM(false)
          .build();
  RMApp app1 = MockRMAppSubmitter.submit(rm, data);
  MockAM am1 = MockRM.launchAndRegisterAM(app1, rm, nm1);
  // Allocate two more containers
  am1.allocate(
      Arrays.asList(ResourceRequest.newInstance(Priority.newInstance(1),
          "*", Resources.createResource(2 * GB), 2)),
      null);
  ContainerId containerId1 =
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 1);
  ContainerId containerId2 =
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 2);
  ContainerId containerId3 =
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 3);
  Assert.assertTrue(rm.waitForState(nm1, containerId3,
      RMContainerState.ALLOCATED));
  // Acquire them
  am1.allocate(null, null);
  sentRMContainerLaunched(rm,
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 1L));
  sentRMContainerLaunched(rm,
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 2L));
  sentRMContainerLaunched(rm,
      ContainerId.newContainerId(am1.getApplicationAttemptId(), 3L));
  // am1 asks to change its AM container from 1GB to 3GB
  am1.sendContainerResizingRequest(Arrays.asList(
          UpdateContainerRequest
              .newInstance(0, containerId1,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(3 * GB), null)));
  FiCaSchedulerApp app = getFiCaSchedulerApp(rm, app1.getApplicationId());
  Assert.assertEquals(2 * GB,
      app.getAppAttemptResourceUsage().getPending().getMemorySize());
  checkPendingResource(rm, "a1", 2 * GB, null);
  checkPendingResource(rm, "a", 2 * GB, null);
  checkPendingResource(rm, "root", 2 * GB, null);
  // am1 asks to change containerId2 (2G -> 3G) and containerId3 (2G -> 5G)
  am1.sendContainerResizingRequest(Arrays.asList(
      UpdateContainerRequest
              .newInstance(0, containerId2,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(3 * GB), null),
      UpdateContainerRequest
              .newInstance(0, containerId3,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(5 * GB), null)));
  Assert.assertEquals(6 * GB,
      app.getAppAttemptResourceUsage().getPending().getMemorySize());
  checkPendingResource(rm, "a1", 6 * GB, null);
  checkPendingResource(rm, "a", 6 * GB, null);
  checkPendingResource(rm, "root", 6 * GB, null);
  // am1 asks to change containerId1 (1G->3G), containerId2 (2G -> 4G) and
  // containerId3 (2G -> 2G)
  am1.sendContainerResizingRequest(Arrays.asList(
      UpdateContainerRequest
              .newInstance(0, containerId1,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(3 * GB), null),
      UpdateContainerRequest
              .newInstance(0, containerId2,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(4 * GB), null),
      UpdateContainerRequest
              .newInstance(0, containerId3,
                  ContainerUpdateType.INCREASE_RESOURCE,
                  Resources.createResource(2 * GB), null)));
  Assert.assertEquals(4 * GB,
      app.getAppAttemptResourceUsage().getPending().getMemorySize());
  checkPendingResource(rm, "a1", 4 * GB, null);
  checkPendingResource(rm, "a", 4 * GB, null);
  checkPendingResource(rm, "root", 4 * GB, null);
}