8153543: java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java fails intermittently
authormli
Tue, 22 Nov 2016 01:37:18 -0800
changeset 42183 6b4cdd4a4609
parent 42182 293b784c607e
child 42184 6965d53e507c
8153543: java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java fails intermittently Reviewed-by: chegar
jdk/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java
--- a/jdk/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java	Tue Nov 22 08:22:57 2016 +0000
+++ b/jdk/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java	Tue Nov 22 01:37:18 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2016, 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
@@ -53,7 +53,7 @@
 
 public class ReuseDefaultPort implements Remote {
 
-    private static final int PORT = TestLibrary.getUnusedRandomPort();
+    private static int rmiPort = 0;
 
     private ReuseDefaultPort() { }
 
@@ -64,7 +64,7 @@
         Remote stub = UnicastRemoteObject.exportObject(impl, 0);
         System.err.println("- exported object: " + stub);
         try {
-            Registry registry = LocateRegistry.createRegistry(PORT);
+            Registry registry = LocateRegistry.createRegistry(rmiPort);
             System.err.println("- exported registry: " + registry);
             System.err.println("TEST PASSED");
         } finally {
@@ -77,13 +77,15 @@
             RMISocketFactory.getDefaultSocketFactory();
         SF() { }
         public Socket createSocket(String host, int port) throws IOException {
+            System.err.format("in SF::createSocket: %s, %d%n", host, port);
             return defaultFactory.createSocket(host, port);
         }
         public ServerSocket createServerSocket(int port) throws IOException {
-            if (port == 0) {
-                port = PORT;
-            }
-            return defaultFactory.createServerSocket(port);
+            System.err.format("in SF::createServerSocket: %d%n", port);
+            ServerSocket server = defaultFactory.createServerSocket(port);
+            rmiPort = server.getLocalPort();
+            System.err.println("rmiPort: " + rmiPort);
+            return server;
         }
     }
 }