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

Print this page

        

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

@@ -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 {