test/java/rmi/transport/closeServerSocket/CloseServerSocket.java

Print this page

        

@@ -28,11 +28,12 @@
  * RMIServerSocketFactory value (including null) have been unexported,
  * the server socket created for the exports should be closed (so that
  * the local port is released).
  * @author Peter Jones
  *
- * @build CloseServerSocket
+ * @library ../../testlibrary
+ * @build CloseServerSocket TestLibrary
  * @run main/othervm CloseServerSocket
  */
 
 import java.io.IOException;
 import java.net.BindException;

@@ -42,12 +43,11 @@
 import java.rmi.registry.Registry;
 import java.rmi.server.RMIServerSocketFactory;
 import java.rmi.server.UnicastRemoteObject;
 
 public class CloseServerSocket implements Remote {
-
-    private static final int PORT = 2020;
+    private static final int PORT = TestLibrary.getUnusedRandomPort();
 
     private CloseServerSocket() { }
 
     public static void main(String[] args) throws Exception {
         System.err.println("\nRegression test for bug 4457683\n");

@@ -86,11 +86,11 @@
 
         System.err.println("TEST PASSED");
     }
 
     private static void verifyPortFree(int port) throws IOException {
-        ServerSocket ss = new ServerSocket(PORT);
+        ServerSocket ss = new ServerSocket(port);
         ss.close();
         System.err.println("- port " + port + " is free");
     }
 
     private static void verifyPortInUse(int port) throws IOException {