changeset 16460:144b1248e27d

8030950: TEST_BUG: java/rmi/registry/classPathCodebase/ClassPathCodebase.java failing intermittently Reviewed-by: rriggs
author mli
date Thu, 12 Jan 2017 10:10:32 -0800
parents dfbdab76bedc
children 72adb4e6b20a
files test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java test/java/rmi/registry/classPathCodebase/registry.security.policy test/java/rmi/registry/classPathCodebase/security.policy
diffstat 3 files changed, 39 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java	Thu Jan 12 18:02:48 2017 +0000
+++ b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java	Thu Jan 12 10:10:32 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2017, 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
@@ -34,7 +34,7 @@
  *          java.rmi/sun.rmi.server
  *          java.rmi/sun.rmi.transport
  *          java.rmi/sun.rmi.transport.tcp
- * @build TestLibrary Dummy
+ * @build TestLibrary Dummy RegistryVM RMIRegistryRunner
  * @run main/othervm/policy=security.policy
  *     -Djava.rmi.server.useCodebaseOnly=false ClassPathCodebase
  */
@@ -48,8 +48,9 @@
 
 public class ClassPathCodebase {
 
-    /** wait 10 seconds for the registry process to be ready to call */
-    private final static long REGISTRY_WAIT = 15000;
+    /** wait dozens of seconds for the registry process to be ready to call */
+    private static final long REGISTRY_WAIT =
+            (long)(10000 * TestLibrary.getTimeoutFactor());
 
     private final static String dummyClassName = "Dummy";
 
@@ -64,7 +65,7 @@
 
         TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
 
-        Process rmiregistry = null;
+        RegistryVM rmiregistry = null;
 
         try {
             /*
@@ -82,27 +83,13 @@
              * Spawn an rmiregistry in the "import" codebase directory.
              */
             File rmiregistryDir =
-                new File(System.getProperty("user.dir", "."), importCodebase);
-
-            String rmiregistryCommand =
-                System.getProperty("java.home") + File.separator +
-                "bin" + File.separator + "rmiregistry";
-
-            int port = TestLibrary.getUnusedRandomPort();
-            String cmdarray[] = new String[] {
-                rmiregistryCommand,
-                "-J-Denv.class.path=.",
-                "-J-Djava.rmi.server.codebase=" + exportCodebaseURL,
-                Integer.toString(port) };
-
-            System.err.println("\nCommand used to spawn rmiregistry process:");
-            System.err.println("\t" + Arrays.asList(cmdarray).toString());
-
-            rmiregistry = Runtime.getRuntime().exec(cmdarray, null, rmiregistryDir);
-
-            // pipe rmiregistry output to our output, for debugging failures
-            StreamPipe.plugTogether(rmiregistry.getInputStream(), System.err);
-            StreamPipe.plugTogether(rmiregistry.getErrorStream(), System.err);
+                  new File(System.getProperty("user.dir", "."), importCodebase);
+            rmiregistry = RegistryVM.createRegistryVMWithRunner("RMIRegistryRunner",
+                            " -Denv.class.path=."
+                            + " -Djava.rmi.server.codebase=" + exportCodebaseURL
+                            + " -Duser.dir=" + rmiregistryDir.getAbsolutePath());
+            rmiregistry.start();
+            int port = rmiregistry.getPort();
 
             /*
              * Wait for the registry to initialize and be ready to call.
@@ -174,7 +161,7 @@
             throw new RuntimeException("TEST FAILED: " + e.toString());
         } finally {
             if (rmiregistry != null) {
-                rmiregistry.destroy();
+                rmiregistry.cleanup();
             }
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/rmi/registry/classPathCodebase/registry.security.policy	Thu Jan 12 10:10:32 2017 -0800
@@ -0,0 +1,18 @@
+/*
+ * security policy used by the registry process started by RegistryVM.
+ */
+
+grant {
+  permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry";
+  permission java.util.PropertyPermission "env.class.path", "read";
+  permission java.io.FilePermission ".", "read";
+  permission java.util.PropertyPermission "user.dir", "read";
+  permission java.lang.RuntimePermission "createClassLoader";
+  permission java.lang.RuntimePermission "setContextClassLoader";
+  permission java.io.FilePermission ".-Djava.rmi.server.codebase=file", "read";
+  permission java.io.FilePermission ".${/}-", "read";
+  permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server";
+  permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport";
+  permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp";
+  permission java.net.SocketPermission "*:1024-", "listen,resolve,connect,accept";
+};
--- a/test/java/rmi/registry/classPathCodebase/security.policy	Thu Jan 12 18:02:48 2017 +0000
+++ b/test/java/rmi/registry/classPathCodebase/security.policy	Thu Jan 12 10:10:32 2017 -0800
@@ -18,6 +18,12 @@
   // test needs to use java to exec an rmiregistry
   permission java.io.FilePermission "${java.home}${/}bin${/}-", "execute";
 
-  // test needs to communicate with this its registry
+  // test needs to communicate with its registry
   permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+
+  permission java.util.PropertyPermission "java.security.policy", "read";
+  permission java.util.PropertyPermission "java.security.manager", "read";
+
+  // used by TestLibrary to determine extra commandline properties
+  permission java.io.FilePermission "..${/}..${/}test.props", "read";
 };