Java 类org.apache.hadoop.mapreduce.v2.app.job.event.TaskRecoverEvent 实例源码

项目:hadoop    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:aliyun-oss-hadoop-fs    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:big-c    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hadoop-2.6.0-cdh5.4.3    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hadoop-plus    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:FlexMap    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
    LOG.info("schedule task"+taskID.toString());
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hops    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hadoop-TCP    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hardfs    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hadoop-on-lustre2    文件:JobImpl.java   
protected void scheduleTasks(Set<TaskId> taskIDs,
    boolean recoverTaskOutput) {
  for (TaskId taskID : taskIDs) {
    TaskInfo taskInfo = completedTasksFromPreviousRun.remove(taskID);
    if (taskInfo != null) {
      eventHandler.handle(new TaskRecoverEvent(taskID, taskInfo,
          committer, recoverTaskOutput));
    } else {
      eventHandler.handle(new TaskEvent(taskID, TaskEventType.T_SCHEDULE));
    }
  }
}
项目:hadoop    文件:TaskImpl.java   
@Override
public TaskStateInternal transition(TaskImpl task, TaskEvent event) {
  TaskRecoverEvent tre = (TaskRecoverEvent) event;
  return task.recover(tre.getTaskInfo(), tre.getOutputCommitter(),
      tre.getRecoverTaskOutput());
}
项目:hadoop    文件:TestRecovery.java   
@Test
public void testRecoverySuccessAttempt() {
  LOG.info("--- START: testRecoverySuccessAttempt ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo,mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 1L);
}
项目:hadoop    文件:TestRecovery.java   
@Test
public void testRecoveryAllFailAttempts() {
  LOG.info("--- START: testRecoveryAllFailAttempts ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);

  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("FAILED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.FAILED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsFail() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);
  // check for one new attempt launched since successful attempt not found
  TaskAttemptID taId3 = new TaskAttemptID(taskID, 2000);
  finalAttemptStates.put(taId3, TaskAttemptState.NEW);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  recoveryChecker(recoverMapTask, TaskState.RUNNING, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsSucceed() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.SUCCEEDED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:hadoop    文件:TestRecovery.java   
@Test
public void testRecoveryAllAttemptsKilled() {
  LOG.info("--- START:  testRecoveryAllAttemptsKilled ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();
  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("KILLED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.KILLED);
  finalAttemptStates.put(taId2, TaskAttemptState.KILLED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.KILLED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:aliyun-oss-hadoop-fs    文件:TaskImpl.java   
@Override
public TaskStateInternal transition(TaskImpl task, TaskEvent event) {
  TaskRecoverEvent tre = (TaskRecoverEvent) event;
  return task.recover(tre.getTaskInfo(), tre.getOutputCommitter(),
      tre.getRecoverTaskOutput());
}
项目:aliyun-oss-hadoop-fs    文件:TestRecovery.java   
@Test
public void testRecoverySuccessAttempt() {
  LOG.info("--- START: testRecoverySuccessAttempt ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo,mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 1L);
}
项目:aliyun-oss-hadoop-fs    文件:TestRecovery.java   
@Test
public void testRecoveryAllFailAttempts() {
  LOG.info("--- START: testRecoveryAllFailAttempts ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);

  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("FAILED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.FAILED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:aliyun-oss-hadoop-fs    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsFail() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);
  // check for one new attempt launched since successful attempt not found
  TaskAttemptID taId3 = new TaskAttemptID(taskID, 2000);
  finalAttemptStates.put(taId3, TaskAttemptState.NEW);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  recoveryChecker(recoverMapTask, TaskState.RUNNING, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:aliyun-oss-hadoop-fs    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsSucceed() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.SUCCEEDED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:aliyun-oss-hadoop-fs    文件:TestRecovery.java   
@Test
public void testRecoveryAllAttemptsKilled() {
  LOG.info("--- START:  testRecoveryAllAttemptsKilled ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();
  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("KILLED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.KILLED);
  finalAttemptStates.put(taId2, TaskAttemptState.KILLED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.KILLED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:big-c    文件:TaskImpl.java   
@Override
public TaskStateInternal transition(TaskImpl task, TaskEvent event) {
  TaskRecoverEvent tre = (TaskRecoverEvent) event;
  return task.recover(tre.getTaskInfo(), tre.getOutputCommitter(),
      tre.getRecoverTaskOutput());
}
项目:big-c    文件:TestRecovery.java   
@Test
public void testRecoverySuccessAttempt() {
  LOG.info("--- START: testRecoverySuccessAttempt ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo,mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 1L);
}
项目:big-c    文件:TestRecovery.java   
@Test
public void testRecoveryAllFailAttempts() {
  LOG.info("--- START: testRecoveryAllFailAttempts ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);

  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("FAILED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.FAILED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:big-c    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsFail() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);
  // check for one new attempt launched since successful attempt not found
  TaskAttemptID taId3 = new TaskAttemptID(taskID, 2000);
  finalAttemptStates.put(taId3, TaskAttemptState.NEW);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  recoveryChecker(recoverMapTask, TaskState.RUNNING, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:big-c    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsSucceed() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.SUCCEEDED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:big-c    文件:TestRecovery.java   
@Test
public void testRecoveryAllAttemptsKilled() {
  LOG.info("--- START:  testRecoveryAllAttemptsKilled ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();
  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("KILLED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.KILLED);
  finalAttemptStates.put(taId2, TaskAttemptState.KILLED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.KILLED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TaskImpl.java   
@Override
public TaskStateInternal transition(TaskImpl task, TaskEvent event) {
  TaskRecoverEvent tre = (TaskRecoverEvent) event;
  return task.recover(tre.getTaskInfo(), tre.getOutputCommitter(),
      tre.getRecoverTaskOutput());
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRecovery.java   
@Test
public void testRecoverySuccessAttempt() {
  LOG.info("--- START: testRecoverySuccessAttempt ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo,mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 1L);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRecovery.java   
@Test
public void testRecoveryAllFailAttempts() {
  LOG.info("--- START: testRecoveryAllFailAttempts ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);

  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("FAILED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.FAILED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsFail() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);
  // check for one new attempt launched since successful attempt not found
  TaskAttemptID taId3 = new TaskAttemptID(taskID, 2000);
  finalAttemptStates.put(taId3, TaskAttemptState.NEW);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  recoveryChecker(recoverMapTask, TaskState.RUNNING, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsSucceed() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.SUCCEEDED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:hadoop-2.6.0-cdh5.4.3    文件:TestRecovery.java   
@Test
public void testRecoveryAllAttemptsKilled() {
  LOG.info("--- START:  testRecoveryAllAttemptsKilled ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();
  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("KILLED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.KILLED);
  finalAttemptStates.put(taId2, TaskAttemptState.KILLED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.KILLED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:hadoop-plus    文件:TaskImpl.java   
@Override
public TaskStateInternal transition(TaskImpl task, TaskEvent event) {
  TaskRecoverEvent tre = (TaskRecoverEvent) event;
  return task.recover(tre.getTaskInfo(), tre.getOutputCommitter(),
      tre.getRecoverTaskOutput());
}
项目:hadoop-plus    文件:TestRecovery.java   
@Test
public void testRecoverySuccessAttempt() {
  LOG.info("--- START: testRecoverySuccessAttempt ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo,mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 1L);
}
项目:hadoop-plus    文件:TestRecovery.java   
@Test
public void testRecoveryAllFailAttempts() {
  LOG.info("--- START: testRecoveryAllFailAttempts ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);

  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("FAILED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.FAILED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop-plus    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsFail() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.FAILED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.FAILED);
  finalAttemptStates.put(taId2, TaskAttemptState.FAILED);
  // check for one new attempt launched since successful attempt not found
  TaskAttemptID taId3 = new TaskAttemptID(taskID, 2000);
  finalAttemptStates.put(taId3, TaskAttemptState.NEW);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FAILED);
  recoveryChecker(recoverMapTask, TaskState.RUNNING, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 2L);
}
项目:hadoop-plus    文件:TestRecovery.java   
@Test
public void testRecoveryTaskSuccessAllAttemptsSucceed() {
  LOG.info("--- START:  testRecoveryTaskSuccessAllAttemptsFail ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();

  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.SUCCEEDED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("SUCCEEDED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.SUCCEEDED);
  finalAttemptStates.put(taId2, TaskAttemptState.SUCCEEDED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_FINISHED);
  jobHistoryEvents.add(EventType.TASK_FINISHED);
  recoveryChecker(recoverMapTask, TaskState.SUCCEEDED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}
项目:hadoop-plus    文件:TestRecovery.java   
@Test
public void testRecoveryAllAttemptsKilled() {
  LOG.info("--- START:  testRecoveryAllAttemptsKilled ---");

  long clusterTimestamp = System.currentTimeMillis();
  EventHandler mockEventHandler = mock(EventHandler.class);
  MapTaskImpl recoverMapTask = getMockMapTask(clusterTimestamp,
      mockEventHandler);

  TaskId taskId = recoverMapTask.getID();
  JobID jobID = new JobID(Long.toString(clusterTimestamp), 1);
  TaskID taskID = new TaskID(jobID,
      org.apache.hadoop.mapreduce.TaskType.MAP, taskId.getId());

  //Mock up the TaskAttempts
  Map<TaskAttemptID, TaskAttemptInfo> mockTaskAttempts =
      new HashMap<TaskAttemptID, TaskAttemptInfo>();
  TaskAttemptID taId1 = new TaskAttemptID(taskID, 2);
  TaskAttemptInfo mockTAinfo1 = getMockTaskAttemptInfo(taId1,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId1, mockTAinfo1);

  TaskAttemptID taId2 = new TaskAttemptID(taskID, 1);
  TaskAttemptInfo mockTAinfo2 = getMockTaskAttemptInfo(taId2,
      TaskAttemptState.KILLED);
  mockTaskAttempts.put(taId2, mockTAinfo2);

  OutputCommitter mockCommitter = mock (OutputCommitter.class);
  TaskInfo mockTaskInfo = mock(TaskInfo.class);
  when(mockTaskInfo.getTaskStatus()).thenReturn("KILLED");
  when(mockTaskInfo.getTaskId()).thenReturn(taskID);
  when(mockTaskInfo.getAllTaskAttempts()).thenReturn(mockTaskAttempts);

  recoverMapTask.handle(
      new TaskRecoverEvent(taskId, mockTaskInfo, mockCommitter, true));

  ArgumentCaptor<Event> arg = ArgumentCaptor.forClass(Event.class);
  verify(mockEventHandler,atLeast(1)).handle(
      (org.apache.hadoop.yarn.event.Event) arg.capture());

  Map<TaskAttemptID, TaskAttemptState> finalAttemptStates =
      new HashMap<TaskAttemptID, TaskAttemptState>();
  finalAttemptStates.put(taId1, TaskAttemptState.KILLED);
  finalAttemptStates.put(taId2, TaskAttemptState.KILLED);

  List<EventType> jobHistoryEvents = new ArrayList<EventType>();
  jobHistoryEvents.add(EventType.TASK_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_STARTED);
  jobHistoryEvents.add(EventType.MAP_ATTEMPT_KILLED);
  jobHistoryEvents.add(EventType.TASK_FAILED);
  recoveryChecker(recoverMapTask, TaskState.KILLED, finalAttemptStates,
      arg, jobHistoryEvents, 2L, 0L);
}