Java 类org.apache.hadoop.mapreduce.v2.app.webapp.AppForTest 实例源码

项目:hadoop    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:aliyun-oss-hadoop-fs    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:big-c    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:FlexMap    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:hops    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:hadoop-on-lustre2    文件:TestBlocks.java   
/**
 * test HsTasksBlock's rendering.
 */
@Test
public void testHsTasksBlock() {

  Task task = getTask(0);

  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(task.getID(), task);

  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);

  app.setJob(job);

  HsTasksBlockForTest block = new HsTasksBlockForTest(app);

  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about task
  assertTrue(data.toString().contains("task_0_0001_r_000000"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains(""));
}
项目:hadoop    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("0 attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:hadoop    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m01_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:aliyun-oss-hadoop-fs    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:aliyun-oss-hadoop-fs    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:big-c    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("0 attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:big-c    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m01_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("0 attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m01_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:FlexMap    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("0 attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:FlexMap    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m01_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:hops    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newContainerId(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records <p> \n");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertFalse(data.toString().contains("Processed 128/128 records <p> \n"));
  assertTrue(data.toString().contains("Processed 128\\/128 records &lt;p&gt; \\n"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:hops    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}
项目:hadoop-on-lustre2    文件:TestBlocks.java   
/**
 * test AttemptsBlock's rendering.
 */
@Test
public void testAttemptsBlock() {
  AppContext ctx = mock(AppContext.class);
  AppForTest app = new AppForTest(ctx);

  Task task = getTask(0);
  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);
  when(attempt.getNodeHttpAddress()).thenReturn("Node address");

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 5);
  ApplicationAttemptId appAttemptId = ApplicationAttemptIdPBImpl.newInstance(appId, 1);

  ContainerId containerId = ContainerIdPBImpl.newInstance(appAttemptId, 1);
  when(attempt.getAssignedContainerID()).thenReturn(containerId);

  when(attempt.getAssignedContainerMgrAddress()).thenReturn(
          "assignedContainerMgrAddress");
  when(attempt.getNodeRackName()).thenReturn("nodeRackName");

  final long taStartTime = 100002L;
  final long taFinishTime = 100012L;
  final long taShuffleFinishTime = 100010L;
  final long taSortFinishTime = 100011L;
  final TaskAttemptState taState = TaskAttemptState.SUCCEEDED;

  when(attempt.getLaunchTime()).thenReturn(taStartTime);
  when(attempt.getFinishTime()).thenReturn(taFinishTime);
  when(attempt.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(attempt.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(attempt.getState()).thenReturn(taState);

  TaskAttemptReport taReport = mock(TaskAttemptReport.class);
  when(taReport.getStartTime()).thenReturn(taStartTime);
  when(taReport.getFinishTime()).thenReturn(taFinishTime);
  when(taReport.getShuffleFinishTime()).thenReturn(taShuffleFinishTime);
  when(taReport.getSortFinishTime()).thenReturn(taSortFinishTime);
  when(taReport.getContainerId()).thenReturn(containerId);
  when(taReport.getProgress()).thenReturn(1.0f);
  when(taReport.getStateString()).thenReturn("Processed 128/128 records");
  when(taReport.getTaskAttemptState()).thenReturn(taState);
  when(taReport.getDiagnosticInfo()).thenReturn("");

  when(attempt.getReport()).thenReturn(taReport);

  attempts.put(taId, attempt);
  when(task.getAttempts()).thenReturn(attempts);

  app.setTask(task);
  Job job = mock(Job.class);
  when(job.getUserName()).thenReturn("User");
  app.setJob(job);

  AttemptsBlockForTest block = new AttemptsBlockForTest(app);
  block.addParameter(AMParams.TASK_TYPE, "r");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  block.render(html);
  pWriter.flush();
  // should be printed information about attempts
  assertTrue(data.toString().contains("0 attempt_0_0001_r_000000_0"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains(
          "_0005_01_000001:attempt_0_0001_r_000000_0:User:"));
  assertTrue(data.toString().contains("100002"));
  assertTrue(data.toString().contains("100010"));
  assertTrue(data.toString().contains("100011"));
  assertTrue(data.toString().contains("100012"));
}
项目:hadoop-on-lustre2    文件:TestBlocks.java   
/**
 * test HsController
 */

@Test
public void testHsController() throws Exception {
  AppContext ctx = mock(AppContext.class);
  ApplicationId appId = ApplicationIdPBImpl.newInstance(0,5);

  when(ctx.getApplicationID()).thenReturn(appId);

  AppForTest app = new AppForTest(ctx);
  Configuration config = new Configuration();
  RequestContext requestCtx = mock(RequestContext.class);
  HsControllerForTest controller = new HsControllerForTest(app, config,
          requestCtx);
  controller.index();
  assertEquals("JobHistory", controller.get(Params.TITLE, ""));
  assertEquals(HsJobPage.class, controller.jobPage());
  assertEquals(HsCountersPage.class, controller.countersPage());
  assertEquals(HsTasksPage.class, controller.tasksPage());
  assertEquals(HsTaskPage.class, controller.taskPage());
  assertEquals(HsAttemptsPage.class, controller.attemptsPage());

  controller.set(AMParams.JOB_ID, "job_01_01");
  controller.set(AMParams.TASK_ID, "task_01_01_m01_01");
  controller.set(AMParams.TASK_TYPE, "m");
  controller.set(AMParams.ATTEMPT_STATE, "State");

  Job job = mock(Job.class);
  Task task = mock(Task.class);
  when(job.getTask(any(TaskId.class))).thenReturn(task);
  JobId jobID = MRApps.toJobID("job_01_01");
  when(ctx.getJob(jobID)).thenReturn(job);
  when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class)))
          .thenReturn(true);

  controller.job();
  assertEquals(HsJobPage.class, controller.getClazz());
  controller.jobCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.taskCounters();
  assertEquals(HsCountersPage.class, controller.getClazz());
  controller.tasks();
  assertEquals(HsTasksPage.class, controller.getClazz());
  controller.task();
  assertEquals(HsTaskPage.class, controller.getClazz());
  controller.attempts();
  assertEquals(HsAttemptsPage.class, controller.getClazz());

  assertEquals(HsConfPage.class, controller.confPage());
  assertEquals(HsAboutPage.class, controller.aboutPage());
  controller.about();
  assertEquals(HsAboutPage.class, controller.getClazz());
  controller.logs();
  assertEquals(HsLogsPage.class, controller.getClazz());
  controller.nmlogs();
  assertEquals(AggregatedLogsPage.class, controller.getClazz());

  assertEquals(HsSingleCounterPage.class, controller.singleCounterPage());
  controller.singleJobCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());
  controller.singleTaskCounter();
  assertEquals(HsSingleCounterPage.class, controller.getClazz());


}