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);
RunningJob networkJob = jobClient.getJob(id);
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);
}
}
Assert.assertTrue("Task attempt temporary folder has not been cleaned.",
isTempFolderExists && filesStatus.length == 0);
UtilsForTests.waitFor(1000);
jInfo = remoteJTClient.getJobInfo(id);
LOG.info("Waiting till the job is completed...");
while (!jInfo.getStatus().isJobComplete()) {
UtilsForTests.waitFor(100);
jInfo = remoteJTClient.getJobInfo(id);
}
}