JobConf conf = new JobConf();
conf.setNumMapTasks(1);
conf.setNumReduceTasks(1);
conf.set(MRJobConfig.MAX_TASK_FAILURES_PER_TRACKER, "1");
conf.set(MRJobConfig.SETUP_CLEANUP_NEEDED, "false");
FakeJobInProgress job = new FakeJobInProgress(conf, jobTracker);
job.initTasks();
job.setClusterSize(4);
// Tracker 0 gets the map task
tid[0] = job.findMapTask(trackers[0]);
job.finishTask(tid[0]);
// validate the total tracker count
assertEquals("Active tracker count mismatch",
1, jobTracker.getClusterStatus(false).getTaskTrackers());
// lose the tracker
clock.advance(1100);
jobTracker.checkExpiredTrackers();
assertFalse("Tracker 0 not lost",
jobTracker.getClusterStatus(false).getActiveTrackerNames()
.contains(trackers[0]));
// validate the total tracker count
assertEquals("Active tracker count mismatch",
0, jobTracker.getClusterStatus(false).getTaskTrackers());
// Tracker 1 establishes contact with JT
FakeObjectUtilities.establishFirstContact(jobTracker, trackers[1]);
// Tracker1 should get assigned the lost map task
tid[1] = job.findMapTask(trackers[1]);
assertNotNull("Map Task from Lost Tracker did not get reassigned", tid[1]);
assertEquals("Task ID of reassigned map task does not match",
tid[0].getTaskID().toString(), tid[1].getTaskID().toString());
// finish the map task
job.finishTask(tid[1]);
// finish the reduce task
tid[2] = job.findReduceTask(trackers[1]);
job.finishTask(tid[2]);
// check if job is successful
assertEquals("Job not successful",
JobStatus.SUCCEEDED, job.getStatus().getRunState());
// check if the tracker is lost
// validate the total tracker count
assertEquals("Active tracker count mismatch",
1, jobTracker.getClusterStatus(false).getTaskTrackers());