JobConf conf = new JobConf();
conf.setSpeculativeExecution(true);
conf.setNumMapTasks(3);
conf.setNumReduceTasks(3);
conf.setFloat(JobContext.SPECULATIVE_SLOWTASK_THRESHOLD, 0.5f);
FakeJobInProgress job = new FakeJobInProgress(conf, jobTracker);
job.initTasks();
//Check for runningMap counts first
//schedule maps
taskAttemptID[0] = job.findMapTask(trackers[0]);
taskAttemptID[1] = job.findMapTask(trackers[1]);
taskAttemptID[2] = job.findMapTask(trackers[2]);
clock.advance(5000);
job.finishTask(taskAttemptID[0]);
clock.advance(1000);
job.finishTask(taskAttemptID[1]);
clock.advanceBySpeculativeLag();
//we should get a speculative task now
taskAttemptID[3] = job.findMapTask(trackers[3]);
int oldRunningMap = job.runningMaps();
LOG.info("No of running maps before fail was " + oldRunningMap);
job.failTask(taskAttemptID[2]);
assertEquals(
"Running maps count should be updated from " + oldRunningMap + " to " +
(oldRunningMap - 1), job.runningMaps(), oldRunningMap - 1);
LOG.info(" Job running maps after fail " + job.runningMaps());
clock.advance(5000);
job.finishTask(taskAttemptID[3]);
//check for runningReduce count.
taskAttemptID[4] = job.findReduceTask(trackers[0]);
taskAttemptID[5] = job.findReduceTask(trackers[1]);
taskAttemptID[6] = job.findReduceTask(trackers[2]);
clock.advance(5000);
job.finishTask(taskAttemptID[4]);
clock.advance(1000);
job.finishTask(taskAttemptID[5]);
clock.advanceBySpeculativeLag();
taskAttemptID[7] = job.findReduceTask(trackers[4]);
int oldRunningReduces = job.runningReduces();
job.failTask(taskAttemptID[6]);
LOG.info(
" No of running Reduces before fail " + oldRunningReduces);
LOG.info(
" No of runing reduces after fail " + job.runningReduces());
assertEquals(
"Running reduces count should be updated from " + oldRunningReduces +
" to " + (oldRunningReduces - 1), job.runningReduces(),
oldRunningReduces - 1);
job.finishTask(taskAttemptID[7]);
}