7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
Summary: Tighten up JavaVM test library API, and adjust tests to match.
Reviewed-by: mchung, dmocek
diff --git a/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java b/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java
index 64233bf..b6ede1d 100644
--- a/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java
+++ b/test/java/rmi/activation/Activatable/shutdownGracefully/ShutdownGracefully.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -168,7 +168,7 @@
registering = null;
// Need to make sure that rmid goes away by itself
- Process rmidProcess = rmid.getVM();
+ JavaVM rmidProcess = rmid;
if (rmidProcess != null) {
try {
Runnable waitThread =
@@ -205,9 +205,9 @@
* class that waits for rmid to exit
*/
private static class ShutdownDetectThread implements Runnable {
- private Process rmidProcess = null;
+ private JavaVM rmidProcess = null;
- ShutdownDetectThread(Process rmidProcess) {
+ ShutdownDetectThread(JavaVM rmidProcess) {
this.rmidProcess = rmidProcess;
}
public void run() {
diff --git a/test/java/rmi/activation/checkusage/CheckUsage.java b/test/java/rmi/activation/checkusage/CheckUsage.java
index 2b514e1..c114928 100644
--- a/test/java/rmi/activation/checkusage/CheckUsage.java
+++ b/test/java/rmi/activation/checkusage/CheckUsage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -23,6 +23,7 @@
/* @test
* @bug 4259564
+ * @summary RMID's usage message is incomplete and inconsistent with other tools
*
* @library ../../testlibrary
* @build TestLibrary JavaVM
@@ -37,23 +38,16 @@
*/
public class CheckUsage {
public static void main(String[] args) {
-
- System.err.println("\nregression test for 4259564\n");
-
- JavaVM rmidVM = null;
-
try {
- // make sure the registry exits with a proper usage statement
ByteArrayOutputStream berr = new ByteArrayOutputStream();
- // run a VM to start the registry
- rmidVM = new JavaVM("sun.rmi.server.Activation", "", "foo",
- System.out, berr);
+ // create rmid with incorrect command line args
+ JavaVM rmidVM = new JavaVM("sun.rmi.server.Activation", "", "foo",
+ System.out, berr);
System.err.println("starting rmid");
- rmidVM.start();
- // wait for registry exit
- int rmidVMExitStatus = rmidVM.getVM().waitFor();
+ // run the subprocess and wait for it to exit
+ int rmidVMExitStatus = rmidVM.execute();
System.err.println("rmid exited with status: " +
rmidVMExitStatus);
@@ -66,12 +60,8 @@
} else {
System.err.println("test passed");
}
-
} catch (Exception e) {
TestLibrary.bomb(e);
- } finally {
- rmidVM.destroy();
- rmidVM = null;
}
}
}
diff --git a/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java b/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java
index 08d030e..3510429 100644
--- a/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java
+++ b/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -76,8 +76,7 @@
}
System.err.println("starting " + utilityToStart);
- vm.start();
- vm.getVM().waitFor();
+ vm.execute();
} catch (Exception e) {
TestLibrary.bomb(e);
diff --git a/test/java/rmi/registry/checkusage/CheckUsage.java b/test/java/rmi/registry/checkusage/CheckUsage.java
index 19dac5b..88d9a90 100644
--- a/test/java/rmi/registry/checkusage/CheckUsage.java
+++ b/test/java/rmi/registry/checkusage/CheckUsage.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -35,34 +35,21 @@
/**
* Make sure that the rmiregistry prints out a correct usage statement
- * when run with an incorrect command line; test written to conform to
- * new tighter bug fix/regression test guidelines.
+ * when run with an incorrect command line.
*/
public class CheckUsage {
public static void main(String[] args) {
- System.err.println("\nregression test for 4151966\n");
-
- JavaVM registryVM = null;
-
try {
- // make sure the registry exits with a proper usage statement
ByteArrayOutputStream berr = new ByteArrayOutputStream();
// run a VM to start the registry
- registryVM = new JavaVM("sun.rmi.registry.RegistryImpl",
- "", "foo",
- System.out, berr);
+ JavaVM registryVM = new JavaVM("sun.rmi.registry.RegistryImpl",
+ "", "foo",
+ System.out, berr);
System.err.println("starting registry");
- registryVM.start();
-
- // wait for registry exit
System.err.println(" registry exited with status: " +
- registryVM.getVM().waitFor());
- try {
- Thread.sleep(7000);
- } catch (InterruptedException ie) {
- }
+ registryVM.execute());
String usage = new String(berr.toByteArray());
@@ -75,9 +62,6 @@
}
} catch (Exception e) {
TestLibrary.bomb(e);
- } finally {
- registryVM.destroy();
- registryVM = null;
}
}
}
diff --git a/test/java/rmi/registry/reexport/Reexport.java b/test/java/rmi/registry/reexport/Reexport.java
index c209f7c..3841178 100644
--- a/test/java/rmi/registry/reexport/Reexport.java
+++ b/test/java/rmi/registry/reexport/Reexport.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -122,8 +122,7 @@
try {
JavaVM jvm = new JavaVM("RegistryRunner", "", Integer.toString(p));
jvm.start();
- Reexport.subreg = jvm.getVM();
-
+ Reexport.subreg = jvm;
} catch (IOException e) {
// one of these is summarily dropped, can't remember which one
System.out.println ("Test setup failed - cannot run rmiregistry");
@@ -135,7 +134,8 @@
} catch (Exception whatever) {
}
}
- private static Process subreg = null;
+
+ private static JavaVM subreg = null;
public static void killRegistry(int port) {
if (Reexport.subreg != null) {
diff --git a/test/java/rmi/testlibrary/JavaVM.java b/test/java/rmi/testlibrary/JavaVM.java
index 6ccae91..c363f8e 100644
--- a/test/java/rmi/testlibrary/JavaVM.java
+++ b/test/java/rmi/testlibrary/JavaVM.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
private OutputStream outputStream = System.out;
private OutputStream errorStream = System.err;
private String policyFileName = null;
+ private StreamPipe outPipe;
+ private StreamPipe errPipe;
private static void mesg(Object mesg) {
System.err.println("JAVAVM: " + mesg.toString());
@@ -145,13 +147,12 @@
}
mesg("command = " + Arrays.asList(javaCommand).toString());
- System.err.println("");
vm = Runtime.getRuntime().exec(javaCommand);
/* output from the execed process may optionally be captured. */
- StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
- StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
+ outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
+ errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
}
public void destroy() {
@@ -161,7 +162,25 @@
vm = null;
}
- protected Process getVM() {
- return vm;
+ /**
+ * Waits for the subprocess to exit, joins the pipe threads to ensure that
+ * all output is collected, and returns its exit status.
+ */
+ public int waitFor() throws InterruptedException {
+ if (vm == null)
+ throw new IllegalStateException("can't wait for JavaVM that hasn't started");
+
+ int status = vm.waitFor();
+ outPipe.join();
+ errPipe.join();
+ return status;
+ }
+
+ /**
+ * Starts the subprocess, waits for it to exit, and returns its exit status.
+ */
+ public int execute() throws IOException, InterruptedException {
+ start();
+ return waitFor();
}
}
diff --git a/test/java/rmi/testlibrary/RMID.java b/test/java/rmi/testlibrary/RMID.java
index e963c45..8b0f3e2 100644
--- a/test/java/rmi/testlibrary/RMID.java
+++ b/test/java/rmi/testlibrary/RMID.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -202,8 +202,6 @@
public void start(long waitTime) throws IOException {
- if (getVM() != null) return;
-
// if rmid is already running, then the test will fail with
// a well recognized exception (port already in use...).
diff --git a/test/java/rmi/transport/checkFQDN/CheckFQDN.java b/test/java/rmi/transport/checkFQDN/CheckFQDN.java
index 9660f53..deceb27 100644
--- a/test/java/rmi/transport/checkFQDN/CheckFQDN.java
+++ b/test/java/rmi/transport/checkFQDN/CheckFQDN.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -114,6 +114,7 @@
equal = "=";
}
+ // create a client to tell checkFQDN what its rmi name is.
JavaVM jvm = new JavaVM("CheckFQDNClient",
propOption + property +
equal +
@@ -125,10 +126,7 @@
propertyBeingTested=property;
propertyBeingTestedValue=propertyValue;
- // create a client to tell checkFQDN what its rmi name is. */
- jvm.start();
-
- if (jvm.getVM().waitFor() != 0 ) {
+ if (jvm.execute() != 0) {
TestLibrary.bomb("Test failed, error in client.");
}
diff --git a/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java b/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java
index 52fd7df..b32a8a5 100644
--- a/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java
+++ b/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -102,9 +102,8 @@
" -Drmi.registry.port=" +
registryPort,
"");
- jvm.start();
- if (jvm.getVM().waitFor() == 1 ) {
+ if (jvm.execute() != 0) {
TestLibrary.bomb("Client process failed");
}
}