< prev index next >

test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java

Print this page

        

@@ -41,22 +41,23 @@
 import java.net.MalformedURLException;
 import java.rmi.*;
 import java.rmi.registry.*;
 
 public class UseCustomSocketFactory {
-    static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
+    static int registryPort = -1;
 
     static String[] protocol = new String[] { "", "compress", "xor" };
 
     public static void main(String[] args) {
 
         System.out.println("\nRegression test for bug 4115696\n");
 
         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
 
         try {
-            LocateRegistry.createRegistry(REGISTRY_PORT);
+            Registry reg = LocateRegistry.createRegistry(0);
+            registryPort = TestLibrary.getRegistryPort(reg);
         } catch (RemoteException e) {
             TestLibrary.bomb("creating registry", e);
         }
 
         RMID rmid = null;

@@ -88,11 +89,11 @@
         for (int i = 0; i < protocol.length; i++) {
             JavaVM serverVM = new JavaVM("EchoImpl",
                                          "-Djava.security.policy=" +
                                          TestParams.defaultPolicy +
                                          " -Drmi.registry.port=" +
-                                         REGISTRY_PORT +
+                                         registryPort +
                                          " -Djava.rmi.activation.port=" +
                                          rmidPort,
                                          protocol[i]);
 
             System.err.println("\nusing protocol: " +

@@ -106,11 +107,11 @@
                 echo[i] = null;
                 // 24 seconds timeout
                 long stopTime = System.currentTimeMillis() + 24000;
                 do {
                     try {
-                        echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT +
+                        echo[i] = (Echo) Naming.lookup("//:" + registryPort +
                                                        "/EchoServer");
                         break;
                     } catch (NotBoundException e) {
                         try {
                             Thread.sleep(200);

@@ -136,11 +137,11 @@
                 TestLibrary.bomb("test failed", e);
 
             } finally {
                 serverVM.destroy();
                 try {
-                    Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
+                    Naming.unbind("//:" + registryPort + "/EchoServer");
                 } catch (RemoteException | NotBoundException | MalformedURLException e) {
                     TestLibrary.bomb("unbinding EchoServer", e);
                 }
             }
         }
< prev index next >