@Test(timeout = 120000)
public void testUpdateApplicationPriorityRequest() throws Exception {

  int maxPriority = 10;
  int appPriority = 5;
  YarnConfiguration conf = new YarnConfiguration();
  Assume.assumeFalse("FairScheduler does not support Application Priorities",
      conf.get(YarnConfiguration.RM_SCHEDULER)
          .equals(FairScheduler.class.getName()));
  conf.setInt(YarnConfiguration.MAX_CLUSTER_LEVEL_APPLICATION_PRIORITY,
      maxPriority);
  MockRM rm = new MockRM(conf);
  rm.init(conf);
  rm.start();
  rm.registerNode("host1:1234", 1024);
  // Start app1 with appPriority 5
  MockRMAppSubmissionData data = MockRMAppSubmissionData.Builder
      .createWithMemory(1024, rm)
      .withAppPriority(Priority.newInstance(appPriority))
      .build();
  RMApp app1 = MockRMAppSubmitter.submit(rm, data);
  Assert.assertEquals("Incorrect priority has been set to application",
      appPriority, app1.getApplicationPriority().getPriority());
  appPriority = 11;
  ClientRMService rmService = rm.getClientRMService();
  testApplicationPriorityUpdation(rmService, app1, appPriority, maxPriority);
  appPriority = 9;
  testApplicationPriorityUpdation(rmService, app1, appPriority, appPriority);
  rm.killApp(app1.getApplicationId());
  rm.waitForState(app1.getApplicationId(), RMAppState.KILLED);
  // Update priority request for invalid application id.
  ApplicationId invalidAppId = ApplicationId.newInstance(123456789L, 3);
  UpdateApplicationPriorityRequest updateRequest =
      UpdateApplicationPriorityRequest.newInstance(invalidAppId,
          Priority.newInstance(appPriority));
  try {
    rmService.updateApplicationPriority(updateRequest);
    Assert.fail("ApplicationNotFoundException should be thrown "
        + "for invalid application id");
  } catch (ApplicationNotFoundException e) {
    // Expected
  }
  updateRequest =
      UpdateApplicationPriorityRequest.newInstance(app1.getApplicationId(),
          Priority.newInstance(11));
  Assert.assertEquals("Incorrect priority has been set to application",
      appPriority, rmService.updateApplicationPriority(updateRequest)
          .getApplicationPriority().getPriority());
  rm.stop();
}