109 Long child = Long.valueOf(split[2]);
110 Long parent = Long.valueOf(split[0].split(":")[0]);
111 processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get());
112 }
113 });
114
115 proc.sendAction("spawn", "3", "stdin");
116
117 proc.sendAction("child", "spawn", "2", "stdin");
118
119 // Poll until all 9 child processes exist or the timeout is reached
120 int expected = 9;
121 long timeout = Utils.adjustTimeout(10L);
122 Instant endTimeout = Instant.now().plusSeconds(timeout);
123 do {
124 Thread.sleep(200L);
125 printf(" subprocess count: %d, waiting for %d%n", processes.size(), expected);
126 } while (processes.size() < expected &&
127 Instant.now().isBefore(endTimeout));
128
129 children = getAllChildren(procHandle);
130
131 ConcurrentHashMap<ProcessHandle, CompletableFuture<ProcessHandle>> completions =
132 new ConcurrentHashMap<>();
133 Instant startTime = Instant.now();
134 // Create a future for each of the 9 children
135 processes.forEach( (p, parent) -> {
136 CompletableFuture<ProcessHandle> cf = p.onExit().whenComplete((ph, ex) -> {
137 Duration elapsed = Duration.between(startTime, Instant.now());
138 printf("whenComplete: pid: %s, exception: %s, thread: %s, elapsed: %s%n",
139 ph, ex, Thread.currentThread(), elapsed);
140 });
141 completions.put(p, cf);
142 });
143
144 // Check that each of the spawned processes is included in the children
145 List<ProcessHandle> remaining = new ArrayList<>(children);
146 processes.forEach((p, parent) -> {
147 Assert.assertTrue(remaining.remove(p), "spawned process should have been in children");
148 });
|
109 Long child = Long.valueOf(split[2]);
110 Long parent = Long.valueOf(split[0].split(":")[0]);
111 processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get());
112 }
113 });
114
115 proc.sendAction("spawn", "3", "stdin");
116
117 proc.sendAction("child", "spawn", "2", "stdin");
118
119 // Poll until all 9 child processes exist or the timeout is reached
120 int expected = 9;
121 long timeout = Utils.adjustTimeout(10L);
122 Instant endTimeout = Instant.now().plusSeconds(timeout);
123 do {
124 Thread.sleep(200L);
125 printf(" subprocess count: %d, waiting for %d%n", processes.size(), expected);
126 } while (processes.size() < expected &&
127 Instant.now().isBefore(endTimeout));
128
129 if (processes.size() < expected) {
130 printf("WARNING: not all children have been started. Can't complete test.%n");
131 printf(" You can try to increase the timeout or%n");
132 printf(" you can try to use a faster VM (i.e. not a debug version).%n");
133 return;
134 }
135 children = getAllChildren(procHandle);
136
137 ConcurrentHashMap<ProcessHandle, CompletableFuture<ProcessHandle>> completions =
138 new ConcurrentHashMap<>();
139 Instant startTime = Instant.now();
140 // Create a future for each of the 9 children
141 processes.forEach( (p, parent) -> {
142 CompletableFuture<ProcessHandle> cf = p.onExit().whenComplete((ph, ex) -> {
143 Duration elapsed = Duration.between(startTime, Instant.now());
144 printf("whenComplete: pid: %s, exception: %s, thread: %s, elapsed: %s%n",
145 ph, ex, Thread.currentThread(), elapsed);
146 });
147 completions.put(p, cf);
148 });
149
150 // Check that each of the spawned processes is included in the children
151 List<ProcessHandle> remaining = new ArrayList<>(children);
152 processes.forEach((p, parent) -> {
153 Assert.assertTrue(remaining.remove(p), "spawned process should have been in children");
154 });
|