test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java

Print this page

        

@@ -26,36 +26,36 @@
  * @summary synopsis: unexporting doesn't guarantee that DGC will
  * let go of remote object
  *
  * @author Ann Wollrath
  *
+ * @library ../../../testlibrary
  * @build UnexportLeak
  * @build UnexportLeak_Stub
+ * @build TestLibrary
  * @build Ping
  * @run main/othervm UnexportLeak
  */
 
 import java.lang.ref.*;
 import java.rmi.*;
 import java.rmi.server.*;
 import java.rmi.registry.*;
 
 public class UnexportLeak implements Ping {
-
-    private static int PORT = 2006;
-
     public void ping() {
     }
 
     public static void main(String[] args) {
         try {
             System.err.println("\nRegression test for bug 4331349\n");
-            LocateRegistry.createRegistry(PORT);
+            Registry registry = TestLibrary.createRegistryOnUnusedPort();
+            int registryPort = TestLibrary.getRegistryPort(registry);
             Remote obj = new UnexportLeak();
             WeakReference wr = new WeakReference(obj);
             UnicastRemoteObject.exportObject(obj);
-            LocateRegistry.getRegistry(PORT).rebind("UnexportLeak", obj);
+            LocateRegistry.getRegistry(registryPort).rebind("UnexportLeak", obj);
             UnicastRemoteObject.unexportObject(obj, true);
             obj = null;
             flushRefs();
             if (wr.get() != null) {
                 System.err.println("FAILED: unexported object not collected");