Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java')
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java57
1 files changed, 56 insertions, 1 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java
index 0134dc349..7dbdd2215 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/RuntimeProcessTests.java
@@ -15,8 +15,10 @@ package org.eclipse.debug.tests.console;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.debug.core.DebugEvent;
@@ -78,11 +80,64 @@ public class RuntimeProcessTests extends AbstractDebugTest {
mockProcess.setExitValue(1);
runtimeProcess.terminate();
- assertFalse("RuntimeProcess failed to terminated wrapped process.", mockProcess.isAlive());
+ assertFalse("RuntimeProcess failed to terminate wrapped process.", mockProcess.isAlive());
TestUtil.waitWhile(p -> !p.isTerminated(), runtimeProcess, 1000, p -> "RuntimePocess not terminated.");
TestUtil.waitForJobs(name.getMethodName(), 25, 500);
assertEquals("Wrong number of terminate events.", 1, processTerminateEvents.get());
assertEquals("RuntimeProcess reported wrong exit code.", 1, runtimeProcess.getExitValue());
}
+
+ /**
+ * Test {@link RuntimeProcess} terminating the wrapped process and its
+ * descendants.
+ */
+ @Test
+ public void testTerminateProcessWithSubProcesses() throws Exception {
+
+ MockProcess grandChildProcess = new MockProcess(MockProcess.RUN_FOREVER);
+
+ MockProcess childProcess1 = new MockProcess(MockProcess.RUN_FOREVER);
+ childProcess1.setHandle(new MockProcessHandle(childProcess1, List.of(grandChildProcess)));
+
+ MockProcess childProcess2 = new MockProcess(MockProcess.RUN_FOREVER);
+
+ MockProcess mockProcess = new MockProcess(MockProcess.RUN_FOREVER);
+ mockProcess.setHandle(new MockProcessHandle(childProcess1, List.of(childProcess1, childProcess2)));
+
+ RuntimeProcess runtimeProcess = mockProcess.toRuntimeProcess();
+
+ assertTrue("RuntimeProcess already terminated.", grandChildProcess.isAlive());
+ assertTrue("RuntimeProcess already terminated.", childProcess1.isAlive());
+ assertTrue("RuntimeProcess already terminated.", childProcess2.isAlive());
+ assertFalse("RuntimeProcess already terminated.", runtimeProcess.isTerminated());
+
+ runtimeProcess.terminate();
+
+ assertFalse("RuntimeProcess failed to terminate wrapped process.", mockProcess.isAlive());
+ assertFalse("RuntimeProcess failed to terminate child of wrapped process.", childProcess1.isAlive());
+ assertFalse("RuntimeProcess failed to terminate child of wrapped process.", childProcess2.isAlive());
+ assertFalse("RuntimeProcess failed to terminate descendant of wrapped process.", grandChildProcess.isAlive());
+
+ TestUtil.waitWhile(p -> !p.isTerminated(), runtimeProcess, 1000, p -> "RuntimePocess not terminated.");
+ }
+
+ /**
+ * Test {@link RuntimeProcess} terminating the wrapped process which does
+ * not support {@link Process#toHandle()}.
+ */
+ @Test
+ public void testTerminateProcessNotSupportingProcessToHandle() throws Exception {
+
+ MockProcess mockProcess = new MockProcess(MockProcess.RUN_FOREVER);
+ // set handle to null, so the standard java.lang.Process.toHandle()
+ // implementation is called which throws an
+ // UnsupportedOperationException
+ mockProcess.setHandle(null);
+ assertThrows(UnsupportedOperationException.class, () -> mockProcess.toHandle());
+ RuntimeProcess runtimeProcess = mockProcess.toRuntimeProcess();
+ runtimeProcess.terminate(); // must not throw, even toHandle() does
+
+ TestUtil.waitWhile(p -> !p.isTerminated(), runtimeProcess, 1000, p -> "RuntimePocess not terminated.");
+ }
}

Back to the top