@@ -98,6 +98,7 @@ public static void main(String... args) throws Exception {
98
98
System .out .println ("Waiting for all processes to get started notification" );
99
99
listener .started .acquire (PROCESS_COUNT );
100
100
101
+ System .out .println ("Terminating all processes" );
101
102
for (JavaProcess javaProcess : javaProcesses ) {
102
103
javaProcess .terminate ();
103
104
}
@@ -138,7 +139,7 @@ public void disconnected(HostEvent arg0) {
138
139
}
139
140
140
141
private void releaseStarted (Set <Integer > ids ) {
141
- System .out .println ("realeaseStarted (" + ids + ")" );
142
+ System .out .println ("releaseStarted (" + ids + ")" );
142
143
for (Integer id : ids ) {
143
144
releaseStarted (id );
144
145
}
@@ -149,11 +150,12 @@ private void releaseStarted(Integer id) {
149
150
if (hasMainArgs (id , jp .getMainArgsIdentifier ())) {
150
151
// store id for terminated identification
151
152
jp .setId (id );
152
- System .out .println ("RELEASED (id=" + jp .getId () + ", args=" + jp .getMainArgsIdentifier () + ")" );
153
+ System .out .println ("RELEASED started (id=" + jp .getId () + ", args=" + jp .getMainArgsIdentifier () + ")" );
153
154
started .release ();
154
155
return ;
155
156
}
156
157
}
158
+ System .out .println ("releaseStarted: not a test pid: " + id );
157
159
}
158
160
159
161
private void releaseTerminated (Set <Integer > ids ) {
@@ -166,23 +168,44 @@ private void releaseTerminated(Set<Integer> ids) {
166
168
private void releaseTerminated (Integer id ) {
167
169
for (JavaProcess jp : processes ) {
168
170
if (id .equals (jp .getId ())) {
169
- System .out .println ("RELEASED (id=" + jp .getId () + ", args=" + jp .getMainArgsIdentifier () + ")" );
171
+ System .out .println ("RELEASED terminated (id=" + jp .getId () + ", args=" + jp .getMainArgsIdentifier () + ")" );
170
172
terminated .release ();
171
173
return ;
172
174
}
173
175
}
174
176
}
175
177
178
+ private static final int ARGS_ATTEMPTS = 3 ;
179
+
176
180
private boolean hasMainArgs (Integer id , String args ) {
181
+ VmIdentifier vmid = null ;
177
182
try {
178
- VmIdentifier vmid = new VmIdentifier ("//" + id .intValue ());
179
- MonitoredVm target = host .getMonitoredVm (vmid );
180
- String monitoredArgs = MonitoredVmUtil .mainArgs (target );
181
- if (monitoredArgs != null && monitoredArgs .contains (args )) {
182
- return true ;
183
+ vmid = new VmIdentifier ("//" + id .intValue ());
184
+ } catch (URISyntaxException e ) {
185
+ System .out .println ("hasMainArgs(" + id + "): " + e );
186
+ return false ;
187
+ }
188
+ // Retry a failing attempt to check arguments for a match,
189
+ // as not recognizing a test process will cause timeout and failure.
190
+ for (int i = 0 ; i < ARGS_ATTEMPTS ; i ++) {
191
+ try {
192
+ MonitoredVm target = host .getMonitoredVm (vmid );
193
+ String monitoredArgs = MonitoredVmUtil .mainArgs (target );
194
+ System .out .println ("hasMainArgs(" + id + "): has main args: '" + monitoredArgs + "'" );
195
+ if (monitoredArgs == null || monitoredArgs .equals ("Unknown" )) {
196
+ System .out .println ("hasMainArgs(" + id + "): retry" );
197
+ takeNap ();
198
+ continue ;
199
+ } else if (monitoredArgs .contains (args )) {
200
+ return true ;
201
+ } else {
202
+ return false ;
203
+ }
204
+ } catch (MonitorException e ) {
205
+ // Process probably not running or not ours, e.g.
206
+ // sun.jvmstat.monitor.MonitorException: Could not attach to PID
207
+ System .out .println ("hasMainArgs(" + id + "): " + e );
183
208
}
184
- } catch (URISyntaxException | MonitorException e ) {
185
- // ok. process probably not running
186
209
}
187
210
return false ;
188
211
}
@@ -247,14 +270,6 @@ private static void waitForRemoval(Path path) {
247
270
}
248
271
}
249
272
250
- private static void takeNap () {
251
- try {
252
- Thread .sleep (100 );
253
- } catch (InterruptedException e ) {
254
- // ignore
255
- }
256
- }
257
-
258
273
private final String mainArgsIdentifier ;
259
274
private final ShutdownHook shutdownHook ;
260
275
private volatile Integer id ;
@@ -323,4 +338,12 @@ public String getMainArgsIdentifier() {
323
338
return mainArgsIdentifier ;
324
339
}
325
340
}
341
+
342
+ public static void takeNap () {
343
+ try {
344
+ Thread .sleep (1000 );
345
+ } catch (InterruptedException e ) {
346
+ // ignore
347
+ }
348
+ }
326
349
}
0 commit comments