in.close();
JVMId jvmid = mapJvmManager.runningTaskToJvm.get(taskRunner);
jvmManager.setPidToJvm(jvmid, pid);
// kill JvmRunner
final JvmRunner jvmRunner = mapJvmManager.jvmIdToRunner.get(jvmid);
Thread killer = new Thread() {
public void run() {
try {
jvmRunner.kill();
} catch (IOException e) {
e.printStackTrace();
setThreadCaughtException();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
killer.start();
//wait for a while so that killer thread is started.
Thread.sleep(100);
// kill the jvm externally
taskRunner.kill();
assertTrue(jvmRunner.killed);
// launch another jvm and see it finishes properly
attemptID = new TaskAttemptID("test", 0, true, 0, 1);
task = new MapTask(null, attemptID, 0, null, MAP_SLOTS);
task.setUser(user);
task.setConf(taskConf);
tip = tt.new TaskInProgress(task, taskConf);
TaskRunner taskRunner2 = task.createRunner(tt, tip, rjob);
// build dummy vargs to call ls
Vector<String> vargs2 = new Vector<String>(1);
vargs2.add(writeScript("LS", "ls", pidFile).getAbsolutePath());
File workDir2 = new File(TEST_DIR, "work2");
File stdout2 = new File(TEST_DIR, "stdout2");
File stderr2 = new File(TEST_DIR, "stderr2");
taskRunner2.launchJvmAndWait(null, vargs2, stdout2, stderr2, 100, workDir2);
// join all the threads
killer.join();
jvmRunner.join();
launcher.join();
assertFalse("Thread caught unexpected IOException",
threadCaughtException);
}