@Test public void testJobToString() throws IOException, InterruptedException { Cluster cluster = mock(Cluster.class); ClientProtocol client = mock(ClientProtocol.class); when(cluster.getClient()).thenReturn(client); JobID jobid = new JobID("1014873536921", 6); JobStatus status = new JobStatus(jobid, 0.0f, 0.0f, 0.0f, 0.0f, State.FAILED, JobPriority.DEFAULT, "root", "TestJobToString", "job file", "tracking url"); when(client.getJobStatus(jobid)).thenReturn(status); when(client.getTaskReports(jobid, TaskType.MAP)).thenReturn( new TaskReport[0]); when(client.getTaskReports(jobid, TaskType.REDUCE)).thenReturn( new TaskReport[0]); when(client.getTaskCompletionEvents(jobid, 0, 10)).thenReturn( new TaskCompletionEvent[0]); Job job = Job.getInstance(cluster, status, new JobConf()); Assert.assertNotNull(job.toString()); }
@Test public void testUnexpectedJobStatus() throws Exception { Cluster cluster = mock(Cluster.class); JobID jobid = new JobID("1014873536921", 6); ClientProtocol clientProtocol = mock(ClientProtocol.class); when(cluster.getClient()).thenReturn(clientProtocol); JobStatus status = new JobStatus(jobid, 0f, 0f, 0f, 0f, State.RUNNING, JobPriority.DEFAULT, "root", "testUnexpectedJobStatus", "job file", "tracking URL"); when(clientProtocol.getJobStatus(jobid)).thenReturn(status); Job job = Job.getInstance(cluster, status, new JobConf()); // ensurer job status is RUNNING Assert.assertNotNull(job.getStatus()); Assert.assertTrue(job.getStatus().getState() == State.RUNNING); // when updating job status, job client could not retrieve // job status, and status reset to null when(clientProtocol.getJobStatus(jobid)).thenReturn(null); try { job.updateStatus(); } catch (IOException e) { Assert.assertTrue(e != null && e.getMessage().contains("Job status not available")); } try { ControlledJob cj = new ControlledJob(job, null); Assert.assertNotNull(cj.toString()); } catch (NullPointerException e) { Assert.fail("job API fails with NPE"); } }
when(clientProtocol.getJobStatus(any(JobID.class))).thenReturn(jobStatus_1, jobStatus_2);
/** * Get job corresponding to jobid. * * @param jobId * @return object of {@link Job} * @throws IOException * @throws InterruptedException */ public Job getJob(JobID jobId) throws IOException, InterruptedException { JobStatus status = client.getJobStatus(jobId); if (status != null) { return new Job(this, status, new JobConf(status.getJobFile())); } return null; }
/** Some methods need to update status immediately. So, refresh * immediately * @throws IOException */ synchronized void updateStatus() throws IOException, InterruptedException { this.status = cluster.getClient().getJobStatus(status.getJobID()); if (this.status == null) { throw new IOException("Job status not available "); } this.statustime = System.currentTimeMillis(); }
/** * Get job corresponding to jobid. * * @param jobId * @return object of {@link Job} * @throws IOException * @throws InterruptedException */ public Job getJob(JobID jobId) throws IOException, InterruptedException { JobStatus status = client.getJobStatus(jobId); if (status != null) { JobConf conf; try { conf = new JobConf(status.getJobFile()); } catch (RuntimeException ex) { // If job file doesn't exist it means we can't find the job if (ex.getCause() instanceof FileNotFoundException) { return null; } else { throw ex; } } return Job.getInstance(this, status, conf); } return null; }
/** * Get job corresponding to jobid. * * @param jobId * @return object of {@link Job} * @throws IOException * @throws InterruptedException */ public Job getJob(JobID jobId) throws IOException, InterruptedException { JobStatus status = client.getJobStatus(jobId); if (status != null) { JobConf conf; try { conf = new JobConf(status.getJobFile()); } catch (RuntimeException ex) { // If job file doesn't exist it means we can't find the job if (ex.getCause() instanceof FileNotFoundException) { return null; } else { throw ex; } } return Job.getInstance(this, status, conf); } return null; }
/** * Get job corresponding to jobid. * * @param jobId * @return object of {@link Job} * @throws IOException * @throws InterruptedException */ public Job getJob(JobID jobId) throws IOException, InterruptedException { JobStatus status = client.getJobStatus(jobId); if (status != null) { JobConf conf; try { conf = new JobConf(status.getJobFile()); } catch (RuntimeException ex) { // If job file doesn't exist it means we can't find the job if (ex.getCause() instanceof FileNotFoundException) { return null; } else { throw ex; } } return Job.getInstance(this, status, conf); } return null; }
/** * Get job corresponding to jobid. * * @param jobId * @return object of {@link Job} * @throws IOException * @throws InterruptedException */ public Job getJob(JobID jobId) throws IOException, InterruptedException { JobStatus status = client.getJobStatus(jobId); if (status != null) { JobConf conf; try { conf = new JobConf(status.getJobFile()); } catch (RuntimeException ex) { // If job file doesn't exist it means we can't find the job if (ex.getCause() instanceof FileNotFoundException) { return null; } else { throw ex; } } return Job.getInstance(this, status, conf); } return null; }
@Override public JobStatus run() throws IOException, InterruptedException { return cluster.getClient().getJobStatus(status.getJobID()); } });
@Override public JobStatus run() throws IOException, InterruptedException { return cluster.getClient().getJobStatus(status.getJobID()); } });
@Override public JobStatus run() throws IOException, InterruptedException { return cluster.getClient().getJobStatus(status.getJobID()); } });
@Override public JobStatus run() throws IOException, InterruptedException { return cluster.getClient().getJobStatus(status.getJobID()); } });