/** * Simple test PartialJob */ @Test(timeout = 3000) public void testPartialJob() throws Exception { JobId jobId = new JobIdPBImpl(); jobId.setId(0); JobIndexInfo jii = new JobIndexInfo(0L, System.currentTimeMillis(), "user", "jobName", jobId, 3, 2, "JobStatus"); PartialJob test = new PartialJob(jii, jobId); assertEquals(1.0f, test.getProgress(), 0.001); assertNull(test.getAllCounters()); assertNull(test.getTasks()); assertNull(test.getTasks(TaskType.MAP)); assertNull(test.getTask(new TaskIdPBImpl())); assertNull(test.getTaskAttemptCompletionEvents(0, 100)); assertNull(test.getMapAttemptCompletionEvents(0, 100)); assertTrue(test.checkAccess(UserGroupInformation.getCurrentUser(), null)); assertNull(test.getAMInfos()); }
private Job getJob() { Job job = mock(Job.class); JobId jobId = new JobIdPBImpl(); ApplicationId appId = ApplicationIdPBImpl.newInstance(System.currentTimeMillis(),4); jobId.setAppId(appId); jobId.setId(1); when(job.getID()).thenReturn(jobId); JobReport report = mock(JobReport.class); when(report.getStartTime()).thenReturn(100010L); when(report.getFinishTime()).thenReturn(100015L); when(job.getReport()).thenReturn(report); when(job.getName()).thenReturn("JobName"); when(job.getUserName()).thenReturn("UserName"); when(job.getQueueName()).thenReturn("QueueName"); when(job.getState()).thenReturn(JobState.SUCCEEDED); when(job.getTotalMaps()).thenReturn(3); when(job.getCompletedMaps()).thenReturn(2); when(job.getTotalReduces()).thenReturn(2); when(job.getCompletedReduces()).thenReturn(1); when(job.getCompletedReduces()).thenReturn(1); return job; }
private Task getTask(long timestamp) { JobId jobId = new JobIdPBImpl(); jobId.setId(0); jobId.setAppId(ApplicationIdPBImpl.newInstance(timestamp,1)); TaskId taskId = new TaskIdPBImpl(); taskId.setId(0); taskId.setTaskType(TaskType.REDUCE); taskId.setJobId(jobId); Task task = mock(Task.class); when(task.getID()).thenReturn(taskId); TaskReport report = mock(TaskReport.class); when(report.getProgress()).thenReturn(0.7f); when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED); when(report.getStartTime()).thenReturn(100001L); when(report.getFinishTime()).thenReturn(100011L); when(task.getReport()).thenReturn(report); when(task.getType()).thenReturn(TaskType.REDUCE); return task; }
/** * Simple test PartialJob */ @Test(timeout = 3000) public void testPartialJob() throws Exception { JobId jobId = new JobIdPBImpl(); jobId.setId(0); JobIndexInfo jii = new JobIndexInfo(0L, System.currentTimeMillis(), "user", "jobName", jobId, 3, 2, "JobStatus"); PartialJob test = new PartialJob(jii, jobId); Assert.assertEquals(1.0f, test.getProgress(), 0.001f); assertNull(test.getAllCounters()); assertNull(test.getTasks()); assertNull(test.getTasks(TaskType.MAP)); assertNull(test.getTask(new TaskIdPBImpl())); assertNull(test.getTaskAttemptCompletionEvents(0, 100)); assertNull(test.getMapAttemptCompletionEvents(0, 100)); assertTrue(test.checkAccess(UserGroupInformation.getCurrentUser(), null)); assertNull(test.getAMInfos()); }
/** * Simple test PartialJob */ @Test(timeout = 1000) public void testPartialJob() throws Exception { JobId jobId = new JobIdPBImpl(); jobId.setId(0); JobIndexInfo jii = new JobIndexInfo(0L, System.currentTimeMillis(), "user", "jobName", jobId, 3, 2, "JobStatus"); PartialJob test = new PartialJob(jii, jobId); assertEquals(1.0f, test.getProgress(), 0.001); assertNull(test.getAllCounters()); assertNull(test.getTasks()); assertNull(test.getTasks(TaskType.MAP)); assertNull(test.getTask(new TaskIdPBImpl())); assertNull(test.getTaskAttemptCompletionEvents(0, 100)); assertNull(test.getMapAttemptCompletionEvents(0, 100)); assertTrue(test.checkAccess(UserGroupInformation.getCurrentUser(), null)); assertNull(test.getAMInfos()); }
/** * Test rendering for TasksBlock */ @Test public void testTasksBlock() throws Exception { ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 1); JobId jobId = new JobIdPBImpl(); jobId.setId(0); jobId.setAppId(appId); TaskId taskId = new TaskIdPBImpl(); taskId.setId(0); taskId.setTaskType(TaskType.MAP); taskId.setJobId(jobId); Task task = mock(Task.class); when(task.getID()).thenReturn(taskId); TaskReport report = mock(TaskReport.class); when(report.getProgress()).thenReturn(0.7f); when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED); when(report.getStartTime()).thenReturn(100001L); when(report.getFinishTime()).thenReturn(100011L); when(report.getStatus()).thenReturn("Dummy Status \n*"); when(task.getReport()).thenReturn(report); when(task.getType()).thenReturn(TaskType.MAP); Map<TaskId, Task> tasks = new HashMap<TaskId, Task>(); tasks.put(taskId, task); AppContext ctx = mock(AppContext.class); Job job = mock(Job.class); when(job.getTasks()).thenReturn(tasks); App app = new App(ctx); app.setJob(job); TasksBlockForTest taskBlock = new TasksBlockForTest(app); taskBlock.addParameter(AMParams.TASK_TYPE, "m"); PrintWriter pWriter = new PrintWriter(data); Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false); taskBlock.render(html); pWriter.flush(); assertTrue(data.toString().contains("task_0_0001_m_000000")); assertTrue(data.toString().contains("70.00")); assertTrue(data.toString().contains("SUCCEEDED")); assertTrue(data.toString().contains("100001")); assertTrue(data.toString().contains("100011")); assertFalse(data.toString().contains("Dummy Status \n*")); assertTrue(data.toString().contains("Dummy Status \\n*")); }
private JobIdPBImpl convertFromProtoFormat(JobIdProto p) { return new JobIdPBImpl(p); }
private JobIdProto convertToProtoFormat(JobId t) { return ((JobIdPBImpl)t).getProto(); }
private static JobId createJobId(int id) { JobId jobId = new JobIdPBImpl(); jobId.setId(id); jobId.setAppId(ApplicationIdPBImpl.newInstance(0, id)); return jobId; }
/** * test AttemptsBlock's rendering. */ @Test public void testAttemptsBlock() { AppContext ctx = mock(AppContext.class); AppForTest app = new AppForTest(ctx); JobId jobId = new JobIdPBImpl(); jobId.setId(0); jobId.setAppId(ApplicationIdPBImpl.newInstance(0,1)); TaskId taskId = new TaskIdPBImpl(); taskId.setId(0); taskId.setTaskType(TaskType.REDUCE); taskId.setJobId(jobId); Task task = mock(Task.class); when(task.getID()).thenReturn(taskId); TaskReport report = mock(TaskReport.class); when(task.getReport()).thenReturn(report); when(task.getType()).thenReturn(TaskType.REDUCE); Map<TaskId, Task> tasks = new HashMap<TaskId, Task>(); Map<TaskAttemptId, TaskAttempt> attempts = new HashMap<TaskAttemptId, TaskAttempt>(); TaskAttempt attempt = mock(TaskAttempt.class); TaskAttemptId taId = new TaskAttemptIdPBImpl(); taId.setId(0); taId.setTaskId(task.getID()); when(attempt.getID()).thenReturn(taId); final TaskAttemptState taState = TaskAttemptState.SUCCEEDED; when(attempt.getState()).thenReturn(taState); TaskAttemptReport taReport = mock(TaskAttemptReport.class); when(taReport.getTaskAttemptState()).thenReturn(taState); when(attempt.getReport()).thenReturn(taReport); attempts.put(taId, attempt); tasks.put(taskId, task); when(task.getAttempts()).thenReturn(attempts); app.setTask(task); Job job = mock(Job.class); when(job.getTasks(TaskType.REDUCE)).thenReturn(tasks); app.setJob(job); AttemptsBlockForTest block = new AttemptsBlockForTest(app, new Configuration()); block.addParameter(AMParams.TASK_TYPE, "r"); block.addParameter(AMParams.ATTEMPT_STATE, "SUCCESSFUL"); PrintWriter pWriter = new PrintWriter(data); Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false); block.render(html); pWriter.flush(); assertTrue(data.toString().contains( "<a href='" + block.url("task",task.getID().toString()) +"'>" +"attempt_0_0001_r_000000_0</a>")); }