CLI extends Configured implements Tool { @VisibleForTesting Job getJob(JobID jobid) throws IOException, InterruptedException { int maxRetry = getConf().getInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, MRJobConfig.DEFAULT_MR_CLIENT_JOB_MAX_RETRIES); long retryInterval = getConf() .getLong(MRJobConfig.MR_CLIENT_JOB_RETRY_INTERVAL, MRJobConfig.DEFAULT_MR_CLIENT_JOB_RETRY_INTERVAL); Job job = cluster.getJob(jobid); for (int i = 0; i < maxRetry; ++i) { if (job != null) { return job; } LOG.info("Could not obtain job info after " + String.valueOf(i + 1) + " attempt(s). Sleeping for " + String.valueOf(retryInterval / 1000) + " seconds and retrying."); Thread.sleep(retryInterval); job = cluster.getJob(jobid); } return job; } CLI();  CLI(Configuration conf); int run(String[] argv); void displayJobList(JobStatus[] jobs); @Private void displayJobList(JobStatus[] jobs, PrintWriter writer); static void main(String[] argv); @Private
  static String headerPattern; @Private
  static String dataPattern; }
@Test public void testGetJobWithoutRetry() throws Exception { Configuration conf = new Configuration(); conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, 0); final Cluster mockCluster = mock(Cluster.class); when(mockCluster.getJob(any(JobID.class))).thenReturn(null); CLI cli = new CLI(conf); cli.cluster = mockCluster; Job job = cli.getJob(JobID.forName("job_1234654654_001")); Assert.assertTrue("job is not null", job == null); }
@Test public void testGetJobWithRetry() throws Exception { Configuration conf = new Configuration(); conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, 1); final Cluster mockCluster = mock(Cluster.class); final Job mockJob = Job.getInstance(conf); when(mockCluster.getJob(any(JobID.class))).thenReturn( null).thenReturn(mockJob); CLI cli = new CLI(conf); cli.cluster = mockCluster; Job job = cli.getJob(JobID.forName("job_1234654654_001")); Assert.assertTrue("job is null", job != null); }