RemoteAppChecker extends AppChecker { @Override @Private public boolean isApplicationActive(ApplicationId id) throws YarnException { ApplicationReport report = null; try { report = client.getApplicationReport(id); } catch (ApplicationNotFoundException e) { return false; } catch (IOException e) { throw new YarnException(e); } if (report == null) { return false; } return ACTIVE_STATES.contains(report.getYarnApplicationState()); } RemoteAppChecker();   RemoteAppChecker(YarnClient client); @Override @Private boolean isApplicationActive(ApplicationId id); @Override @Private Collection<ApplicationId> getActiveApplications();  }
@Test public void testNonExistentApp() throws Exception { YarnClient client = createCheckerWithMockedClient(); ApplicationId id = ApplicationId.newInstance(1, 1); doReturn(null).when(client).getApplicationReport(id); assertFalse(checker.isApplicationActive(id)); doThrow(new ApplicationNotFoundException("Throw!")).when(client) .getApplicationReport(id); assertFalse(checker.isApplicationActive(id)); }
@Test public void testRunningApp() throws Exception { YarnClient client = createCheckerWithMockedClient(); ApplicationId id = ApplicationId.newInstance(1, 1); ApplicationReport report = new ApplicationReportPBImpl(); report.setYarnApplicationState(YarnApplicationState.ACCEPTED); doReturn(report).when(client).getApplicationReport(id); assertTrue(checker.isApplicationActive(id)); }