1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.commons.exec.issues;
21
22 import static org.junit.jupiter.api.Assertions.assertFalse;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.io.File;
26
27 import org.apache.commons.exec.CommandLine;
28 import org.apache.commons.exec.DefaultExecuteResultHandler;
29 import org.apache.commons.exec.DefaultExecutor;
30 import org.apache.commons.exec.ExecuteWatchdog;
31 import org.apache.commons.exec.Executor;
32 import org.apache.commons.exec.TestUtil;
33 import org.junit.jupiter.api.Test;
34
35
36
37
38 class Exec44Test {
39
40 private final Executor exec = DefaultExecutor.builder().get();
41 private final File testDir = new File("src/test/scripts");
42 private final File foreverTestScript = TestUtil.resolveScriptFileForOS(testDir + "/forever");
43
44
45
46
47
48
49
50
51 @Test
52 void testExec44() throws Exception {
53
54 final CommandLine cl = new CommandLine(foreverTestScript);
55 final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
56 final ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT);
57
58 exec.setWatchdog(watchdog);
59 exec.execute(cl, resultHandler);
60
61
62 Thread.sleep(5000);
63 assertTrue(watchdog.isWatching(), "The watchdog is watching the process");
64
65
66 watchdog.destroyProcess();
67 assertTrue(watchdog.killedProcess(), "The watchdog has killed the process");
68 assertFalse(watchdog.isWatching(), "The watchdog is no longer watching any process");
69 }
70 }