[Test failed] GridCommandLineLoaderTest test crashes the process on some environments
@@ -52,6 +52,9 @@ public final class GridJavaProcess {
/** Internal protocol message prefix saying that the next text in the outputted line is pid. */
public static final String PID_MSG_PREFIX = "my_pid_is:";
+ /** Default pid. */
+ private static final String DFLT_PID = "-1";
+
/** Logger */
private IgniteLogger log;
@@ -59,7 +62,7 @@ public final class GridJavaProcess {
private Process proc;
/** Pid of wrapped process. Made as array to be changeable in nested static class. */
- private volatile String pid = "-1";
+ private volatile String pid = DFLT_PID;
/** system.out stream grabber for process in which user class is running. */
private ProcessStreamGrabber osGrabber;
@@ -186,6 +189,7 @@ public final class GridJavaProcess {
* @throws Exception If any problem occurred.
*/
public void kill() throws Exception {
+ if (!pid.equals(DFLT_PID)) {
Process killProc = U.isWindows() ?
Runtime.getRuntime().exec(new String[]{"taskkill", "/pid", pid, "/f", "/t"}) :
Runtime.getRuntime().exec(new String[]{"kill", "-9", pid});
@@ -197,6 +201,7 @@ public final class GridJavaProcess {
if (exitVal != 0 && log.isInfoEnabled())
log.info(String.format("Abnormal exit value of %s for trying to kill the pid %s", exitVal, pid));
+ }
if (!proc.waitFor(5000, TimeUnit.MILLISECONDS))
throw new IllegalStateException("Failed to kill grid java process.");
