public void testDirCleanupAfterTaskKilled()
throws IOException, InterruptedException {
TaskInfo taskInfo = null;
boolean isTempFolderExists = false;
String localTaskDir = null;
TTClient ttClient = null;
TaskID tID = 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.setMaxMapAttempts(20);
jconf.setMaxReduceAttempts(20);
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);
int counter = 0;
while (counter < 60) {
if (jInfo.getStatus().getRunState() == JobStatus.RUNNING) {
break;
} else {
UtilsForTests.waitFor(1000);
jInfo = remoteJTClient.getJobInfo(id);
}
counter++;
}
Assert.assertTrue("Job has not been started for 1 min.", counter != 60);
JobStatus[] jobStatus = jobClient.getAllJobs();
String userName = jobStatus[0].getUsername();
TaskInfo[] taskInfos = remoteJTClient.getTaskInfo(id);
for (TaskInfo taskinfo : taskInfos) {
if (!taskinfo.isSetupOrCleanup()) {
taskInfo = taskinfo;
break;
}
}
counter = 0;
while (counter < 30) {
if (taskInfo.getTaskStatus().length > 0) {
if (taskInfo.getTaskStatus()[0].getRunState() == TaskStatus.State.RUNNING) {
break;
}
}
UtilsForTests.waitFor(1000);
taskInfo = remoteJTClient.getTaskInfo(taskInfo.getTaskID());
counter++;
}
Assert.assertTrue("Task has not been started for 30 sec.", counter != 30);
tID = TaskID.downgrade(taskInfo.getTaskID());
FinishTaskControlAction action = new FinishTaskControlAction(tID);
String[] taskTrackers = taskInfo.getTaskTrackers();
counter = 0;
while (counter < 30) {
if (taskTrackers.length != 0) {
break;
}
UtilsForTests.waitFor(100);
taskTrackers = taskInfo.getTaskTrackers();
counter++;
}
String hostName = taskTrackers[0].split("_")[1];
hostName = hostName.split(":")[0];
ttClient = cluster.getTTClient(hostName);
ttClient.getProxy().sendAction(action);
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;
NetworkedJob networkJob = jobClient.new NetworkedJob(jInfo.getStatus());
networkJob.killTask(taskAttID, false);
break;
}
}
Assert.assertTrue(
"Task Attempt directory "
+ taskAttID + " has not been found while task was running.",
isTempFolderExists);
taskInfo = remoteJTClient.getTaskInfo(tID);
counter = 0;
while (counter < 60) {
UtilsForTests.waitFor(1000);
taskInfo = remoteJTClient.getTaskInfo(tID);
filesStatus = ttClient.listStatus(localTaskDir, true);
if (filesStatus.length == 0) {
break;
}
counter++;
}