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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 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.

@@ -44,18 +44,21 @@
 
 public class UseCustomSocketFactory {
 
     public static void main(String[] args) {
 
+        int registryPort = -1;
+
         String[] protocol = new String[] { "", "compress", "xor" };
 
         System.out.println("\nRegression test for bug 4127826\n");
 
         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
 
         try {
-            LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT);
+            Registry registry = TestLibrary.createRegistryOnUnusedPort();
+            registryPort = TestLibrary.getRegistryPort(registry);
         } catch (Exception e) {
             TestLibrary.bomb("creating registry", e);
         }
 
         for (int i = 0; i < protocol.length; i++) {

@@ -63,11 +66,13 @@
             System.err.println("test policy: " +
                                TestParams.defaultPolicy);
 
             JavaVM serverVM = new JavaVM("EchoImpl",
                                          "-Djava.security.policy=" +
-                                         TestParams.defaultPolicy,
+                                         TestParams.defaultPolicy +
+                                         " -Drmi.registry.port=" +
+                                         registryPort,
                                          protocol[i]);
             System.err.println("\nusing protocol: " +
                                (protocol[i] == "" ? "none" : protocol[i]));
 
             try {

@@ -77,11 +82,11 @@
                 /* lookup server */
                 int tries = 8;
                 Echo obj = null;
                 do {
                     try {
-                        obj = (Echo) Naming.lookup("//:" + TestLibrary.REGISTRY_PORT +
+                        obj = (Echo) Naming.lookup("//:" + registryPort +
                                                    "/EchoServer");
                         break;
                     } catch (NotBoundException e) {
                         try {
                             Thread.sleep(2000);

@@ -107,11 +112,11 @@
                 TestLibrary.bomb("test failed", e);
 
             } finally {
                 serverVM.destroy();
                 try {
-                    Naming.unbind("//:" + TestLibrary.REGISTRY_PORT +
+                    Naming.unbind("//:" + registryPort +
                                   "/EchoServer");
                 } catch (Exception e) {
                     TestLibrary.bomb("unbinding EchoServer", e);
 
                 }