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 testGetJob() throws Exception { Configuration conf = new Configuration(); long sleepTime = 100; conf.setLong(MRJobConfig.MR_CLIENT_JOB_RETRY_INTERVAL, sleepTime); Cluster mockCluster = mock(Cluster.class); JobID jobId1 = JobID.forName("job_1234654654_001"); when(mockCluster.getJob(jobId1)).thenReturn(null); for (int i = 0; i < 2; ++i) { conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, i); CLI cli = spy(new CLI(conf)); cli.cluster = mockCluster; doReturn(mockCluster).when(cli).createCluster(); long start = Time.monotonicNow(); cli.getJob(jobId1); long end = Time.monotonicNow(); Assert.assertTrue(end - start > (i * sleepTime)); Assert.assertTrue(end - start < ((i + 1) * sleepTime)); } }