YarnJobValidationTool { public ApplicationAttemptId validateRunningAttemptId(ApplicationId appId) throws Exception { ApplicationAttemptId attemptId = this.client.getApplicationReport(appId).getCurrentApplicationAttemptId(); ApplicationAttemptReport attemptReport = this.client.getApplicationAttemptReport(attemptId); if (attemptReport.getYarnApplicationAttemptState() == YarnApplicationAttemptState.RUNNING) { log.info("Job is running. AttempId " + attemptId.toString()); return attemptId; } else { throw new SamzaException("Job not running " + this.jobName); } } YarnJobValidationTool(JobConfig config, YarnClient client, MetricsValidator validator); void run(); ApplicationId validateAppId(); ApplicationAttemptId validateRunningAttemptId(ApplicationId appId); int validateContainerCount(ApplicationAttemptId attemptId); void validateJmxMetrics(); static void main(String[] args);  }
@Test public void testValidateRunningAttemptId() throws Exception { ApplicationReport appReport = mock(ApplicationReport.class); when(client.getApplicationReport(appId)).thenReturn(appReport); when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId); ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class); when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING); when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId); when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport); assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId)); when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED); exception.expect(SamzaException.class); tool.validateRunningAttemptId(appId); }