From 9e0c46f629db2d8edbca774ae2e742c95e0763c0 Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Thu, 5 Mar 2015 17:04:47 +0000 Subject: [PATCH] 8005226: java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java fails intermittently Reviewed-by: rriggs, smarks --- jdk/test/java/rmi/testlibrary/TestLibrary.java | 10 ++++++++++ .../pinClientSocketFactory/PinClientSocketFactory.java | 8 +++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jdk/test/java/rmi/testlibrary/TestLibrary.java b/jdk/test/java/rmi/testlibrary/TestLibrary.java index a8077ed8207..ff6c5c506c8 100644 --- a/jdk/test/java/rmi/testlibrary/TestLibrary.java +++ b/jdk/test/java/rmi/testlibrary/TestLibrary.java @@ -412,6 +412,16 @@ public class TestLibrary { return LocateRegistry.createRegistry(getUnusedRandomPort()); } + /** + * Creates an RMI {@link Registry} on an ephemeral port. + * + * @returns an RMI Registry + * @throws RemoteException if there was a problem creating a Registry. + */ + public static Registry createRegistryOnEphemeralPort() throws RemoteException { + return LocateRegistry.createRegistry(0); + } + /** * Returns the port number the RMI {@link Registry} is running on. * diff --git a/jdk/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java b/jdk/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java index 99357ffdb0b..51dc4c849b4 100644 --- a/jdk/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java +++ b/jdk/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java @@ -58,7 +58,6 @@ import java.util.concurrent.atomic.AtomicInteger; public class PinClientSocketFactory { - private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int SESSIONS = 50; public interface Factory extends Remote { @@ -96,10 +95,13 @@ public class PinClientSocketFactory { } UnicastRemoteObject.unexportObject(factoryImpl, true); - Registry registryImpl = LocateRegistry.createRegistry(PORT); + Registry registryImpl = TestLibrary.createRegistryOnEphemeralPort(); + int port = TestLibrary.getRegistryPort(registryImpl); + System.out.println("Registry listening on port " + port); + CSF csf = new CSF(); Reference registryRef = new WeakReference(csf); - Registry registryStub = LocateRegistry.getRegistry("", PORT, csf); + Registry registryStub = LocateRegistry.getRegistry("", port, csf); csf = null; registryStub.list(); registryStub = null;