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

Print this page

        

@@ -31,13 +31,12 @@
  * @build TestLibrary Echo EchoImpl EchoImpl_Stub
  * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory
  */
 
 import java.io.*;
+import java.net.MalformedURLException;
 import java.rmi.*;
-import java.rmi.activation.*;
-import java.rmi.server.*;
 import java.rmi.registry.*;
 
 public class UseCustomSocketFactory {
     static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort();
 

@@ -49,11 +48,11 @@
 
         TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
 
         try {
             LocateRegistry.createRegistry(REGISTRY_PORT);
-        } catch (Exception e) {
+        } catch (RemoteException e) {
             TestLibrary.bomb("creating registry", e);
         }
 
         RMID rmid = null;
 

@@ -90,35 +89,35 @@
                                          " -Djava.rmi.activation.port=" +
                                          rmidPort,
                                          protocol[i]);
 
             System.err.println("\nusing protocol: " +
-                               (protocol[i] == "" ? "none" : protocol[i]));
+                    ("".equals(protocol[i]) ? "none" : protocol[i]));
 
             try {
                 /* spawn VM for EchoServer */
                 serverVM.start();
 
                 /* lookup server */
-                int tries = 12;        // need enough tries for slow machine.
                 echo[i] = null;
+                // 24 seconds timeout
+                long stopTime = System.currentTimeMillis() + 24000;
                 do {
                     try {
                         echo[i] = (Echo) Naming.lookup("//:" + REGISTRY_PORT +
                                                        "/EchoServer");
                         break;
                     } catch (NotBoundException e) {
                         try {
-                            Thread.sleep(2000);
-                        } catch (Exception ignore) {
+                            Thread.sleep(200);
+                        } catch (InterruptedException ignore) {
                         }
-                        continue;
                     }
-                } while (--tries > 0);
+                } while (System.currentTimeMillis() < stopTime);             
 
                 if (echo[i] == null)
-                    TestLibrary.bomb("server not bound in 12 tries", null);
+                    TestLibrary.bomb("server not bound in 120 tries", null);
 
                 /* invoke remote method and print result*/
                 System.err.println("Bound to " + echo[i]);
                 byte[] data = ("Greetings, citizen " +
                                System.getProperty("user.name") + "!"). getBytes();

@@ -133,13 +132,12 @@
 
             } finally {
                 serverVM.destroy();
                 try {
                     Naming.unbind("//:" + REGISTRY_PORT + "/EchoServer");
-                } catch (Exception e) {
+                } catch (RemoteException | NotBoundException | MalformedURLException e) {
                     TestLibrary.bomb("unbinding EchoServer", e);
-
                 }
             }
         }
         return echo;
     }

@@ -150,11 +148,11 @@
         System.err.println("\nReactivate Test-->");
 
         for (int i = 0; i < echo.length; i++) {
             try {
                 System.err.println("\nusing protocol: " +
-                                   (protocol[i] == "" ? "none" : protocol[i]));
+                           ("".equals(protocol[i]) ? "none" : protocol[i]));
                 byte[] data = ("Greetings, citizen " +
                                System.getProperty("user.name") + "!").getBytes();
                 byte[] result = echo[i].echoNot(data);
                 for (int j = 0; j < result.length; j++)
                     result[j] = (byte) ~result[j];