1 /*
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
27 import java.rmi.registry.*;
28 import java.time.LocalTime;
29 import java.util.concurrent.TimeoutException;
30
31 /**
32 * Utility class that creates an instance of rmid with a policy
33 * file of name <code>TestParams.defaultPolicy</code>.
34 *
35 * Activation groups should run with the same security manager as the
36 * test.
37 */
38 public class RMID extends JavaVM {
39
40 // TODO: adjust these based on the timeout factor
41 // such as jcov.sleep.multiplier; see start(long) method.
42 // Also consider the test.timeout.factor property (a float).
43 private static final long TIMEOUT_SHUTDOWN_MS = 60_000L;
44 private static final long TIMEOUT_DESTROY_MS = 10_000L;
45 private static final long STARTTIME_MS = 15_000L;
46 private static final long POLLTIME_MS = 100L;
47
48 // when restart rmid, it may take more time than usual because of
49 // "port in use" by a possible interloper (check JDK-8168975),
50 // so need to set a longer timeout for restart.
51 private static long restartTimeout;
52 // Same reason to inheritedChannel in RMIDSelectorProvider.
53 // Put it here rather than in RMIDSelectorProvider to adjust
54 // both timeout values together.
55 private static long inheritedChannelTimeout;
56
57 private static final String SYSTEM_NAME = ActivationSystem.class.getName();
58 // "java.rmi.activation.ActivationSystem"
59
60 public static String MANAGER_OPTION="-Djava.security.manager=";
61
62 /**
63 * Test port for rmid.
64 *
65 * May initially be 0, which means that the child rmid process will choose
66 * an ephemeral port and report it back to the parent process. This field
67 * will then be set to the child rmid's ephemeral port value.
68 */
69 private volatile int port;
70 //private final boolean ephemeralPort
71
247 true, false, 0, additionalOptions);
248 }
249
250 public static RMID createRMIDOnEphemeralPort(OutputStream out,
251 OutputStream err,
252 boolean debugExec)
253 {
254 return createRMID(out, err, debugExec, false, 0);
255 }
256
257
258 /**
259 * Private constructor. RMID instances should be created
260 * using the static factory methods.
261 */
262 private RMID(String classname, String options, String args,
263 OutputStream out, OutputStream err, int port)
264 {
265 super(classname, options, args, out, err);
266 this.port = port;
267 long waitTime = (long)(240_000 * TestLibrary.getTimeoutFactor());
268 restartTimeout = (long)(waitTime * 0.9);
269 inheritedChannelTimeout = (long)(waitTime * 0.8);
270 }
271
272 /**
273 * Removes rmid's log file directory.
274 */
275 public static void removeLog() {
276 File f = new File(LOGDIR, log);
277
278 if (f.exists()) {
279 mesg("Removing rmid's old log file.");
280 String[] files = f.list();
281
282 if (files != null) {
283 for (int i=0; i<files.length; i++) {
284 (new File(f, files[i])).delete();
285 }
286 }
287
288 if (! f.delete()) {
389
390 mesg("after fail to looking up activation system, at " + LocalTime.now());
391 if (System.currentTimeMillis() > deadline) {
392 TestLibrary.bomb("Failed to start rmid, giving up after " +
393 (System.currentTimeMillis() - startTime) + "ms.", null);
394 }
395 }
396 }
397
398 /**
399 * Destroys rmid and restarts it. Note that this does NOT clean up
400 * the log file, because it stores information about restartable
401 * and activatable objects that must be carried over to the new
402 * rmid instance.
403 */
404 public void restart() throws IOException {
405 destroy();
406 options = makeOptions(port, true, true);
407 args = makeArgs();
408
409 start(restartTimeout);
410 }
411
412 /**
413 * Ask rmid to shutdown gracefully using a remote method call.
414 * catch any errors that might occur from rmid not being present
415 * at time of shutdown invocation. If the remote call is
416 * successful, wait for the process to terminate. Return true
417 * if the process terminated, otherwise return false.
418 */
419 private boolean shutdown() throws InterruptedException {
420 mesg("shutdown()");
421 long startTime = System.currentTimeMillis();
422 ActivationSystem system = lookupSystem(port);
423 if (system == null) {
424 mesg("lookupSystem() returned null after " +
425 (System.currentTimeMillis() - startTime) + "ms.");
426 return false;
427 }
428
429 try {
|
1 /*
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
27 import java.rmi.registry.*;
28 import java.time.LocalTime;
29 import java.util.concurrent.TimeoutException;
30
31 /**
32 * Utility class that creates an instance of rmid with a policy
33 * file of name <code>TestParams.defaultPolicy</code>.
34 *
35 * Activation groups should run with the same security manager as the
36 * test.
37 */
38 public class RMID extends JavaVM {
39
40 // TODO: adjust these based on the timeout factor
41 // such as jcov.sleep.multiplier; see start(long) method.
42 // Also consider the test.timeout.factor property (a float).
43 private static final long TIMEOUT_SHUTDOWN_MS = 60_000L;
44 private static final long TIMEOUT_DESTROY_MS = 10_000L;
45 private static final long STARTTIME_MS = 15_000L;
46 private static final long POLLTIME_MS = 100L;
47 private static final long TIMEOUT_BASE = 240_000L;
48
49 // when restart rmid, it may take more time than usual because of
50 // "port in use" by a possible interloper (check JDK-8168975),
51 // so need to set a longer timeout for restart.
52 private static final long RESTART_TIMEOUT = (long)(TIMEOUT_BASE * 0.9);
53 // Same reason to inheritedChannel in RMIDSelectorProvider.
54 // Put it here rather than in RMIDSelectorProvider to adjust
55 // both timeout values together.
56 private static long inheritedChannelTimeout;
57
58 private static final String SYSTEM_NAME = ActivationSystem.class.getName();
59 // "java.rmi.activation.ActivationSystem"
60
61 public static String MANAGER_OPTION="-Djava.security.manager=";
62
63 /**
64 * Test port for rmid.
65 *
66 * May initially be 0, which means that the child rmid process will choose
67 * an ephemeral port and report it back to the parent process. This field
68 * will then be set to the child rmid's ephemeral port value.
69 */
70 private volatile int port;
71 //private final boolean ephemeralPort
72
248 true, false, 0, additionalOptions);
249 }
250
251 public static RMID createRMIDOnEphemeralPort(OutputStream out,
252 OutputStream err,
253 boolean debugExec)
254 {
255 return createRMID(out, err, debugExec, false, 0);
256 }
257
258
259 /**
260 * Private constructor. RMID instances should be created
261 * using the static factory methods.
262 */
263 private RMID(String classname, String options, String args,
264 OutputStream out, OutputStream err, int port)
265 {
266 super(classname, options, args, out, err);
267 this.port = port;
268 long waitTime = (long)(TIMEOUT_BASE * TestLibrary.getTimeoutFactor());
269 inheritedChannelTimeout = (long)(waitTime * 0.8);
270 }
271
272 /**
273 * Removes rmid's log file directory.
274 */
275 public static void removeLog() {
276 File f = new File(LOGDIR, log);
277
278 if (f.exists()) {
279 mesg("Removing rmid's old log file.");
280 String[] files = f.list();
281
282 if (files != null) {
283 for (int i=0; i<files.length; i++) {
284 (new File(f, files[i])).delete();
285 }
286 }
287
288 if (! f.delete()) {
389
390 mesg("after fail to looking up activation system, at " + LocalTime.now());
391 if (System.currentTimeMillis() > deadline) {
392 TestLibrary.bomb("Failed to start rmid, giving up after " +
393 (System.currentTimeMillis() - startTime) + "ms.", null);
394 }
395 }
396 }
397
398 /**
399 * Destroys rmid and restarts it. Note that this does NOT clean up
400 * the log file, because it stores information about restartable
401 * and activatable objects that must be carried over to the new
402 * rmid instance.
403 */
404 public void restart() throws IOException {
405 destroy();
406 options = makeOptions(port, true, true);
407 args = makeArgs();
408
409 start(RESTART_TIMEOUT);
410 }
411
412 /**
413 * Ask rmid to shutdown gracefully using a remote method call.
414 * catch any errors that might occur from rmid not being present
415 * at time of shutdown invocation. If the remote call is
416 * successful, wait for the process to terminate. Return true
417 * if the process terminated, otherwise return false.
418 */
419 private boolean shutdown() throws InterruptedException {
420 mesg("shutdown()");
421 long startTime = System.currentTimeMillis();
422 ActivationSystem system = lookupSystem(port);
423 if (system == null) {
424 mesg("lookupSystem() returned null after " +
425 (System.currentTimeMillis() - startTime) + "ms.");
426 return false;
427 }
428
429 try {
|