@Test (timeout = 20000)
public void testInvalidSymlinkDiagnostics() throws IOException  {

  File shellFile = null;
  File tempFile = null;
  String symLink = Shell.WINDOWS ? "test.cmd" :
    "test";
  File symLinkFile = null;
  try {
    shellFile = Shell.appendScriptExtension(tmpDir, "hello");
    tempFile = Shell.appendScriptExtension(tmpDir, "temp");
    String timeoutCommand = Shell.WINDOWS ? "@echo \"hello\"" :
      "echo \"hello\"";
    PrintWriter writer = new PrintWriter(new FileOutputStream(shellFile));
    FileUtil.setExecutable(shellFile, true);
    writer.println(timeoutCommand);
    writer.close();
    Map<Path, List<String>> resources =
        new HashMap<Path, List<String>>();
    //This is an invalid path and should throw exception because of No such file.
    Path invalidPath = new Path(shellFile.getAbsolutePath()+"randomPath");
    resources.put(invalidPath, Arrays.asList(symLink));
    FileOutputStream fos = new FileOutputStream(tempFile);
    Map<String, String> env = new HashMap<String, String>();
    List<String> commands = new ArrayList<String>();
    if (Shell.WINDOWS) {
      commands.add("cmd");
      commands.add("/c");
      commands.add("\"" + symLink + "\"");
    } else {
      commands.add("/bin/sh ./\\\"" + symLink + "\\\"");
    }
    ContainerLaunch.writeLaunchEnv(fos, env, resources, commands);
    fos.flush();
    fos.close();
    FileUtil.setExecutable(tempFile, true);
    Shell.ShellCommandExecutor shexc
    = new Shell.ShellCommandExecutor(new String[]{tempFile.getAbsolutePath()}, tmpDir);
    String diagnostics = null;
    try {
      shexc.execute();
      Assert.fail("Should catch exception");
    } catch(ExitCodeException e){
      diagnostics = e.getMessage();
    }
    Assert.assertNotNull(diagnostics);
    Assert.assertTrue(shexc.getExitCode() != 0);
    symLinkFile = new File(tmpDir, symLink);
  }
  finally {
    // cleanup
    if (shellFile != null
        && shellFile.exists()) {
      shellFile.delete();
    }
    if (tempFile != null
        && tempFile.exists()) {
      tempFile.delete();
    }
    if (symLinkFile != null
        && symLinkFile.exists()) {
      symLinkFile.delete();
    }
  }
}