|
@@ -20,6 +20,7 @@ package org.apache.hadoop.mapreduce.v2.app.job.impl;
|
|
|
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Mockito.doNothing;
|
|
|
+import static org.mockito.Mockito.doThrow;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
@@ -72,6 +73,37 @@ public class TestJobImpl {
|
|
|
JobState.ERROR, state);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testCommitJobFailsJob() {
|
|
|
+
|
|
|
+ JobImpl mockJob = mock(JobImpl.class);
|
|
|
+ mockJob.tasks = new HashMap<TaskId, Task>();
|
|
|
+ OutputCommitter mockCommitter = mock(OutputCommitter.class);
|
|
|
+ EventHandler mockEventHandler = mock(EventHandler.class);
|
|
|
+ JobContext mockJobContext = mock(JobContext.class);
|
|
|
+
|
|
|
+ when(mockJob.getCommitter()).thenReturn(mockCommitter);
|
|
|
+ when(mockJob.getEventHandler()).thenReturn(mockEventHandler);
|
|
|
+ when(mockJob.getJobContext()).thenReturn(mockJobContext);
|
|
|
+ doNothing().when(mockJob).setFinishTime();
|
|
|
+ doNothing().when(mockJob).logJobHistoryFinishedEvent();
|
|
|
+ when(mockJob.finished(JobState.KILLED)).thenReturn(JobState.KILLED);
|
|
|
+ when(mockJob.finished(JobState.FAILED)).thenReturn(JobState.FAILED);
|
|
|
+ when(mockJob.finished(JobState.SUCCEEDED)).thenReturn(JobState.SUCCEEDED);
|
|
|
+
|
|
|
+ try {
|
|
|
+ doThrow(new IOException()).when(mockCommitter).commitJob(any(JobContext.class));
|
|
|
+ } catch (IOException e) {
|
|
|
+ // commitJob stubbed out, so this can't happen
|
|
|
+ }
|
|
|
+ doNothing().when(mockEventHandler).handle(any(JobHistoryEvent.class));
|
|
|
+ Assert.assertNotNull("checkJobCompleteSuccess incorrectly returns null " +
|
|
|
+ "for successful job",
|
|
|
+ JobImpl.checkJobCompleteSuccess(mockJob));
|
|
|
+ Assert.assertEquals("checkJobCompleteSuccess returns incorrect state",
|
|
|
+ JobState.FAILED, JobImpl.checkJobCompleteSuccess(mockJob));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testCheckJobCompleteSuccess() {
|
|
|
|
|
@@ -98,9 +130,7 @@ public class TestJobImpl {
|
|
|
"for successful job",
|
|
|
JobImpl.checkJobCompleteSuccess(mockJob));
|
|
|
Assert.assertEquals("checkJobCompleteSuccess returns incorrect state",
|
|
|
- JobImpl.checkJobCompleteSuccess(mockJob), JobState.SUCCEEDED);
|
|
|
-
|
|
|
-
|
|
|
+ JobState.SUCCEEDED, JobImpl.checkJobCompleteSuccess(mockJob));
|
|
|
}
|
|
|
|
|
|
@Test
|