test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, 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
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -28,11 +28,11 @@
  * java.rmi.server.codebase property, not the list of "file:" URLs for the
  * actual elements of the CLASSPATH.
  * @author Peter Jones
  *
  * @library ../../testlibrary
- * @build ClassPathCodebase Dummy
+ * @build ClassPathCodebase Dummy TestLibrary
  * @run main/othervm/policy=security.policy ClassPathCodebase
  */
 
 import java.io.*;
 import java.net.*;

@@ -81,15 +81,16 @@
 
             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(TestLibrary.REGISTRY_PORT) };
+                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);

@@ -116,11 +117,11 @@
             /*
              * Find the registry that we created and bind the
              * dummy object to it.
              */
             Registry registry = LocateRegistry.getRegistry(
-                "localhost", TestLibrary.REGISTRY_PORT);
+                "localhost", port);
 
             try {
                 registry.bind(dummyBinding, dummyObject);
                 System.err.println("Bound dummy object in registry");
             } catch (java.rmi.ConnectException e) {

@@ -131,11 +132,11 @@
                     ((UnmarshalException) e.detail).detail instanceof
                         ClassNotFoundException)
                 {
                     System.err.println(
                         "Error: another registry running on port " +
-                        TestLibrary.REGISTRY_PORT + "?");
+                        port + "?");
                 }
                 throw e;
             }
 
             /*