public void testDirCleanupAfterTaskKilled() throws IOException,
InterruptedException {
TaskInfo taskInfo = null;
boolean isTempFolderExists = false;
String localTaskDir = null;
TTClient ttClient = null;
FileStatus filesStatus [] = null;
Path inputDir = new Path("input");
Path outputDir = new Path("output");
Configuration conf = new Configuration(cluster.getConf());
JobConf jconf = new JobConf(conf);
jconf.setJobName("Word Count");
jconf.setJarByClass(WordCount.class);
jconf.setMapperClass(WordCount.MapClass.class);
jconf.setCombinerClass(WordCount.Reduce.class);
jconf.setReducerClass(WordCount.Reduce.class);
jconf.setNumMapTasks(1);
jconf.setNumReduceTasks(1);
jconf.setOutputKeyClass(Text.class);
jconf.setOutputValueClass(IntWritable.class);
cleanup(inputDir, conf);
cleanup(outputDir, conf);
createInput(inputDir, conf);
FileInputFormat.setInputPaths(jconf, inputDir);
FileOutputFormat.setOutputPath(jconf, outputDir);
RunningJob runJob = jobClient.submitJob(jconf);
JobID id = runJob.getID();
JobInfo jInfo = remoteJTClient.getJobInfo(id);
Assert.assertTrue("Job has not been started for 1 min.",
jtClient.isJobStarted(id));
JobStatus[] jobStatus = jobClient.getAllJobs();
String userName = jobStatus[0].getUsername();
TaskInfo[] taskInfos = remoteJTClient.getTaskInfo(id);
for (TaskInfo taskinfo : taskInfos) {
if (!taskinfo.isSetupOrCleanup() && taskinfo.getTaskID().isMap()) {
taskInfo = taskinfo;
break;
}
}
Assert.assertTrue("Task has not been started for 1 min.",
jtClient.isTaskStarted(taskInfo));
TaskID tID = TaskID.downgrade(taskInfo.getTaskID());
FinishTaskControlAction action = new FinishTaskControlAction(tID);
String[] taskTrackers = taskInfo.getTaskTrackers();
int counter = 0;
TaskInfo prvTaskInfo = taskInfo;
while (counter++ < 30) {
if (taskTrackers.length > 0) {
break;
} else {
UtilsForTests.waitFor(100);
taskInfo = remoteJTClient.getTaskInfo(taskInfo.getTaskID());
if (taskInfo == null) {
taskInfo = prvTaskInfo;
} else {
prvTaskInfo = taskInfo;
}
taskTrackers = taskInfo.getTaskTrackers();
}
}
Assert.assertTrue("TaskTracker is not found.", taskTrackers.length > 0);
String hostName = taskTrackers[0].split("_")[1];
hostName = hostName.split(":")[0];
ttClient = cluster.getTTClient(hostName);
String localDirs[] = ttClient.getMapredLocalDirs();
TaskAttemptID taskAttID = new TaskAttemptID(tID, 0);
for (String localDir : localDirs) {
localTaskDir = localDir + "/"
+ TaskTracker.getLocalTaskDir(userName,
id.toString(), taskAttID.toString());
filesStatus = ttClient.listStatus(localTaskDir, true);
if (filesStatus.length > 0) {
isTempFolderExists = true;
break;
}
}
Assert.assertTrue("Task Attempt directory " +
taskAttID + " has not been found while task was running.",
isTempFolderExists);
NetworkedJob networkJob = jobClient.new NetworkedJob(jInfo.getStatus());
networkJob.killTask(taskAttID, false);
ttClient.getProxy().sendAction(action);
taskInfo = remoteJTClient.getTaskInfo(tID);
while(taskInfo.getTaskStatus()[0].getRunState() ==
TaskStatus.State.RUNNING) {
UtilsForTests.waitFor(1000);
taskInfo = remoteJTClient.getTaskInfo(tID);
}
UtilsForTests.waitFor(1000);
taskInfo = remoteJTClient.getTaskInfo(tID);
Assert.assertTrue("Task status has not been changed to KILLED.",
(TaskStatus.State.KILLED ==
taskInfo.getTaskStatus()[0].getRunState()
|| TaskStatus.State.KILLED_UNCLEAN ==
taskInfo.getTaskStatus()[0].getRunState()));
taskInfo = remoteJTClient.getTaskInfo(tID);
counter = 0;
while (counter++ < 60) {
filesStatus = ttClient.listStatus(localTaskDir, true);
if (filesStatus.length == 0) {
break;
} else {
UtilsForTests.waitFor(100);
}