@Test
public void testForceKillApplication() throws Exception {

  YarnConfiguration conf = new YarnConfiguration();
  MockRM rm = new MockRM();
  rm.init(conf);
  rm.start();
  ClientRMService rmService = rm.getClientRMService();
  GetApplicationsRequest getRequest = GetApplicationsRequest.newInstance(
      EnumSet.of(YarnApplicationState.KILLED));
  RMApp app1 = rm.submitApp(1024);
  RMApp app2 = rm.submitApp(1024, true);
  assertEquals("Incorrect number of apps in the RM", 0,
      rmService.getApplications(getRequest).getApplicationList().size());
  KillApplicationRequest killRequest1 =
      KillApplicationRequest.newInstance(app1.getApplicationId());
  KillApplicationRequest killRequest2 =
      KillApplicationRequest.newInstance(app2.getApplicationId());
  int killAttemptCount = 0;
  for (int i = 0; i < 100; i++) {
    KillApplicationResponse killResponse1 =
        rmService.forceKillApplication(killRequest1);
    killAttemptCount++;
    if (killResponse1.getIsKillCompleted()) {
      break;
    }
    Thread.sleep(10);
  }
  assertTrue("Kill attempt count should be greater than 1 for managed AMs",
      killAttemptCount > 1);
  assertEquals("Incorrect number of apps in the RM", 1,
      rmService.getApplications(getRequest).getApplicationList().size());
  KillApplicationResponse killResponse2 =
      rmService.forceKillApplication(killRequest2);
  assertTrue("Killing UnmanagedAM should falsely acknowledge true",
      killResponse2.getIsKillCompleted());
  for (int i = 0; i < 100; i++) {
    if (2 ==
        rmService.getApplications(getRequest).getApplicationList().size()) {
      break;
    }
    Thread.sleep(10);
  }
  assertEquals("Incorrect number of apps in the RM", 2,
      rmService.getApplications(getRequest).getApplicationList().size());
}