|
12 | 12 | import java.nio.file.Path; |
13 | 13 | import java.util.concurrent.atomic.AtomicInteger; |
14 | 14 | import org.junit.AfterClass; |
15 | | -import org.junit.Assert; |
16 | 15 | import org.junit.Test; |
17 | 16 | import org.junit.runner.RunWith; |
18 | 17 | import org.junit.runners.JUnit4; |
|
22 | 21 | @RunWith(JUnit4.class) |
23 | 22 | public class WorkerTest { |
24 | 23 |
|
25 | | - @Test |
26 | | - public void testEphemeralWorkerSystemExit() throws Exception { |
27 | | - |
28 | | - // An ephemeral worker behaves like a regular main method, |
29 | | - // so we expect the worker to system exit normally |
30 | | - |
31 | | - Worker.Interface worker = |
32 | | - new Worker.Interface() { |
33 | | - @Override |
34 | | - public void work(String[] args) { |
35 | | - System.exit(99); |
36 | | - } |
37 | | - }; |
38 | | - |
39 | | - int code = |
40 | | - assertThrows(Worker.ExitTrapped.class, () -> Worker.workerMain(new String[] {}, worker)) |
41 | | - .code; |
42 | | - |
43 | | - assert (code == 99); |
44 | | - } |
45 | | - |
46 | | - @Test |
47 | | - public void testPersistentWorkerSystemExit() throws Exception { |
48 | | - // We're going to spin up a persistent worker and run a single |
49 | | - // work request. We expect System.exit calls to impact the |
50 | | - // worker request lifecycle without exiting the overall worker |
51 | | - // process. |
52 | | - |
53 | | - try (PersistentWorkerHelper helper = new PersistentWorkerHelper(); ) { |
54 | | - WorkerProtocol.WorkRequest.newBuilder().build().writeDelimitedTo(helper.requestOut); |
55 | | - |
56 | | - Worker.Interface worker = |
57 | | - new Worker.Interface() { |
58 | | - @Override |
59 | | - public void work(String[] args) { |
60 | | - // we should see this print statement |
61 | | - System.out.println("before exit"); |
62 | | - System.exit(100); |
63 | | - // we should not see this print statement |
64 | | - System.out.println("after exit"); |
65 | | - } |
66 | | - }; |
67 | | - |
68 | | - helper.runWorker(worker); |
69 | | - |
70 | | - WorkerProtocol.WorkResponse response = |
71 | | - WorkerProtocol.WorkResponse.parseDelimitedFrom(helper.responseIn); |
72 | | - |
73 | | - assert (response.getOutput().contains("before")); |
74 | | - assert (response.getExitCode() == 100); |
75 | | - assert (!response.getOutput().contains("after")); |
76 | | - } |
77 | | - } |
78 | | - |
79 | 24 | @Test |
80 | 25 | public void testPersistentWorkerNoStdin() throws Exception { |
81 | 26 | try (PersistentWorkerHelper helper = new PersistentWorkerHelper(); ) { |
|
0 commit comments