From e57ac292fb0ee988119fa38a8f2aa34347cf22d3 Mon Sep 17 00:00:00 2001 From: dmocek Date: Tue, 17 Jul 2012 11:01:44 -0700 Subject: [PATCH] 7142596: RMI JPRT tests are failing Summary: Changed RMI tests to use random port numbers for the RMI Registry and RMID so the tests can be run concurrently without test failures due to tests using the same port numbers. Reviewed-by: smarks, alanb Contributed-by: olivier.lagneau@oracle.com --- test/ProblemList.txt | 10 -- test/TEST.ROOT | 2 +- .../ContextWithNullProperties.java | 22 ++- .../RegistryContext/UnbindIdempotent.java | 45 ++++-- test/java/rmi/Naming/LookupNameWithColon.java | 18 +-- test/java/rmi/Naming/RmiIsNoScheme.java | 12 +- test/java/rmi/Naming/UnderscoreHost.java | 71 +++++----- .../LegalRegistryNames.java | 6 +- .../checkActivateRef/security.policy | 3 +- .../checkAnnotations/security.policy | 3 +- .../checkImplClassLoader/security.policy | 3 +- .../checkRegisterInLog/security.policy | 5 +- .../createPrivateActivable/security.policy | 3 +- .../downloadParameterClass/security.policy | 3 +- .../elucidateNoSuchMethod/security.policy | 3 +- .../Activatable/extLoadedImpl/security.policy | 3 +- .../forceLogSnapshot/security.policy | 3 +- .../Activatable/inactiveGroup/security.policy | 5 +- .../LookupActivationSystem.java | 4 +- .../nestedActivate/security.policy | 5 +- .../nonExistentActivatable/security.policy | 3 +- .../restartCrashedService/security.policy | 3 +- .../restartLatecomer/security.policy | 3 +- .../restartService/security.policy | 3 +- .../shutdownGracefully/security.policy | 3 +- .../unregisterInactive/security.policy | 3 +- .../activateFails/security.policy | 3 +- .../activeGroup/security.policy | 3 +- .../modifyDescriptor/security.policy | 3 +- .../StubClassesPermitted.java | 10 +- .../stubClassesPermitted/security.policy | 9 +- .../unregisterGroup/UnregisterGroup.java | 9 +- .../unregisterGroup/security.policy | 3 +- .../CommandEnvironment/SetChildEnv.java | 37 +++-- .../CommandEnvironment/security.policy | 1 + .../InheritedChannelNotServerSocket.java | 20 +-- .../RmidViaInheritedChannel.java | 23 +-- .../rmid.security.policy | 1 + .../AltSecurityManager.java | 45 ++++-- .../classPathCodebase/ClassPathCodebase.java | 11 +- .../rmi/registry/emptyName/EmptyName.java | 6 +- .../registry/interfaceHash/InterfaceHash.java | 6 +- .../MultipleRegistries.java | 15 +- test/java/rmi/registry/readTest/readTest.java | 9 +- test/java/rmi/registry/readTest/readTest.sh | 12 +- test/java/rmi/registry/reexport/Reexport.java | 25 ++-- .../rmi/reliability/juicer/AppleUserImpl.java | 22 +-- .../reliability/juicer/ApplicationServer.java | 27 +++- .../activatable/EchoImpl.java | 7 +- .../activatable/UseCustomSocketFactory.java | 16 ++- .../activatable/security.policy | 3 + .../useSocketFactory/registry/HelloImpl.java | 5 +- .../registry/UseCustomSocketFactory.java | 14 +- .../useSocketFactory/registry/security.policy | 2 + .../useSocketFactory/unicast/EchoImpl.java | 5 +- .../unicast/UseCustomSocketFactory.java | 15 +- .../useSocketFactory/unicast/security.policy | 9 ++ .../rmi/server/RemoteServer/AddrInUse.java | 12 +- .../KeepAliveDuringCall.java | 10 +- .../keepAliveDuringCall/ShutdownImpl.java | 5 +- .../unexportObject/UnexportLeak.java | 12 +- .../finiteGCLatency/FiniteGCLatency.java | 9 +- .../LeaseCheckInterval.java | 8 +- .../leaseCheckInterval/SelfTerminator.java | 6 +- .../UnreferencedContext.java | 8 +- .../rmi/server/useCustomRef/UseCustomRef.java | 8 +- .../rmi/server/useCustomRef/security.policy | 3 + .../rmi/testlibrary/ActivationLibrary.java | 39 +----- test/java/rmi/testlibrary/RMID.java | 25 ++-- test/java/rmi/testlibrary/RegistryRunner.java | 9 +- test/java/rmi/testlibrary/StreamPipe.java | 6 +- test/java/rmi/testlibrary/TestLibrary.java | 132 ++++++++++++++++-- .../rmi/transport/checkFQDN/CheckFQDN.java | 13 +- .../transport/checkFQDN/CheckFQDNClient.java | 5 +- .../checkLeaseInfoLeak/CheckLeaseLeak.java | 13 +- .../checkLeaseInfoLeak/LeaseLeakClient.java | 6 +- .../checkLeaseInfoLeak/security.policy | 1 + .../closeServerSocket/CloseServerSocket.java | 10 +- .../transport/dgcDeadLock/DGCDeadLock.java | 13 +- .../rmi/transport/dgcDeadLock/TestImpl.java | 10 +- .../handshakeFailure/HandshakeFailure.java | 7 +- .../handshakeTimeout/HandshakeTimeout.java | 7 +- .../transport/httpSocket/HttpSocketTest.java | 16 +-- .../rmi/transport/httpSocket/security.policy | 4 + .../PinClientSocketFactory.java | 6 +- .../RapidExportUnexport.java | 9 +- .../reuseDefaultPort/ReuseDefaultPort.java | 7 +- .../newrmic/equivalence/AppleUserImpl.java | 17 +-- test/sun/rmi/rmic/newrmic/equivalence/run.sh | 4 +- .../runtime/Log/6409194/NoConsoleOutput.java | 8 +- .../Log/checkLogging/CheckLogging.java | 11 +- .../transport/proxy/EagerHttpFallback.java | 8 +- .../transport/tcp/DeadCachedConnection.java | 4 +- 93 files changed, 682 insertions(+), 412 deletions(-) diff --git a/test/ProblemList.txt b/test/ProblemList.txt index af875d9fb..2128aaeab 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -158,9 +158,6 @@ java/lang/Math/WorstCaseTests.java generic-all # 6988950 demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all -# Need to be marked othervm, or changed to be samevm safe -com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all - # 7162111 demo/jvmti/mtrace/TraceJFrame.java macosx-all javax/script/CauseExceptionTest.java macosx-all @@ -265,18 +262,11 @@ java/nio/channels/Selector/OutOfBand.java macosx-all # jdk_rmi -# 7140992 -java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java generic-all - # 7146541 java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java linux-all # 7132247 java/rmi/registry/readTest/readTest.sh windows-all - -# 7142596 -java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java generic-all - ############################################################################ # jdk_security diff --git a/test/TEST.ROOT b/test/TEST.ROOT index 8aa398f60..e6d8dfca6 100644 --- a/test/TEST.ROOT +++ b/test/TEST.ROOT @@ -9,4 +9,4 @@ keys=2d dnd i18n othervm.dirs=java/rmi sun/rmi javax/management # Tests that cannot run concurrently -exclusiveAccess.dirs=java/rmi sun/rmi sun/management/jmxremote sun/tools/jstatd +exclusiveAccess.dirs=java/rmi/Naming sun/management/jmxremote sun/tools/jstatd diff --git a/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java b/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java index f8706df0c..3dd724814 100644 --- a/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java +++ b/test/com/sun/jndi/rmi/registry/RegistryContext/ContextWithNullProperties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -25,26 +25,22 @@ * @test * @bug 6676075 * @summary RegistryContext (com.sun.jndi.url.rmi.rmiURLContext) coding problem + * @library ../../../../../../java/rmi/testlibrary + * @build TestLibrary + * @run main ContextWithNullProperties */ +import com.sun.jndi.rmi.registry.RegistryContextsun.jndi.rmi.RegistryContext; import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; - -import com.sun.jndi.rmi.registry.*; +import java.rmi.registry.Registry; public class ContextWithNullProperties { - public static void main(String[] args) throws Exception { - - // Create registry on port 1099 if one is not already running. - try { - LocateRegistry.createRegistry(1099); - } catch (RemoteException e) { - } - + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); System.out.println("Connecting to the default Registry..."); // Connect to the default Registry. // Pass null as the JNDI environment properties (see final argument) - RegistryContext ctx = new RegistryContext(null, -1, null); + RegistryContext ctx = new RegistryContext(null, registryPort, null); } } diff --git a/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java b/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java index 35753b82d..9ff1d0162 100644 --- a/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java +++ b/test/com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java @@ -1,26 +1,51 @@ +/* + * Copyright (c) 2007, 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + /* * @test * @bug 4278121 * @summary Ensure that calling unbind() on an unbound name returns * successfully. + * @library ../../../../../../java/rmi/testlibrary + * @build TestLibrary + * @run main UnbindIdempotent */ -import javax.naming.*; +import java.rmi.registry.Registry; +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NamingException; public class UnbindIdempotent { public static void main(String[] args) throws Exception { - - // Create registry on port 1099 if one is not already running. - try { - java.rmi.registry.LocateRegistry.createRegistry(1099); - } catch (java.rmi.RemoteException e) { - } - - Context ictx = new InitialContext(); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + InitialContext ictx = new InitialContext(); Context rctx; + try { - rctx = (Context)ictx.lookup("rmi://localhost:1099"); + rctx = (Context)ictx.lookup("rmi://localhost:" + Integer.toString(registryPort)); } catch (NamingException e) { // Unable to set up for test. return; diff --git a/test/java/rmi/Naming/LookupNameWithColon.java b/test/java/rmi/Naming/LookupNameWithColon.java index 15b9663ee..e3865fd12 100644 --- a/test/java/rmi/Naming/LookupNameWithColon.java +++ b/test/java/rmi/Naming/LookupNameWithColon.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -25,10 +25,13 @@ * @bug 4387038 * @summary Ensure that java.rmi.Naming.lookup functions properly for names * containing embedded ':' characters. + * + * @library ../testlibrary + * @build TestLibrary + * @run main LookupNameWithColon */ import java.rmi.Naming; -import java.rmi.registry.LocateRegistry; import java.rmi.registry.Registry; public class LookupNameWithColon { @@ -38,15 +41,12 @@ public class LookupNameWithColon { "multiple:colons:in:name" }; - Registry reg; - try { - reg = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); - } catch (Exception ex) { - reg = LocateRegistry.getRegistry(); - } + Registry reg = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(reg); + for (int i = 0; i < names.length; i++) { reg.rebind(names[i], reg); - Naming.lookup("rmi://localhost/" + names[i]); + Naming.lookup("rmi://localhost:" + port + "/" + names[i]); } } } diff --git a/test/java/rmi/Naming/RmiIsNoScheme.java b/test/java/rmi/Naming/RmiIsNoScheme.java index 9edebe33a..865a07c99 100644 --- a/test/java/rmi/Naming/RmiIsNoScheme.java +++ b/test/java/rmi/Naming/RmiIsNoScheme.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -39,9 +39,6 @@ import java.rmi.*; import java.rmi.registry.*; public class RmiIsNoScheme implements Remote, Serializable { - - private static final int REGISTRY_PORT = 2002; - private RmiIsNoScheme() {} public static void main(String[] args) { @@ -49,10 +46,11 @@ public class RmiIsNoScheme implements Remote, Serializable { System.err.println("\nRegression test for bug 4626311\n"); try { - LocateRegistry.createRegistry(REGISTRY_PORT); - Naming.rebind("//:" + REGISTRY_PORT + "/RmiIsNoScheme", + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + Naming.rebind("//:" + registryPort + "/RmiIsNoScheme", new RmiIsNoScheme()); - String name = Naming.list("//:" + REGISTRY_PORT)[0]; + String name = Naming.list("//:" + registryPort)[0]; System.err.println("name = " + name); if (name.startsWith("rmi:", 0) == false) { System.err.println("TEST PASSED: rmi scheme not present"); diff --git a/test/java/rmi/Naming/UnderscoreHost.java b/test/java/rmi/Naming/UnderscoreHost.java index 1dd81c3f2..0d7375693 100644 --- a/test/java/rmi/Naming/UnderscoreHost.java +++ b/test/java/rmi/Naming/UnderscoreHost.java @@ -1,37 +1,37 @@ -/* - * Copyright (c) 2005, 2006, 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. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ + /* + * 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. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ -/* - * @test - * @bug 5083594 - * @summary Ensure that Naming.java correctly parses host names with '_' in - * them. - * @author Vinod Johnson - * - * @library ../testlibrary - * @build TestLibrary - * @build UnderscoreHost UnderscoreHost_Stub - * @run main/othervm UnderscoreHost + /* + * @test + * @bug 5083594 + * @summary Ensure that Naming.java correctly parses host names with '_' in + * them. + * @author Vinod Johnson + * + * @library ../testlibrary + * @build TestLibrary + * @build UnderscoreHost UnderscoreHost_Stub + * @run main/othervm UnderscoreHost */ import java.io.IOException; @@ -77,11 +77,12 @@ public class UnderscoreHost extends UnicastRemoteObject implements Remote { try { HostVerifyingSocketFactory hvf = new HostVerifyingSocketFactory(); RMISocketFactory.setSocketFactory(hvf); - Registry r = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); + Registry r = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(r); t = new UnderscoreHost(); r.rebind(NAME, t); Naming.lookup("rmi://" + HOSTNAME + - ":" + Registry.REGISTRY_PORT + "/" + NAME); + ":" + port + "/" + NAME); /* * This test is coded to pass whether java.net.URI obeys * RFC 2396 or RFC 3986 (see 5085902, 6394131, etc.). diff --git a/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java b/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java index 8ac8bdb82..0d367974b 100644 --- a/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java +++ b/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -45,7 +45,9 @@ import java.util.Vector; /** * Ensure that all legal forms of Naming URLs operate with the - * java.rmi.Naming interface + * java.rmi.Naming interface. This test requires using the default RMI Registry + * port as it tests all of the RMI naming URL's, including the ones which do not + * take a port (and therefore uses the default port). */ public class LegalRegistryNames extends UnicastRemoteObject implements Legal diff --git a/test/java/rmi/activation/Activatable/checkActivateRef/security.policy b/test/java/rmi/activation/Activatable/checkActivateRef/security.policy index 078b8a76a..f33bc8511 100644 --- a/test/java/rmi/activation/Activatable/checkActivateRef/security.policy +++ b/test/java/rmi/activation/Activatable/checkActivateRef/security.policy @@ -29,11 +29,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/checkAnnotations/security.policy b/test/java/rmi/activation/Activatable/checkAnnotations/security.policy index b6e691b60..e13da7fa2 100644 --- a/test/java/rmi/activation/Activatable/checkAnnotations/security.policy +++ b/test/java/rmi/activation/Activatable/checkAnnotations/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy b/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy index 8b7ec7c17..b66dd8c46 100644 --- a/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy +++ b/test/java/rmi/activation/Activatable/checkImplClassLoader/security.policy @@ -32,11 +32,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy b/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy index d1d1b6268..f78e1068d 100644 --- a/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy +++ b/test/java/rmi/activation/Activatable/checkRegisterInLog/security.policy @@ -21,17 +21,18 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting object with non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; diff --git a/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy b/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy index e6178a5b2..f78e1068d 100644 --- a/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy +++ b/test/java/rmi/activation/Activatable/createPrivateActivable/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy b/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy index e4948a96f..657881b33 100644 --- a/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy +++ b/test/java/rmi/activation/Activatable/downloadParameterClass/security.policy @@ -31,11 +31,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; diff --git a/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy b/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy index ede8bd032..3d1c7693e 100644 --- a/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy +++ b/test/java/rmi/activation/Activatable/elucidateNoSuchMethod/security.policy @@ -30,11 +30,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy b/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy index c5b33d9d8..7eb307200 100644 --- a/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy +++ b/test/java/rmi/activation/Activatable/extLoadedImpl/security.policy @@ -17,11 +17,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; diff --git a/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy b/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy index e6178a5b2..f78e1068d 100644 --- a/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy +++ b/test/java/rmi/activation/Activatable/forceLogSnapshot/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/inactiveGroup/security.policy b/test/java/rmi/activation/Activatable/inactiveGroup/security.policy index d1d1b6268..f78e1068d 100644 --- a/test/java/rmi/activation/Activatable/inactiveGroup/security.policy +++ b/test/java/rmi/activation/Activatable/inactiveGroup/security.policy @@ -21,17 +21,18 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting object with non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; diff --git a/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java b/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java index 03d3c1738..eee264f29 100644 --- a/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java +++ b/test/java/rmi/activation/Activatable/lookupActivationSystem/LookupActivationSystem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -58,7 +58,7 @@ public class LookupActivationSystem implements Remote, Serializable { System.err.println("look up activation system"); Registry rmidRegistry = - LocateRegistry.getRegistry(ActivationSystem.SYSTEM_PORT); + LocateRegistry.getRegistry(rmid.getPort()); ActivationSystem system = (ActivationSystem) rmidRegistry.lookup(NAME); diff --git a/test/java/rmi/activation/Activatable/nestedActivate/security.policy b/test/java/rmi/activation/Activatable/nestedActivate/security.policy index c08ff330c..7972e5c59 100644 --- a/test/java/rmi/activation/Activatable/nestedActivate/security.policy +++ b/test/java/rmi/activation/Activatable/nestedActivate/security.policy @@ -21,17 +21,18 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; // allow exporting of remote objects on an arbitrary port. - permission java.net.SocketPermission "*:1024-", "connect,accept"; + permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; // allow exporting of non-public remote interface permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe"; diff --git a/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy b/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy index 63f230676..99feddab0 100644 --- a/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy +++ b/test/java/rmi/activation/Activatable/nonExistentActivatable/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/restartCrashedService/security.policy b/test/java/rmi/activation/Activatable/restartCrashedService/security.policy index fe05fcad4..881781b1c 100644 --- a/test/java/rmi/activation/Activatable/restartCrashedService/security.policy +++ b/test/java/rmi/activation/Activatable/restartCrashedService/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/Activatable/restartLatecomer/security.policy b/test/java/rmi/activation/Activatable/restartLatecomer/security.policy index a96acd772..0e70b29b6 100644 --- a/test/java/rmi/activation/Activatable/restartLatecomer/security.policy +++ b/test/java/rmi/activation/Activatable/restartLatecomer/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Used in remote impl of Activator.inactive; by the method // "restartThread.dispose()"when it calls thread.interrupt() diff --git a/test/java/rmi/activation/Activatable/restartService/security.policy b/test/java/rmi/activation/Activatable/restartService/security.policy index a96acd772..0e70b29b6 100644 --- a/test/java/rmi/activation/Activatable/restartService/security.policy +++ b/test/java/rmi/activation/Activatable/restartService/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Used in remote impl of Activator.inactive; by the method // "restartThread.dispose()"when it calls thread.interrupt() diff --git a/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy b/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy index 6f3936136..693ce51a1 100644 --- a/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy +++ b/test/java/rmi/activation/Activatable/shutdownGracefully/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // allow exporting of remote objects on an arbitrary port. permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; diff --git a/test/java/rmi/activation/Activatable/unregisterInactive/security.policy b/test/java/rmi/activation/Activatable/unregisterInactive/security.policy index ff2ecca4f..749e1425a 100644 --- a/test/java/rmi/activation/Activatable/unregisterInactive/security.policy +++ b/test/java/rmi/activation/Activatable/unregisterInactive/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // Needed to create an activation group permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy b/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy index b6e691b60..e13da7fa2 100644 --- a/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy +++ b/test/java/rmi/activation/ActivateFailedException/activateFails/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy b/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy index a9431dc45..fe0112569 100644 --- a/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy +++ b/test/java/rmi/activation/ActivationSystem/activeGroup/security.policy @@ -15,11 +15,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; diff --git a/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy b/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy index b6e691b60..e13da7fa2 100644 --- a/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy +++ b/test/java/rmi/activation/ActivationSystem/modifyDescriptor/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java index eb4e4f06c..cc7810407 100644 --- a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java +++ b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/StubClassesPermitted.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -61,7 +61,7 @@ public class StubClassesPermitted extends Activatable implements Runnable, CanCreateStubs { public static boolean sameGroup = false; - + private static int registryPort = -1; private static CanCreateStubs canCreateStubs = null; private static Registry registry = null; @@ -76,8 +76,8 @@ public class StubClassesPermitted try { TestLibrary.suggestSecurityManager("java.lang.SecurityManager"); - registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); // must run with java.lang.SecurityManager or the test // result will be nullified if running with a build where @@ -192,7 +192,7 @@ public class StubClassesPermitted // obtain reference to the test registry registry = java.rmi.registry.LocateRegistry. - getRegistry(TestLibrary.REGISTRY_PORT); + getRegistry(registryPort); } /** diff --git a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy index b6e691b60..b6f6ef254 100644 --- a/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy +++ b/test/java/rmi/activation/ActivationSystem/stubClassesPermitted/security.policy @@ -21,15 +21,22 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; + // required for test to get the registry port + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; + // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; }; diff --git a/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java b/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java index 02cfe29c4..3f9ad4c79 100644 --- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -74,7 +74,7 @@ public class UnregisterGroup private static boolean done = false; private static ActivateMe lastResortExitObj = null; private static final int NUM_OBJECTS = 10; - private static int PORT = 2006; + private static int registryPort = -1; public UnregisterGroup(ActivationID id, MarshalledObject mobj) throws Exception @@ -116,7 +116,7 @@ public class UnregisterGroup try { CallbackInterface cobj = - (CallbackInterface)Naming.lookup("//:" + PORT + "/Callback"); + (CallbackInterface)Naming.lookup("//:" + registryPort + "/Callback"); cobj.inc(); } catch (Exception e) { System.err.println("cobj.inc exception"); @@ -235,7 +235,8 @@ public class UnregisterGroup try { // create reg and export callback object - registry = LocateRegistry.createRegistry(PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); Callback robj = new Callback(); registry.bind("Callback", robj); diff --git a/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy b/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy index b6e691b60..e13da7fa2 100644 --- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy +++ b/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy @@ -21,11 +21,12 @@ grant { permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; - // used by TestLibrary to determine test environment + // used by TestLibrary to determine test environment permission java.util.PropertyPermission "test.classes", "read"; permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java b/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java index cbee67ca4..d89450d61 100644 --- a/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java +++ b/test/java/rmi/activation/CommandEnvironment/SetChildEnv.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -53,31 +53,37 @@ public class SetChildEnv public static void main(String argv[]) throws Exception { + int runningPort = TestLibrary.getUnusedRandomPort(); + System.out.println("java.compiler=" + System.getProperty("java.compiler")); // don't embed spaces in any of the test args/props, because // they won't be parsed properly - runwith (new String[0], new String[0]); + runwith (new String[0], new String[0], runningPort); runwith ( new String[] { "-verbosegc" }, new String[] { "foo.bar=SetChildEnvTest", - "sun.rmi.server.doSomething=true" } + "sun.rmi.server.doSomething=true" }, + runningPort ); runwith ( new String[] { }, - new String[] { "parameter.count=zero" } + new String[] { "parameter.count=zero" }, + runningPort ); runwith ( new String[] { "-Xmx32m" }, - new String[] { } + new String[] { }, + runningPort ); } private static void runwith( String[] params, // extra args - String[] props // extra system properties + String[] props, // extra system properties + int port // port on which to communicate ) throws Exception { @@ -89,7 +95,8 @@ public class SetChildEnv RMID.removeLog(); RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(), - true); // debugExec turned on + true, // debugExec turned on + true, port); rmid.start(); @@ -195,7 +202,7 @@ public class SetChildEnv actsys.unregisterGroup(gid); Thread.sleep(5000); - rmid.destroy(); + ActivationLibrary.rmidCleanup(rmid); } public static class DebugExecWatcher @@ -243,7 +250,19 @@ public class SetChildEnv System.err.println(line); } } catch (IOException e) { - e.printStackTrace(); + /* During termination of distant rmid, StreamPipes will be broken when + * distant vm terminates. A "Pipe broken" exception is expected because + * DebugExecWatcher points to the same streams as StreamPipes used by RMID. + * If we get this exception. We just terminate the thread. + */ + if (e.getMessage().equals("Pipe broken")) { + try { + str.close(); + } catch (IOException ioe) {} + } + else { + e.printStackTrace(); + } } } } diff --git a/test/java/rmi/activation/CommandEnvironment/security.policy b/test/java/rmi/activation/CommandEnvironment/security.policy index 14df213a3..fd455a6cd 100644 --- a/test/java/rmi/activation/CommandEnvironment/security.policy +++ b/test/java/rmi/activation/CommandEnvironment/security.policy @@ -27,6 +27,7 @@ grant { permission java.util.PropertyPermission "test.src", "read"; permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java b/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java index 70e98c61a..345aca33a 100644 --- a/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java +++ b/test/java/rmi/activation/rmidViaInheritedChannel/InheritedChannelNotServerSocket.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 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 @@ -31,8 +31,7 @@ * @library ../../testlibrary * @build RMID ActivationLibrary * @build InheritedChannelNotServerSocket - * @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 - * InheritedChannelNotServerSocket + * @run main/othervm/timeout=240 InheritedChannelNotServerSocket */ import java.io.IOException; @@ -55,8 +54,6 @@ import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; public class InheritedChannelNotServerSocket { - - private static final int PORT = 5398; private static final Object lock = new Object(); private static boolean notified = false; @@ -79,7 +76,8 @@ public class InheritedChannelNotServerSocket { public static void main(String[] args) throws Exception { System.err.println("\nRegression test for bug 6261402\n"); - + System.setProperty("java.rmi.activation.port", + Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT)); RMID rmid = null; Callback obj = null; try { @@ -91,7 +89,8 @@ public class InheritedChannelNotServerSocket { Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0); Registry registry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry( + TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); registry.bind("Callback", proxy); /* @@ -99,7 +98,8 @@ public class InheritedChannelNotServerSocket { */ System.err.println("start rmid with inherited channel"); RMID.removeLog(); - rmid = RMID.createRMID(System.out, System.err, true, true, PORT); + rmid = RMID.createRMID(System.out, System.err, true, true, + TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT); rmid.addOptions(new String[]{ "-Djava.nio.channels.spi.SelectorProvider=" + "InheritedChannelNotServerSocket$SP"}); @@ -122,7 +122,7 @@ public class InheritedChannelNotServerSocket { if (obj != null) { UnicastRemoteObject.unexportObject(obj, true); } - ActivationLibrary.rmidCleanup(rmid, PORT); + ActivationLibrary.rmidCleanup(rmid); } } @@ -175,7 +175,7 @@ public class InheritedChannelNotServerSocket { try { System.err.println("notify test..."); Registry registry = - LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); Callback obj = (Callback) registry.lookup("Callback"); obj.notifyTest(); } catch (NotBoundException nbe) { diff --git a/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java b/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java index 170e1716d..008b391ac 100644 --- a/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java +++ b/test/java/rmi/activation/rmidViaInheritedChannel/RmidViaInheritedChannel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -29,7 +29,8 @@ * @library ../../testlibrary * @build RMID ActivationLibrary * @build RmidViaInheritedChannel - * @run main/othervm/timeout=240 -Djava.rmi.activation.port=5398 RmidViaInheritedChannel + * @build TestLibrary + * @run main/othervm/timeout=240 RmidViaInheritedChannel */ import java.io.IOException; @@ -48,8 +49,6 @@ import java.rmi.registry.Registry; import java.rmi.server.UnicastRemoteObject; public class RmidViaInheritedChannel implements Callback { - - private static final int PORT = 5398; private static final Object lock = new Object(); private static boolean notified = false; @@ -64,7 +63,8 @@ public class RmidViaInheritedChannel implements Callback { } public static void main(String[] args) throws Exception { - + System.setProperty("java.rmi.activation.port", + Integer.toString(TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT)); RMID rmid = null; Callback obj = null; @@ -77,7 +77,8 @@ public class RmidViaInheritedChannel implements Callback { Callback proxy = (Callback) UnicastRemoteObject.exportObject(obj, 0); Registry registry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry( + TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT); registry.bind("Callback", proxy); /* @@ -85,7 +86,8 @@ public class RmidViaInheritedChannel implements Callback { */ System.err.println("start rmid with inherited channel"); RMID.removeLog(); - rmid = RMID.createRMID(System.out, System.err, true, false, PORT); + rmid = RMID.createRMID(System.out, System.err, true, false, + TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT); rmid.addOptions(new String[]{ "-Djava.nio.channels.spi.SelectorProvider=RmidViaInheritedChannel$RmidSelectorProvider"}); rmid.start(); @@ -108,7 +110,7 @@ public class RmidViaInheritedChannel implements Callback { if (obj != null) { UnicastRemoteObject.unexportObject(obj, true); } - ActivationLibrary.rmidCleanup(rmid, PORT); + ActivationLibrary.rmidCleanup(rmid); } } @@ -166,7 +168,8 @@ public class RmidViaInheritedChannel implements Callback { channel = ServerSocketChannel.open(); ServerSocket serverSocket = channel.socket(); serverSocket.bind( - new InetSocketAddress(InetAddress.getLocalHost(), PORT)); + new InetSocketAddress(InetAddress.getLocalHost(), + TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT)); System.err.println("serverSocket = " + serverSocket); /* @@ -175,7 +178,7 @@ public class RmidViaInheritedChannel implements Callback { try { System.err.println("notify test..."); Registry registry = - LocateRegistry.getRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry(TestLibrary.RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT); Callback obj = (Callback) registry.lookup("Callback"); obj.notifyTest(); } catch (NotBoundException nbe) { diff --git a/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy b/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy index ceee4d7a8..9ddb55603 100644 --- a/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy +++ b/test/java/rmi/activation/rmidViaInheritedChannel/rmid.security.policy @@ -2,4 +2,5 @@ grant { permission java.lang.RuntimePermission "selectorProvider"; permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch"; permission java.net.SocketPermission "*", "connect,accept"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; }; diff --git a/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java b/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java index 2436920a7..15b98fc85 100644 --- a/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java +++ b/test/java/rmi/registry/altSecurityManager/AltSecurityManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -27,7 +27,7 @@ * @author Laird Dornin * * @library ../../testlibrary - * @build StreamPipe TestParams TestLibrary JavaVM + * @build StreamPipe TestParams TestLibrary JavaVM RMID * @build AltSecurityManager TestSecurityManager * @run main/othervm AltSecurityManager */ @@ -41,23 +41,41 @@ * if registry and rmid take too long to exit. */ public class AltSecurityManager implements Runnable { - + private final int regPort; // variable to hold registry and rmid children static JavaVM vm = null; // names of utilities static String utilityToStart = null; - static String registry = "sun.rmi.registry.RegistryImpl"; - static String rmid = "sun.rmi.server.Activation"; + static final String REGISTRY_IMPL = "sun.rmi.registry.RegistryImpl"; + static final String ACTIVATION = "sun.rmi.server.Activation"; // children should exit in at least this time. static long TIME_OUT = 15000; + public AltSecurityManager(int port) { + if (port <= 0) { + TestLibrary.bomb("Port must be greater then 0."); + } + + this.regPort = port; + } + public void run() { try { - vm = new JavaVM(utilityToStart, - " -Djava.security.manager=TestSecurityManager", - ""); + if (utilityToStart.equals(REGISTRY_IMPL)) { + vm = new JavaVM(utilityToStart, + " -Djava.security.manager=TestSecurityManager", + Integer.toString(regPort)); + } else if (utilityToStart.contains(ACTIVATION)) { + vm = new JavaVM(utilityToStart, + " -Djava.security.manager=TestSecurityManager", + "-port " + Integer.toString(regPort)); + } else { + TestLibrary.bomb("Utility to start must be " + REGISTRY_IMPL + + " or " + ACTIVATION); + } + System.err.println("starting " + utilityToStart); vm.start(); vm.getVM().waitFor(); @@ -75,7 +93,8 @@ public class AltSecurityManager implements Runnable { utilityToStart = utility; try { - Thread thread = new Thread(new AltSecurityManager()); + int port = TestLibrary.getUnusedRandomPort(); + Thread thread = new Thread(new AltSecurityManager(port)); System.err.println("expecting RuntimeException for " + "checkListen in child process"); long start = System.currentTimeMillis(); @@ -90,8 +109,8 @@ public class AltSecurityManager implements Runnable { // dont pollute other tests; increase the likelihood // that rmid will go away if it did not exit already. - if (utility.equals(rmid)) { - RMID.shutdown(); + if (utility.equals(ACTIVATION)) { + RMID.shutdown(port); } TestLibrary.bomb(utilityToStart + @@ -111,10 +130,10 @@ public class AltSecurityManager implements Runnable { System.err.println("\nRegression test for bug 4183202\n"); // make sure the registry exits early. - ensureExit(registry); + ensureExit(REGISTRY_IMPL); // make sure rmid exits early - ensureExit(rmid); + ensureExit(ACTIVATION); System.err.println("test passed"); diff --git a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java index 10534e1b2..9e8cbba8b 100644 --- a/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java +++ b/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -30,7 +30,7 @@ * @author Peter Jones * * @library ../../testlibrary - * @build ClassPathCodebase Dummy + * @build ClassPathCodebase Dummy TestLibrary * @run main/othervm/policy=security.policy ClassPathCodebase */ @@ -83,11 +83,12 @@ public class ClassPathCodebase { System.getProperty("java.home") + File.separator + "bin" + File.separator + "rmiregistry"; + int port = TestLibrary.getUnusedRandomPort(); String cmdarray[] = new String[] { rmiregistryCommand, "-J-Denv.class.path=.", "-J-Djava.rmi.server.codebase=" + exportCodebaseURL, - Integer.toString(TestLibrary.REGISTRY_PORT) }; + Integer.toString(port) }; System.err.println("\nCommand used to spawn rmiregistry process:"); System.err.println("\t" + Arrays.asList(cmdarray).toString()); @@ -118,7 +119,7 @@ public class ClassPathCodebase { * dummy object to it. */ Registry registry = LocateRegistry.getRegistry( - "localhost", TestLibrary.REGISTRY_PORT); + "localhost", port); try { registry.bind(dummyBinding, dummyObject); @@ -133,7 +134,7 @@ public class ClassPathCodebase { { System.err.println( "Error: another registry running on port " + - TestLibrary.REGISTRY_PORT + "?"); + port + "?"); } throw e; } diff --git a/test/java/rmi/registry/emptyName/EmptyName.java b/test/java/rmi/registry/emptyName/EmptyName.java index c3e9f59da..d572b8f8a 100644 --- a/test/java/rmi/registry/emptyName/EmptyName.java +++ b/test/java/rmi/registry/emptyName/EmptyName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -24,6 +24,8 @@ /* @test * @bug 4399304 * @summary check that registry allows empty names + * @library ../../testlibrary + * @build TestLibrary * @run main/othervm EmptyName */ import java.rmi.registry.LocateRegistry; @@ -32,7 +34,7 @@ import java.rmi.server.RemoteObject; public class EmptyName { public static void main(String[] args) throws Exception { - Registry impl = LocateRegistry.createRegistry(0); + Registry impl = TestLibrary.createRegistryOnUnusedPort(); Registry stub = (Registry) RemoteObject.toStub(impl); stub.bind("", stub); stub.lookup(""); diff --git a/test/java/rmi/registry/interfaceHash/InterfaceHash.java b/test/java/rmi/registry/interfaceHash/InterfaceHash.java index a3605f5b5..778241257 100644 --- a/test/java/rmi/registry/interfaceHash/InterfaceHash.java +++ b/test/java/rmi/registry/interfaceHash/InterfaceHash.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -35,8 +35,10 @@ * "interface hash": 4905912898345647071L. * * @author Peter Jones + * @library ../../testlibrary * @build InterfaceHash * @build ReferenceRegistryStub + * @build TestLibrary * @run main/othervm InterfaceHash */ @@ -58,7 +60,7 @@ import sun.rmi.transport.tcp.TCPEndpoint; public class InterfaceHash { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final String NAME = "WMM"; public static void main(String[] args) throws Exception { diff --git a/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java b/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java index 198aa63c0..e75a60989 100644 --- a/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java +++ b/test/java/rmi/registry/multipleRegistries/MultipleRegistries.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -26,6 +26,8 @@ * @summary Can't run multiple registries in the same VM * @author Ann Wollrath * + * @library ../../testlibrary + * @build TestLibrary * @build MultipleRegistries * @run main/othervm/timeout=240 MultipleRegistries */ @@ -58,12 +60,13 @@ public class MultipleRegistries implements RemoteInterface { System.err.println("proxy = " + proxy); System.err.println("export registries"); - Registry registryImpl1 = LocateRegistry.createRegistry(2030); - Registry registryImpl2 = LocateRegistry.createRegistry(2040); - + Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort(); + int port1 = TestLibrary.getRegistryPort(registryImpl1); + Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort(); + int port2 = TestLibrary.getRegistryPort(registryImpl2); System.err.println("bind remote object in registries"); - Registry registry1 = LocateRegistry.getRegistry(2030); - Registry registry2 = LocateRegistry.getRegistry(2040); + Registry registry1 = LocateRegistry.getRegistry(port1); + Registry registry2 = LocateRegistry.getRegistry(port2); registry1.bind(NAME, proxy); registry2.bind(NAME, proxy); diff --git a/test/java/rmi/registry/readTest/readTest.java b/test/java/rmi/registry/readTest/readTest.java index 8942b0c0e..95cd9c0a6 100644 --- a/test/java/rmi/registry/readTest/readTest.java +++ b/test/java/rmi/registry/readTest/readTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -29,18 +29,19 @@ import java.rmi.server.UnicastRemoteObject; public class readTest { public static void main(String args[]) throws Exception { - int port = 7491; try { testPkg.Server obj = new testPkg.Server(); testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0); // Bind the remote object's stub in the registry - Registry registry = LocateRegistry.getRegistry(port); + Registry registry = + LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT); registry.bind("Hello", stub); System.err.println("Server ready"); // now, let's test client - testPkg.Client client = new testPkg.Client(port); + testPkg.Client client = + new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT); String testStubReturn = client.testStub(); if(!testStubReturn.equals(obj.hello)) { throw new RuntimeException("Test Fails : unexpected string from stub call"); diff --git a/test/java/rmi/registry/readTest/readTest.sh b/test/java/rmi/registry/readTest/readTest.sh index cb600d5c1..4490a48c4 100644 --- a/test/java/rmi/registry/readTest/readTest.sh +++ b/test/java/rmi/registry/readTest/readTest.sh @@ -1,5 +1,5 @@ # -# Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2011, 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 @@ -23,6 +23,8 @@ # @test # @bug 7102369 7094468 7100592 +# @library ../../testlibrary +# @build TestLibrary # @summary remove java.rmi.server.codebase property parsing from registyimpl # @run shell readTest.sh @@ -44,22 +46,24 @@ case "$OS" in ;; esac +TEST_CLASSPATH=.:$TESTCLASSES cp -r ${TESTSRC}${FS}* . ${TESTJAVA}${FS}bin${FS}javac testPkg${FS}*java -${TESTJAVA}${FS}bin${FS}javac readTest.java +${TESTJAVA}${FS}bin${FS}javac -cp $TEST_CLASSPATH readTest.java mkdir rmi_tmp RMIREG_OUT=rmi.out #start rmiregistry without any local classes on classpath cd rmi_tmp -${TESTJAVA}${FS}bin${FS}rmiregistry 7491 > ..${FS}${RMIREG_OUT} 2>&1 & +# NOTE: This RMI Registry port must match TestLibrary.READTEST_REGISTRY_PORT +${TESTJAVA}${FS}bin${FS}rmiregistry 64005 > ..${FS}${RMIREG_OUT} 2>&1 & RMIREG_PID=$! # allow some time to start sleep 3 cd .. # trailing / after code base is important for rmi codebase property. -${TESTJAVA}${FS}bin${FS}java -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 & +${TESTJAVA}${FS}bin${FS}java -cp $TEST_CLASSPATH -Djava.rmi.server.codebase=${FILEURL}`pwd`/ readTest > OUT.TXT 2>&1 & TEST_PID=$! #bulk of testcase - let it run for a while sleep 5 diff --git a/test/java/rmi/registry/reexport/Reexport.java b/test/java/rmi/registry/reexport/Reexport.java index be7163283..042088e65 100644 --- a/test/java/rmi/registry/reexport/Reexport.java +++ b/test/java/rmi/registry/reexport/Reexport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -49,22 +49,21 @@ import java.rmi.registry.*; import java.rmi.server.*; public class Reexport { - static public final int regport = TestLibrary.REGISTRY_PORT; - static public void main(String[] argv) { Registry reg = null; + int regPort = TestLibrary.getUnusedRandomPort(); try { System.err.println("\nregression test for 4120329\n"); // establish the registry (we hope) - System.err.println("Starting registry on port " + regport); - Reexport.makeRegistry(regport); + System.err.println("Starting registry on port " + regPort); + Reexport.makeRegistry(regPort); // Get a handle to the registry System.err.println("Creating duplicate registry, this should fail..."); - reg = createReg(true); + reg = createReg(true, regPort); if (reg != null) { TestLibrary.bomb("failed was able to duplicate the registry?!?"); @@ -73,7 +72,7 @@ public class Reexport { // Kill the first registry. System.err.println("Bringing down the first registry"); try { - Reexport.killRegistry(); + Reexport.killRegistry(regPort); } catch (Exception foo) { } @@ -81,7 +80,7 @@ public class Reexport { System.err.println("Trying again to start our own " + "registry... this should work"); - reg = createReg(false); + reg = createReg(false, regPort); if (reg == null) { TestLibrary.bomb("Could not create registry on second try"); @@ -93,17 +92,17 @@ public class Reexport { TestLibrary.bomb(e); } finally { // dont leave the registry around to affect other tests. - killRegistry(); + killRegistry(regPort); reg = null; } } - static Registry createReg(boolean remoteOk) { + static Registry createReg(boolean remoteOk, int port) { Registry reg = null; try { - reg = LocateRegistry.createRegistry(regport); + reg = LocateRegistry.createRegistry(port); } catch (Throwable e) { if (remoteOk) { System.err.println("EXPECTING PORT IN USE EXCEPTION:"); @@ -140,10 +139,10 @@ public class Reexport { } private static Process subreg = null; - public static void killRegistry() { + public static void killRegistry(int port) { if (Reexport.subreg != null) { - RegistryRunner.requestExit(); + RegistryRunner.requestExit(port); try { Reexport.subreg.waitFor(); diff --git a/test/java/rmi/reliability/juicer/AppleUserImpl.java b/test/java/rmi/reliability/juicer/AppleUserImpl.java index 775ca5d45..2ed30c65a 100644 --- a/test/java/rmi/reliability/juicer/AppleUserImpl.java +++ b/test/java/rmi/reliability/juicer/AppleUserImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -59,19 +59,21 @@ * @build Apple AppleEvent AppleImpl AppleUserImpl * @build Orange OrangeEcho OrangeEchoImpl OrangeImpl * @build ApplicationServer + * @build TestLibrary * * @run main/othervm/policy=security.policy AppleUserImpl -seconds 30 * * @author Peter Jones, Nigel Daley */ -import java.rmi.RemoteException; import java.rmi.NoSuchObjectException; -import java.rmi.server.UnicastRemoteObject; +import java.rmi.RemoteException; import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.UnicastRemoteObject; import java.util.Random; -import java.util.logging.Logger; import java.util.logging.Level; +import java.util.logging.Logger; /** * The AppleUserImpl class implements the behavior of the remote @@ -80,7 +82,7 @@ import java.util.logging.Level; * AppleUserThread is created for each apple. */ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { - + private static int registryPort = -1; private static final Logger logger = Logger.getLogger("reliability.appleuser"); private static int threadNum = 0; @@ -308,8 +310,10 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { synchronized (user) { // create new registry and bind new AppleUserImpl in registry - LocateRegistry.createRegistry(2006); - LocateRegistry.getRegistry(2006).rebind("AppleUser",user); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); + LocateRegistry.getRegistry(registryPort).rebind("AppleUser", + user); // start the other server if applicable if (othervm) { @@ -318,7 +322,9 @@ public class AppleUserImpl extends UnicastRemoteObject implements AppleUser { "started in separate process"); } else { Class app = Class.forName("ApplicationServer"); - server = new Thread((Runnable) app.newInstance()); + java.lang.reflect.Constructor appConstructor = + app.getDeclaredConstructor(new Class[] {Integer.TYPE}); + server = new Thread((Runnable) appConstructor.newInstance(registryPort)); logger.log(Level.INFO, "Starting application server " + "in same process"); server.start(); diff --git a/test/java/rmi/reliability/juicer/ApplicationServer.java b/test/java/rmi/reliability/juicer/ApplicationServer.java index 1d1beb266..9e4b404dd 100644 --- a/test/java/rmi/reliability/juicer/ApplicationServer.java +++ b/test/java/rmi/reliability/juicer/ApplicationServer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -38,18 +38,21 @@ public class ApplicationServer implements Runnable { private static final int LOOKUP_ATTEMPTS = 5; private static final int DEFAULT_NUMAPPLES = 10; private static final String DEFAULT_REGISTRYHOST = "localhost"; + private static final int DEFAULT_REGISTRYPORT = -1; private final int numApples; private final String registryHost; + private final int registryPort; private final Apple[] apples; private AppleUser user; - ApplicationServer() { - this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST); + ApplicationServer(int registryPort) { + this(DEFAULT_NUMAPPLES, DEFAULT_REGISTRYHOST, registryPort); } - ApplicationServer(int numApples, String registryHost) { + ApplicationServer(int numApples, String registryHost, int registryPort) { this.numApples = numApples; this.registryHost = registryHost; + this.registryPort = registryPort; apples = new Apple[numApples]; } @@ -71,7 +74,7 @@ public class ApplicationServer implements Runnable { for (i = 0; i < LOOKUP_ATTEMPTS; i++) { try { Registry registry = LocateRegistry.getRegistry( - registryHost, 2006); + registryHost, registryPort); user = (AppleUser) registry.lookup("AppleUser"); user.startTest(); break; //successfully obtained AppleUser @@ -120,16 +123,20 @@ public class ApplicationServer implements Runnable { private static void usage() { System.err.println("Usage: ApplicationServer [-numApples ]"); System.err.println(" [-registryHost ]"); + System.err.println(" -registryPort "); System.err.println(" numApples The number of apples (threads) to use."); System.err.println(" The default is 10 apples."); System.err.println(" host The host running rmiregistry " + "which contains AppleUser."); System.err.println(" The default is \"localhost\"."); + System.err.println(" port The port the rmiregistry is running" + + "on."); System.err.println(); } public static void main(String[] args) { int num = DEFAULT_NUMAPPLES; + int port = -1; String host = DEFAULT_REGISTRYHOST; // parse command line args @@ -142,17 +149,25 @@ public class ApplicationServer implements Runnable { } else if (arg.equals("-registryHost")) { i++; host = args[i]; + } else if (arg.equals("-registryPort")) { + i++; + port = Integer.parseInt(args[i]); } else { usage(); } } + + if (port == -1) { + usage(); + throw new RuntimeException("Port must be specified."); + } } catch (Throwable t) { usage(); throw new RuntimeException("TEST FAILED: Bad argument"); } // start the client server - Thread server = new Thread(new ApplicationServer(num,host)); + Thread server = new Thread(new ApplicationServer(num,host,port)); server.start(); // main should exit once all exported remote objects are gc'd } diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java index f71180554..209be4591 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/EchoImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -128,8 +128,9 @@ public class EchoImpl ActivationGroup.createGroup(groupID, groupDesc, 0); EchoImpl impl = new EchoImpl(protocol); - System.out.println("EchoServer: binding in registry"); - Naming.rebind("//:" + UseCustomSocketFactory.REGISTRY_PORT + + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); + System.out.println("EchoServer: binding in registry on port:" + registryPort); + Naming.rebind("//:" + registryPort + "/EchoServer", impl); System.out.println("EchoServer ready."); } catch (Exception e) { diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java index 49a24b7cb..5868c583b 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/UseCustomSocketFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -32,6 +32,7 @@ * @build EchoImpl * @build EchoImpl_Stub * @build UseCustomSocketFactory + * @build TestLibrary * @run main/othervm/policy=security.policy/timeout=360 UseCustomSocketFactory */ @@ -42,8 +43,8 @@ import java.rmi.server.*; import java.rmi.registry.*; public class UseCustomSocketFactory { + static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); - final static int REGISTRY_PORT = 2006; static String[] protocol = new String[] { "", "compress", "xor" }; public static void main(String[] args) { @@ -68,7 +69,7 @@ public class UseCustomSocketFactory { " -C-Djava.security.manager=java.rmi.RMISecurityManager "}); rmid.start(); - Echo[] echo = spawnAndTest(); + Echo[] echo = spawnAndTest(rmid.getPort()); reactivateAndTest(echo); } catch (IOException e) { TestLibrary.bomb("creating rmid", e); @@ -78,17 +79,20 @@ public class UseCustomSocketFactory { } } - private static Echo[] spawnAndTest() { + private static Echo[] spawnAndTest(int rmidPort) { System.err.println("\nCreate Test-->"); Echo[] echo = new Echo[protocol.length]; for (int i = 0; i < protocol.length; i++) { - JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + REGISTRY_PORT + + " -Djava.rmi.activation.port=" + + rmidPort, protocol[i]); System.err.println("\nusing protocol: " + diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy index 57bd984e1..ffc9b1e81 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/activatable/security.policy @@ -30,6 +30,9 @@ grant { permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.rmi.activation.port", "write"; + // required for test to create an ActivationGroup permission java.lang.RuntimePermission "setFactory"; diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java index 17cc832fc..e2dde858b 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/HelloImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -65,8 +65,9 @@ public class HelloImpl if (args.length >= 1) protocol = args[0]; + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); registry = java.rmi.registry.LocateRegistry. - getRegistry("localhost", TestLibrary.REGISTRY_PORT, + getRegistry("localhost", registryPort, new Compress.CompressRMIClientSocketFactory()); UseCustomSocketFactory.checkStub(registry, "RMIClientSocket"); hello = (Hello) registry.lookup("/HelloServer"); diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java index 5fb383d9a..ba6106883 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/UseCustomSocketFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -32,6 +32,7 @@ * @build Hello * @build HelloImpl * @build HelloImpl_Stub + * @build TestLibrary * @build UseCustomSocketFactory * @build Compress * @run main/othervm/policy=security.policy/timeout=240 UseCustomSocketFactory @@ -58,6 +59,7 @@ public class UseCustomSocketFactory { System.out.println("\nRegression test for bug 4148850\n"); TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); + int registryPort = TestLibrary.getUnusedRandomPort(); try { impl = new HelloImpl(); @@ -67,7 +69,7 @@ public class UseCustomSocketFactory { * allow the rmiregistry to be secure. */ registry = LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT, + createRegistry(registryPort, new Compress.CompressRMIClientSocketFactory(), new Compress.CompressRMIServerSocketFactory()); registry.rebind("/HelloServer", impl); @@ -77,8 +79,12 @@ public class UseCustomSocketFactory { TestLibrary.bomb("creating registry", e); } - JavaVM serverVM = new JavaVM("HelloImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, ""); + JavaVM serverVM = new JavaVM("HelloImpl", + "-Djava.security.policy=" + + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, + ""); try { diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy index 31d3bc529..7567ae191 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/registry/security.policy @@ -22,6 +22,8 @@ grant { permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java index 0dd30c543..d1b4d0625 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/EchoImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -64,8 +64,9 @@ public class EchoImpl System.out.println("EchoServer: creating remote object"); EchoImpl impl = new EchoImpl(protocol); + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); System.out.println("EchoServer: binding in registry"); - Naming.rebind("//:" + TestLibrary.REGISTRY_PORT + + Naming.rebind("//:" + registryPort + "/EchoServer", impl); System.out.println("EchoServer ready."); } catch (Exception e) { diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java index 20d00dfe4..13766abd8 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/UseCustomSocketFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -46,6 +46,8 @@ public class UseCustomSocketFactory { public static void main(String[] args) { + int registryPort = -1; + String[] protocol = new String[] { "", "compress", "xor" }; System.out.println("\nRegression test for bug 4127826\n"); @@ -53,7 +55,8 @@ public class UseCustomSocketFactory { TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); try { - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); } catch (Exception e) { TestLibrary.bomb("creating registry", e); } @@ -65,7 +68,9 @@ public class UseCustomSocketFactory { JavaVM serverVM = new JavaVM("EchoImpl", "-Djava.security.policy=" + - TestParams.defaultPolicy, + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, protocol[i]); System.err.println("\nusing protocol: " + (protocol[i] == "" ? "none" : protocol[i])); @@ -79,7 +84,7 @@ public class UseCustomSocketFactory { Echo obj = null; do { try { - obj = (Echo) Naming.lookup("//:" + TestLibrary.REGISTRY_PORT + + obj = (Echo) Naming.lookup("//:" + registryPort + "/EchoServer"); break; } catch (NotBoundException e) { @@ -109,7 +114,7 @@ public class UseCustomSocketFactory { } finally { serverVM.destroy(); try { - Naming.unbind("//:" + TestLibrary.REGISTRY_PORT + + Naming.unbind("//:" + registryPort + "/EchoServer"); } catch (Exception e) { TestLibrary.bomb("unbinding EchoServer", e); diff --git a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy index 31d3bc529..d1b5073ed 100644 --- a/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy +++ b/test/java/rmi/server/RMISocketFactory/useSocketFactory/unicast/security.policy @@ -22,9 +22,18 @@ grant { permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; + permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; + // used by TestLibrary to get the RMI Registry port + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; + // test needs to export rmid and communicate with objects on arbitrary ports permission java.net.SocketPermission "*:1024-", "connect,accept,listen"; }; diff --git a/test/java/rmi/server/RemoteServer/AddrInUse.java b/test/java/rmi/server/RemoteServer/AddrInUse.java index ad88f98c8..9ab8e50d6 100644 --- a/test/java/rmi/server/RemoteServer/AddrInUse.java +++ b/test/java/rmi/server/RemoteServer/AddrInUse.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -26,6 +26,7 @@ * @summary retryServerSocket should not retry on BindException * @author Ann Wollrath * + * @library ../../testlibrary * @build AddrInUse * @run main/othervm AddrInUse */ @@ -36,7 +37,7 @@ import java.rmi.server.ExportException; public class AddrInUse implements Runnable { - private static final int PORT = 9999; + private static int port = -1; private static final long TIMEOUT = 10000; private boolean exportSucceeded = false; @@ -49,7 +50,7 @@ public class AddrInUse implements Runnable { * has already been bound, and record the result. */ try { - LocateRegistry.createRegistry(PORT); + LocateRegistry.createRegistry(port); synchronized (this) { exportSucceeded = true; notifyAll(); @@ -68,8 +69,9 @@ public class AddrInUse implements Runnable { /* * Bind a server socket to a port. */ - System.err.println("create a ServerSocket on port " + PORT + "..."); - ServerSocket server = new ServerSocket(PORT); + ServerSocket server = new ServerSocket(0); + port = server.getLocalPort(); + System.err.println("Created a ServerSocket on port " + port + "..."); /* * Start a thread that creates a registry on the same port, diff --git a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java index 28679859e..dbe2ffe21 100644 --- a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java +++ b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/KeepAliveDuringCall.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -82,15 +82,17 @@ public class KeepAliveDuringCall implements ShutdownMonitor { UnicastRemoteObject.exportObject(obj); System.err.println("exported shutdown monitor"); - Registry localRegistry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry localRegistry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(localRegistry); System.err.println("created local registry"); localRegistry.bind(BINDING, obj); System.err.println("bound shutdown monitor in local registry"); System.err.println("starting remote ShutdownImpl VM..."); - (new JavaVM("ShutdownImpl")).start(); + (new JavaVM("ShutdownImpl", + "-Drmi.registry.port=" + + registryPort, "")).start(); Shutdown s; synchronized (obj.lock) { diff --git a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java index 6ab0dc66c..7a3d0406a 100644 --- a/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java +++ b/test/java/rmi/server/UnicastRemoteObject/keepAliveDuringCall/ShutdownImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -68,8 +68,9 @@ public class ShutdownImpl implements Shutdown { public static void main(String[] args) { try { + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = - LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry("", registryPort); ShutdownMonitor monitor = (ShutdownMonitor) registry.lookup(KeepAliveDuringCall.BINDING); System.err.println("(ShutdownImpl) retrieved shutdown monitor"); diff --git a/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java b/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java index ed0008076..60325dcaa 100644 --- a/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java +++ b/test/java/rmi/server/UnicastRemoteObject/unexportObject/UnexportLeak.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -28,8 +28,10 @@ * * @author Ann Wollrath * + * @library ../../../testlibrary * @build UnexportLeak * @build UnexportLeak_Stub + * @build TestLibrary * @build Ping * @run main/othervm UnexportLeak */ @@ -40,20 +42,18 @@ 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(); diff --git a/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java b/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java index b60dcc5fb..7b7317a8d 100644 --- a/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java +++ b/test/java/rmi/server/Unreferenced/finiteGCLatency/FiniteGCLatency.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -37,6 +37,7 @@ * @library ../../../testlibrary * @build FiniteGCLatency * @build FiniteGCLatency_Stub + * @build TestLibrary * @run main/othervm/timeout=120 FiniteGCLatency */ @@ -78,11 +79,11 @@ public class FiniteGCLatency implements Remote, Unreferenced { try { UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); - - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry1 = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry1); System.err.println("created registry"); - Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + Registry registry = LocateRegistry.getRegistry("", port); registry.bind(BINDING, obj); System.err.println("bound remote object in registry"); diff --git a/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java b/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java index fb8e8750e..c1d5c5796 100644 --- a/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java +++ b/test/java/rmi/server/Unreferenced/leaseCheckInterval/LeaseCheckInterval.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -87,8 +87,9 @@ public class LeaseCheckInterval implements Remote, Unreferenced { UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); + int registryPort = TestLibrary.getUnusedRandomPort(); Registry localRegistry = - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + LocateRegistry.createRegistry(registryPort); System.err.println("created local registry"); localRegistry.bind(BINDING, obj); @@ -96,7 +97,8 @@ public class LeaseCheckInterval implements Remote, Unreferenced { synchronized (obj.lock) { System.err.println("starting remote client VM..."); - (new JavaVM("SelfTerminator")).start(); + (new JavaVM("SelfTerminator", "-Drmi.registry.port=" + + registryPort, "")).start(); System.err.println("waiting for unreferenced() callback..."); obj.lock.wait(TIMEOUT); diff --git a/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java b/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java index 5bb579f55..4875634db 100644 --- a/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java +++ b/test/java/rmi/server/Unreferenced/leaseCheckInterval/SelfTerminator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -33,8 +33,10 @@ public class SelfTerminator { public static void main(String[] args) { try { + int registryPort = + Integer.parseInt(System.getProperty("rmi.registry.port")); Registry registry = - LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + LocateRegistry.getRegistry("", registryPort); Remote stub = registry.lookup(LeaseCheckInterval.BINDING); Runtime.getRuntime().halt(0); } catch (Exception e) { diff --git a/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java b/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java index 38ce26053..eb9d19287 100644 --- a/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java +++ b/test/java/rmi/server/Unreferenced/unreferencedContext/UnreferencedContext.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -41,6 +41,7 @@ * @library ../../../testlibrary * @build UnreferencedContext * @build UnreferencedContext_Stub + * @build TestLibrary * @run main/othervm/timeout=120 UnreferencedContext */ @@ -119,10 +120,11 @@ public class UnreferencedContext implements Remote, Unreferenced, Runnable { UnicastRemoteObject.exportObject(obj); System.err.println("exported remote object"); - LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry1 = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry1); System.err.println("created registry"); - Registry registry = LocateRegistry.getRegistry("", TestLibrary.REGISTRY_PORT); + Registry registry = LocateRegistry.getRegistry("", port); registry.bind(BINDING, obj); System.err.println("bound remote object in registry"); diff --git a/test/java/rmi/server/useCustomRef/UseCustomRef.java b/test/java/rmi/server/useCustomRef/UseCustomRef.java index f42aa05b0..059c9a849 100644 --- a/test/java/rmi/server/useCustomRef/UseCustomRef.java +++ b/test/java/rmi/server/useCustomRef/UseCustomRef.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -35,6 +35,7 @@ * @build Ping * @build UseCustomRef_Stub * @build UseCustomRef_Skel + * @build TestLibrary * @run main/othervm/policy=security.policy/secure=java.rmi.RMISecurityManager/timeout=120 UseCustomRef * * This test was failing to run because the synthetic access @@ -84,8 +85,9 @@ public class UseCustomRef TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); System.err.println("creating Registry..."); - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + int port = TestLibrary.getRegistryPort(registry); /* * create object with custom ref and bind in registry */ @@ -97,7 +99,7 @@ public class UseCustomRef "instanceof CustomServerRef"); } - String name = "//:" + TestLibrary.REGISTRY_PORT + "/UseCustomRef"; + String name = "//:" + port + "/UseCustomRef"; // String name = "UseCustomRef"; System.err.println("binding object in registry..."); Naming.rebind(name, cr); diff --git a/test/java/rmi/server/useCustomRef/security.policy b/test/java/rmi/server/useCustomRef/security.policy index c2a4b084e..7be818a2a 100644 --- a/test/java/rmi/server/useCustomRef/security.policy +++ b/test/java/rmi/server/useCustomRef/security.policy @@ -8,8 +8,11 @@ grant codeBase "file:${java.home}/lib/ext/*" { grant { // the test uses a class in the package sun.rmi.server + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; permission java.util.PropertyPermission "package.restrict.access.sun", "read"; permission java.util.PropertyPermission "package.restrict.access.sun.rmi", "read"; diff --git a/test/java/rmi/testlibrary/ActivationLibrary.java b/test/java/rmi/testlibrary/ActivationLibrary.java index 86c1744ef..5d21a4a32 100644 --- a/test/java/rmi/testlibrary/ActivationLibrary.java +++ b/test/java/rmi/testlibrary/ActivationLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -169,37 +169,10 @@ public class ActivationLibrary { return false; } - /** - * Check to see if an arry of Strings contains a given string. - */ - private static boolean - containsString(String[] strings, String contained) - { - if (strings == null) { - if (contained == null) { - return true; - } - return false; - } - - for (int i = 0 ; i < strings.length ; i ++ ) { - if ((strings[i] != null) && - (strings[i].indexOf(contained) >= 0)) - { - return true; - } - } - return false; - } - /** cleanup after rmid */ public static void rmidCleanup(RMID rmid) { - rmidCleanup(rmid, TestLibrary.RMID_PORT); - } - - public static void rmidCleanup(RMID rmid, int port) { if (rmid != null) { - if (!ActivationLibrary.safeDestroy(rmid, port, SAFE_WAIT_TIME)) { + if (!ActivationLibrary.safeDestroy(rmid, SAFE_WAIT_TIME)) { TestLibrary.bomb("rmid not destroyed in: " + SAFE_WAIT_TIME + " milliseconds"); @@ -215,8 +188,8 @@ public class ActivationLibrary { * @return whether or not shutdown completed succesfully in the * timeAllowed */ - private static boolean safeDestroy(RMID rmid, int port, long timeAllowed) { - DestroyThread destroyThread = new DestroyThread(rmid, port); + private static boolean safeDestroy(RMID rmid, long timeAllowed) { + DestroyThread destroyThread = new DestroyThread(rmid); destroyThread.start(); try { @@ -236,9 +209,9 @@ public class ActivationLibrary { private final int port; private boolean succeeded = false; - DestroyThread(RMID rmid, int port) { + DestroyThread(RMID rmid) { this.rmid = rmid; - this.port = port; + this.port = rmid.getPort(); this.setDaemon(true); } diff --git a/test/java/rmi/testlibrary/RMID.java b/test/java/rmi/testlibrary/RMID.java index 8a8ac3978..e963c45c9 100644 --- a/test/java/rmi/testlibrary/RMID.java +++ b/test/java/rmi/testlibrary/RMID.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -28,7 +28,6 @@ import java.io.*; import java.rmi.*; import java.rmi.activation.*; -import java.util.Properties; /** * Utility class that creates an instance of rmid with a policy @@ -133,7 +132,7 @@ public class RMID extends JavaVM { boolean debugExec) { return createRMID(out, err, debugExec, true, - TestLibrary.RMID_PORT); + TestLibrary.getUnusedRandomPort()); } public static RMID createRMID(OutputStream out, OutputStream err, @@ -208,7 +207,7 @@ public class RMID extends JavaVM { // if rmid is already running, then the test will fail with // a well recognized exception (port already in use...). - mesg("starting rmid..."); + mesg("starting rmid on port #" + port + "..."); super.start(); int slopFactor = 1; @@ -235,6 +234,14 @@ public class RMID extends JavaVM { // Checking if rmid is present if (ActivationLibrary.rmidRunning(port)) { + /** + * We need to set the java.rmi.activation.port value as the + * activation system will use the property to determine the + * port #. The activation system will use this value if set. + * If it isn't set, the activation system will set it to an + * incorrect value. + */ + System.setProperty("java.rmi.activation.port", Integer.toString(port)); mesg("finished starting rmid."); return; } @@ -259,10 +266,6 @@ public class RMID extends JavaVM { * Shutdown does not nullify possible references to the rmid * process object (destroy does though). */ - public static void shutdown() { - shutdown(TestLibrary.RMID_PORT); - } - public static void shutdown(int port) { try { @@ -301,9 +304,7 @@ public class RMID extends JavaVM { * if rmid is a child process of the current VM. */ public void destroy() { - - // attempt graceful shutdown of the activation system on - // TestLibrary.RMID_PORT + // attempt graceful shutdown of the activation system shutdown(port); if (vm != null) { @@ -357,4 +358,6 @@ public class RMID extends JavaVM { vm = null; } } + + public int getPort() {return port;} } diff --git a/test/java/rmi/testlibrary/RegistryRunner.java b/test/java/rmi/testlibrary/RegistryRunner.java index 20fd38b8b..6290c79f9 100644 --- a/test/java/rmi/testlibrary/RegistryRunner.java +++ b/test/java/rmi/testlibrary/RegistryRunner.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -56,12 +56,13 @@ public class RegistryRunner extends UnicastRemoteObject * Request that the registry process exit and handle * related exceptions. */ - public static void requestExit() { + public static void requestExit(int port) { + try { RemoteExiter exiter = (RemoteExiter) Naming.lookup("rmi://localhost:" + - TestLibrary.REGISTRY_PORT + + port + "/RemoteExiter"); try { exiter.exit(); @@ -84,7 +85,7 @@ public class RegistryRunner extends UnicastRemoteObject System.err.println("Usage: "); System.exit(0); } - int port = TestLibrary.REGISTRY_PORT; + int port = -1; try { port = Integer.parseInt(args[0]); } catch (NumberFormatException nfe) { diff --git a/test/java/rmi/testlibrary/StreamPipe.java b/test/java/rmi/testlibrary/StreamPipe.java index 9278539bf..d2641abd4 100644 --- a/test/java/rmi/testlibrary/StreamPipe.java +++ b/test/java/rmi/testlibrary/StreamPipe.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 1999, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -113,7 +113,9 @@ public class StreamPipe extends Thread { w.flush(); line = r.readLine(); } - + } catch (InterruptedIOException iioe) { + // Thread interrupted during IO operation. Terminate StreamPipe. + return; } catch (IOException e) { System.err.println("*** IOException in StreamPipe.run:"); e.printStackTrace(); diff --git a/test/java/rmi/testlibrary/TestLibrary.java b/test/java/rmi/testlibrary/TestLibrary.java index 7c82cd94b..734d80509 100644 --- a/test/java/rmi/testlibrary/TestLibrary.java +++ b/test/java/rmi/testlibrary/TestLibrary.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,37 +36,62 @@ * not make use of packages. */ +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; -import java.io.OutputStream; import java.io.PrintStream; -import java.net.URL; import java.net.MalformedURLException; -import java.rmi.activation.Activatable; -import java.rmi.activation.ActivationID; +import java.net.ServerSocket; +import java.net.URL; import java.rmi.NoSuchObjectException; -import java.rmi.registry.Registry; import java.rmi.Remote; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.RemoteRef; import java.rmi.server.UnicastRemoteObject; import java.util.Enumeration; -import java.util.Hashtable; import java.util.Properties; -import java.io.ByteArrayOutputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; +import sun.rmi.registry.RegistryImpl; +import sun.rmi.server.UnicastServerRef; +import sun.rmi.transport.Endpoint; +import sun.rmi.transport.LiveRef; +import sun.rmi.transport.tcp.TCPEndpoint; /** * Class of utility/library methods (i.e. procedures) that assist with * the writing and maintainance of rmi regression tests. */ public class TestLibrary { - - /** standard test port number for registry */ - public final static int REGISTRY_PORT = 2006; - /** port for rmid necessary: not used to actually start rmid */ - public final static int RMID_PORT = 1098; + /** + * IMPORTANT! + * + * RMI tests are run concurrently and port conflicts result when a single + * port number is used by multiple tests. When needing a port, use + * getUnusedRandomPort() wherever possible. If getUnusedRandomPort() cannot + * be used, reserve and specify a port to use for your test here. This + * will ensure there are no port conflicts amongst the RMI tests. The + * port numbers specified here may also be specified in the respective + * tests. Do not change the reserved port numbers here without also + * changing the port numbers in the respective tests. + * + * When needing an instance of the RMIRegistry, use + * createRegistryOnUnusedPort wherever possible to prevent port conflicts. + * + * Reserved port range: FIXED_PORT_MIN to FIXED_PORT_MAX (inclusive) for + * tests which cannot use a random port. If new fixed ports are added below + * FIXED_PORT_MIN or above FIXED_PORT_MAX, then adjust + * FIXED_PORT_MIN/MAX appropriately. + */ + public final static int FIXED_PORT_MIN = 64001; + public final static int FIXED_PORT_MAX = 64010; + public final static int RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT = 64001; + public final static int RMIDVIAINHERITEDCHANNEL_REGISTRY_PORT = 64002; + public final static int INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT = 64003; + public final static int INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT = 64004; + public final static int READTEST_REGISTRY_PORT = 64005; static void mesg(Object mesg) { System.err.println("TEST_LIBRARY: " + mesg.toString()); @@ -339,6 +364,83 @@ public class TestLibrary { } } + /** + * Creates an RMI {@link Registry} on a random, un-reserved port. + * + * @returns an RMI Registry, using a random port. + * @throws RemoteException if there was a problem creating a Registry. + */ + public static Registry createRegistryOnUnusedPort() throws RemoteException { + return LocateRegistry.createRegistry(getUnusedRandomPort()); + } + + /** + * Returns the port number the RMI {@link Registry} is running on. + * + * @param registry the registry to find the port of. + * @return the port number the registry is using. + * @throws RuntimeException if there was a problem getting the port number. + */ + public static int getRegistryPort(Registry registry) { + int port = -1; + + try { + RemoteRef remoteRef = ((RegistryImpl)registry).getRef(); + LiveRef liveRef = ((UnicastServerRef)remoteRef).getLiveRef(); + Endpoint endpoint = liveRef.getChannel().getEndpoint(); + TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint; + port = tcpEndpoint.getPort(); + } catch (Exception ex) { + throw new RuntimeException("Error getting registry port.", ex); + } + + return port; + } + + /** + * Returns an unused random port number which is not a reserved port. Will + * try up to 10 times to get a random port before giving up and throwing a + * RuntimeException. + * + * @return an unused random port number. + * @throws RuntimeException if there was a problem getting a port. + */ + public static int getUnusedRandomPort() { + int numTries = 0; + int unusedRandomPort = FIXED_PORT_MIN; + Exception ex = null; + + while (numTries++ < 10) { + ex = null; //reset + + try (ServerSocket ss = new ServerSocket(0)) { + unusedRandomPort = ss.getLocalPort(); + } catch (Exception e) { + ex = e; + } + + if (!isReservedPort(unusedRandomPort)) { + return unusedRandomPort; + } + } + + // If we're here, then either an exception was thrown or the port is + // a reserved port. + throw new RuntimeException("Error getting unused random port.", ex); + } + + /** + * Determines if a port is one of the reserved port numbers. + * + * @param port the port to test. + * @return {@code true} if the port is a reserved port, otherwise + * {@code false}. + */ + public static boolean isReservedPort(int port) { + return ((port >= FIXED_PORT_MIN) && (port <= FIXED_PORT_MAX) || + (port == 1099)); + } + /** * Method to capture the stack trace of an exception and return it * as a string. diff --git a/test/java/rmi/transport/checkFQDN/CheckFQDN.java b/test/java/rmi/transport/checkFQDN/CheckFQDN.java index 880b70071..006de5b6c 100644 --- a/test/java/rmi/transport/checkFQDN/CheckFQDN.java +++ b/test/java/rmi/transport/checkFQDN/CheckFQDN.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -34,6 +34,7 @@ * * @library ../../testlibrary * @build CheckFQDN CheckFQDNClient CheckFQDN_Stub TellServerName + * @build TestLibrary * @run main/othervm/timeout=120 CheckFQDN */ @@ -63,7 +64,7 @@ import java.io.*; */ public class CheckFQDN extends UnicastRemoteObject implements TellServerName { - + public static int REGISTRY_PORT =-1; static String propertyBeingTested = null; static String propertyBeingTestedValue = null; @@ -77,8 +78,8 @@ public class CheckFQDN extends UnicastRemoteObject System.err.println ("\nRegression test for bug/rfe 4115683\n"); - Registry registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + REGISTRY_PORT = TestLibrary.getRegistryPort(registry); registry.bind("CheckFQDN", checkFQDN); /* test the host name scheme in different environments.*/ @@ -117,7 +118,9 @@ public class CheckFQDN extends UnicastRemoteObject JavaVM jvm = new JavaVM("CheckFQDNClient", propOption + property + equal + - propertyValue + extraProp, + propertyValue + extraProp + + " -Drmi.registry.port=" + + REGISTRY_PORT, ""); propertyBeingTested=property; diff --git a/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java b/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java index c1666f49e..37d9b9732 100644 --- a/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java +++ b/test/java/rmi/transport/checkFQDN/CheckFQDNClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -58,8 +58,9 @@ public class CheckFQDNClient implements Runnable { System.err.println("Client host name: " + hostname); + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); tell = (TellServerName) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + registryPort + "/CheckFQDN"); tell.tellServerName(hostname); System.err.println("client has exited"); diff --git a/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java b/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java index 34dd9c99e..0ab00577d 100644 --- a/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java +++ b/test/java/rmi/transport/checkLeaseInfoLeak/CheckLeaseLeak.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -29,6 +29,7 @@ * * @library ../../testlibrary * @build CheckLeaseLeak CheckLeaseLeak_Stub LeaseLeakClient LeaseLeak + * @build TestLibrary * @run main/othervm/timeout=240 CheckLeaseLeak * */ @@ -57,7 +58,6 @@ import java.lang.reflect.*; import java.rmi.registry.*; public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { - public CheckLeaseLeak() throws RemoteException { } public void ping () throws RemoteException { } @@ -87,8 +87,8 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { try { Registry registry = - java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); leakServer = new CheckLeaseLeak(); registry.rebind("/LeaseLeak", leakServer); @@ -99,7 +99,10 @@ public class CheckLeaseLeak extends UnicastRemoteObject implements LeaseLeak { JavaVM jvm = new JavaVM("LeaseLeakClient", " -Djava.security.policy=" + - TestParams.defaultPolicy, ""); + TestParams.defaultPolicy + + " -Drmi.registry.port=" + + registryPort, + ""); jvm.start(); if (jvm.getVM().waitFor() == 1 ) { diff --git a/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java b/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java index c8e5c75c4..d9cf9fa9e 100644 --- a/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java +++ b/test/java/rmi/transport/checkLeaseInfoLeak/LeaseLeakClient.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -31,11 +31,11 @@ public class LeaseLeakClient { try { LeaseLeak leaseLeak = null; + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); // put a reference on a remote object. Registry registry = - java.rmi.registry.LocateRegistry.getRegistry( - TestLibrary.REGISTRY_PORT); + java.rmi.registry.LocateRegistry.getRegistry(registryPort); leaseLeak = (LeaseLeak) registry.lookup("/LeaseLeak"); leaseLeak.ping(); diff --git a/test/java/rmi/transport/checkLeaseInfoLeak/security.policy b/test/java/rmi/transport/checkLeaseInfoLeak/security.policy index 8dd6d5d6f..cc5811f85 100644 --- a/test/java/rmi/transport/checkLeaseInfoLeak/security.policy +++ b/test/java/rmi/transport/checkLeaseInfoLeak/security.policy @@ -19,6 +19,7 @@ grant { permission java.util.PropertyPermission "user.dir", "read"; permission java.util.PropertyPermission "java.home", "read"; + permission java.util.PropertyPermission "rmi.registry.port", "read"; permission java.util.PropertyPermission "java.security.policy", "read"; permission java.util.PropertyPermission "java.security.manager", "read"; diff --git a/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java b/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java index 1feb59789..69c51de80 100644 --- a/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java +++ b/test/java/rmi/transport/closeServerSocket/CloseServerSocket.java @@ -1,5 +1,5 @@ /* - * 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 @@ -30,7 +30,8 @@ * the local port is released). * @author Peter Jones * - * @build CloseServerSocket + * @library ../../testlibrary + * @build CloseServerSocket TestLibrary * @run main/othervm CloseServerSocket */ @@ -44,8 +45,7 @@ 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() { } @@ -88,7 +88,7 @@ public class CloseServerSocket implements Remote { } 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"); } diff --git a/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java b/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java index 2d530db91..97ad31dc9 100644 --- a/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java +++ b/test/java/rmi/transport/dgcDeadLock/DGCDeadLock.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -32,6 +32,7 @@ * @build Test * @build TestImpl * @build TestImpl_Stub + * @build TestLibrary * @run main/othervm/policy=security.policy/timeout=360 DGCDeadLock */ @@ -53,7 +54,7 @@ import java.rmi.*; import java.io.*; public class DGCDeadLock implements Runnable { - + private static final int REGISTRY_PORT = TestLibrary.getUnusedRandomPort(); final static public int HOLD_TARGET_TIME = 25000; public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; public static boolean finished = false; @@ -75,7 +76,9 @@ public class DGCDeadLock implements Runnable { TestParams.defaultPolicy + " -Djava.rmi.dgc.leaseValue=500000" + " -Dsun.rmi.dgc.checkInterval=" + - (HOLD_TARGET_TIME - 5000) + ""; + (HOLD_TARGET_TIME - 5000) + + " -Drmi.registry.port=" + REGISTRY_PORT + + "" ; testImplVM = new JavaVM("TestImpl", options, ""); testImplVM.start(); @@ -112,7 +115,7 @@ public class DGCDeadLock implements Runnable { // create a test client Test foo = (Test) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + + REGISTRY_PORT + "/Foo"); echo = foo.echo("Hello world"); System.err.println("Test object created."); @@ -131,7 +134,7 @@ public class DGCDeadLock implements Runnable { //import "Bar" Test bar = (Test) Naming.lookup("rmi://:" + - TestLibrary.REGISTRY_PORT + + REGISTRY_PORT + "/Bar"); /* infinite loop to show the liveness of Client, diff --git a/test/java/rmi/transport/dgcDeadLock/TestImpl.java b/test/java/rmi/transport/dgcDeadLock/TestImpl.java index e9a734db2..774e38ae6 100644 --- a/test/java/rmi/transport/dgcDeadLock/TestImpl.java +++ b/test/java/rmi/transport/dgcDeadLock/TestImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -36,7 +36,6 @@ import java.rmi.server.*; public class TestImpl extends UnicastRemoteObject implements Test { - static Thread locker = null; static TestImpl foo = null; static TestImpl bar = null; @@ -57,20 +56,21 @@ public class TestImpl extends UnicastRemoteObject Registry registry = null; try { + int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port")); registry = java.rmi.registry.LocateRegistry. - createRegistry(TestLibrary.REGISTRY_PORT); + createRegistry(registryPort); //export "Foo" foo = new TestImpl(); Naming.rebind("rmi://:" + - TestLibrary.REGISTRY_PORT + registryPort + "/Foo", foo); try { //export "Bar" after leases have been expired. bar = new TestImpl(); Naming.rebind("rmi://localhost:" + - TestLibrary.REGISTRY_PORT + registryPort + "/Bar", bar); } catch (Exception e) { throw new RemoteException(e.getMessage()); diff --git a/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java b/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java index f379baa4f..df04070f1 100644 --- a/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java +++ b/test/java/rmi/transport/handshakeFailure/HandshakeFailure.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -30,7 +30,8 @@ * java.rmi.ConnectException or ConnectIOException, not a MarshalException. * @author Peter Jones * - * @build HandshakeFailure + * @library ../../testlibrary + * @build HandshakeFailure TestLibrary * @run main/othervm HandshakeFailure */ @@ -44,7 +45,7 @@ import java.rmi.registry.Registry; public class HandshakeFailure { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int TIMEOUT = 10000; public static void main(String[] args) throws Exception { diff --git a/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java b/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java index 13cffe6d3..304c17577 100644 --- a/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java +++ b/test/java/rmi/transport/handshakeTimeout/HandshakeTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -33,7 +33,8 @@ * this point (because no data for the invocation has yet been written). * @author Peter Jones * - * @build HandshakeTimeout + * @library ../../testlibrary + * @build HandshakeTimeout TestLibrary * @run main/othervm HandshakeTimeout */ @@ -46,7 +47,7 @@ import java.rmi.registry.Registry; public class HandshakeTimeout { - private static final int PORT = 2020; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int TIMEOUT = 10000; public static void main(String[] args) throws Exception { diff --git a/test/java/rmi/transport/httpSocket/HttpSocketTest.java b/test/java/rmi/transport/httpSocket/HttpSocketTest.java index c9b4d4e87..1004bfb86 100644 --- a/test/java/rmi/transport/httpSocket/HttpSocketTest.java +++ b/test/java/rmi/transport/httpSocket/HttpSocketTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 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 @@ -27,7 +27,7 @@ * @author Dana Burns * * @library ../../testlibrary - * @build HttpSocketTest HttpSocketTest_Stub + * @build HttpSocketTest HttpSocketTest_Stub TestLibrary * @run main/othervm/policy=security.policy HttpSocketTest */ @@ -56,10 +56,7 @@ interface MyRemoteInterface extends Remote { public class HttpSocketTest extends UnicastRemoteObject implements MyRemoteInterface { - private static final String NAME = "HttpSocketTest"; - private static final String REGNAME = - "//:" + TestLibrary.REGISTRY_PORT + "/" + NAME; public HttpSocketTest() throws RemoteException{} @@ -76,21 +73,20 @@ public class HttpSocketTest extends UnicastRemoteObject // Set the socket factory. System.err.println("installing socket factory"); RMISocketFactory.setSocketFactory(new RMIHttpToPortSocketFactory()); + int registryPort = -1; try { - System.err.println("Starting registry"); - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); - + registry = TestLibrary.createRegistryOnUnusedPort(); + registryPort = TestLibrary.getRegistryPort(registry); } catch (Exception e) { TestLibrary.bomb(e); } try { - registry.rebind( NAME, new HttpSocketTest() ); MyRemoteInterface httpTest = - (MyRemoteInterface)Naming.lookup( REGNAME ); + (MyRemoteInterface)Naming.lookup("//:" + registryPort + "/" + NAME); httpTest.setRemoteObject( new HttpSocketTest() ); Remote r = httpTest.getRemoteObject(); diff --git a/test/java/rmi/transport/httpSocket/security.policy b/test/java/rmi/transport/httpSocket/security.policy index 476bbaabd..a0e932009 100644 --- a/test/java/rmi/transport/httpSocket/security.policy +++ b/test/java/rmi/transport/httpSocket/security.policy @@ -4,6 +4,10 @@ grant codeBase "file:${java.home}/lib/ext/*" { grant { permission java.net.SocketPermission "*:1024-", "accept,connect,listen"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.registry"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.server"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport"; permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.proxy"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.rmi.transport.tcp"; permission java.lang.RuntimePermission "setFactory"; }; diff --git a/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java b/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java index ef1796024..99357ffdb 100644 --- a/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java +++ b/test/java/rmi/transport/pinClientSocketFactory/PinClientSocketFactory.java @@ -1,5 +1,5 @@ /* - * 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 @@ -31,6 +31,8 @@ * should become unreachable too (through the RMI implementation). * @author Peter Jones * + * @library ../../testlibrary + * @build TestLibrary * @run main/othervm -Dsun.rmi.transport.connectionTimeout=2000 * PinClientSocketFactory */ @@ -56,7 +58,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class PinClientSocketFactory { - private static final int PORT = 2345; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int SESSIONS = 50; public interface Factory extends Remote { diff --git a/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java b/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java index 9e722bac1..5b21da868 100644 --- a/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java +++ b/test/java/rmi/transport/rapidExportUnexport/RapidExportUnexport.java @@ -1,5 +1,5 @@ /* - * 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 @@ -31,7 +31,8 @@ * procedure (which sleeps 10 seconds after 10 rapid failures). * @author Peter Jones * - * @build RapidExportUnexport + * @library ../../testlibrary + * @build TestLibrary RapidExportUnexport * @run main/othervm RapidExportUnexport */ @@ -39,9 +40,7 @@ import java.rmi.Remote; import java.rmi.server.UnicastRemoteObject; public class RapidExportUnexport { - - private static final int PORT = 2055; - + private static final int PORT = TestLibrary.getUnusedRandomPort(); private static final int REPS = 100; private static final long TIMEOUT = 60000; diff --git a/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java b/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java index d75257e75..decec588d 100644 --- a/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java +++ b/test/java/rmi/transport/reuseDefaultPort/ReuseDefaultPort.java @@ -1,5 +1,5 @@ /* - * 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 @@ -33,7 +33,8 @@ * continue to work because existing applications might depend on it. * @author Peter Jones * - * @build ReuseDefaultPort + * @library ../../testlibrary + * @build ReuseDefaultPort TestLibrary * @run main/othervm ReuseDefaultPort */ @@ -48,7 +49,7 @@ import java.rmi.server.UnicastRemoteObject; public class ReuseDefaultPort implements Remote { - private static final int PORT = 2223; + private static final int PORT = TestLibrary.getUnusedRandomPort(); private ReuseDefaultPort() { } diff --git a/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java b/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java index 041aa33b1..ee3421334 100644 --- a/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java +++ b/test/sun/rmi/rmic/newrmic/equivalence/AppleUserImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 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 @@ -25,6 +25,7 @@ import java.rmi.RemoteException; import java.rmi.Naming; import java.rmi.server.UnicastRemoteObject; import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; import java.util.Random; import java.util.ArrayList; import java.util.Date; @@ -249,11 +250,12 @@ public class AppleUserImpl } synchronized (user) { + int port = -1; // create new registry and bind new AppleUserImpl in registry try { - LocateRegistry.createRegistry(1099); //TestLibrary.REGISTRY_PORT); - Naming.rebind("rmi://localhost:1099/AppleUser",user); - //TestLibrary.REGISTRY_PORT + "/AppleUser", user); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + port = TestLibrary.getRegistryPort(registry); + Naming.rebind("rmi://localhost:" + port + "/AppleUser",user); } catch (RemoteException e) { //TestLibrary.bomb("Failed to bind AppleUser", e); } catch (java.net.MalformedURLException e) { @@ -263,10 +265,9 @@ public class AppleUserImpl // start the other server if available try { Class app = Class.forName("ApplicationServer"); - server = new Thread((Runnable) app.newInstance()); - logger.log(Level.INFO, "Starting application server " + - "in same process"); - server.start(); + java.lang.reflect.Constructor appConstructor = + app.getDeclaredConstructor(new Class[] {Integer.TYPE}); + server = new Thread((Runnable) appConstructor.newInstance(port)); } catch (ClassNotFoundException e) { // assume the other server is running in a separate process logger.log(Level.INFO, "Application server must be " + diff --git a/test/sun/rmi/rmic/newrmic/equivalence/run.sh b/test/sun/rmi/rmic/newrmic/equivalence/run.sh index 839c0ce8d..8d4f419d3 100644 --- a/test/sun/rmi/rmic/newrmic/equivalence/run.sh +++ b/test/sun/rmi/rmic/newrmic/equivalence/run.sh @@ -1,5 +1,5 @@ # -# Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2003, 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 @@ -26,6 +26,8 @@ # @summary This test verifies that the new implementation of rmic # generates equivalent classes as the old implementation, for a set # of sample input classes. +# @library ../../../../../java/rmi/testlibrary +# @build TestLibrary # @author Peter Jones # # @build AgentServerImpl diff --git a/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java b/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java index cd1541ccb..e5e19fe12 100644 --- a/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java +++ b/test/sun/rmi/runtime/Log/6409194/NoConsoleOutput.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 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 @@ -90,7 +90,6 @@ public class NoConsoleOutput { } public static class DoRMIStuff { - private static final int PORT = 2020; private interface Foo extends Remote { Object echo(Object obj) throws RemoteException; } @@ -99,8 +98,9 @@ public class NoConsoleOutput { public Object echo(Object obj) { return obj; } } public static void main(String[] args) throws Exception { - LocateRegistry.createRegistry(PORT); - Registry reg = LocateRegistry.getRegistry("", PORT); + Registry registry = TestLibrary.createRegistryOnUnusedPort(); + int registryPort = TestLibrary.getRegistryPort(registry); + Registry reg = LocateRegistry.getRegistry("", registryPort); FooImpl fooimpl = new FooImpl(); UnicastRemoteObject.exportObject(fooimpl, 0); reg.rebind("foo", fooimpl); diff --git a/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java b/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java index 7039c1364..77c236d43 100644 --- a/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java +++ b/test/sun/rmi/runtime/Log/checkLogging/CheckLogging.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -77,8 +77,9 @@ import java.rmi.registry.Registry; * logger output is non-null. */ public class CheckLogging { - private static final String LOCATION = - "rmi://localhost:" + TestLibrary.REGISTRY_PORT + "/"; + private static int REGISTRY_PORT = -1; + private static String LOCATION; + private static final ByteArrayOutputStream clientCallOut = new ByteArrayOutputStream(); @@ -100,7 +101,9 @@ public class CheckLogging { private static Registry registry; static { try { - registry = LocateRegistry.createRegistry(TestLibrary.REGISTRY_PORT); + registry = TestLibrary.createRegistryOnUnusedPort(); + REGISTRY_PORT = TestLibrary.getRegistryPort(registry); + LOCATION = "rmi://localhost:" + REGISTRY_PORT + "/"; } catch (Exception e) { TestLibrary.bomb("could not create registry"); } diff --git a/test/sun/rmi/transport/proxy/EagerHttpFallback.java b/test/sun/rmi/transport/proxy/EagerHttpFallback.java index 049ed1ad3..1f54e2cb8 100644 --- a/test/sun/rmi/transport/proxy/EagerHttpFallback.java +++ b/test/sun/rmi/transport/proxy/EagerHttpFallback.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2002, 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 @@ -25,6 +25,8 @@ * @bug 4290727 * @summary Verify that ConnectException will trigger HTTP fallback if * sun.rmi.transport.proxy.eagerHttpFallback system property is set. + * @library ../../../../java/rmi/testlibrary + * @build TestLibrary * @run main/othervm EagerHttpFallback */ @@ -33,8 +35,8 @@ import java.rmi.registry.*; public class EagerHttpFallback { - static final int INITIAL_PORT = 7070; - static final int FALLBACK_PORT = 7071; + static final int INITIAL_PORT = TestLibrary.getUnusedRandomPort(); + static final int FALLBACK_PORT = TestLibrary.getUnusedRandomPort(); public static void main(String[] args) throws Exception { System.setProperty("http.proxyHost", "127.0.0.1"); diff --git a/test/sun/rmi/transport/tcp/DeadCachedConnection.java b/test/sun/rmi/transport/tcp/DeadCachedConnection.java index 533c4aa09..1372b03fe 100644 --- a/test/sun/rmi/transport/tcp/DeadCachedConnection.java +++ b/test/sun/rmi/transport/tcp/DeadCachedConnection.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 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 @@ -58,7 +58,7 @@ import java.rmi.registry.*; import java.rmi.server.*; public class DeadCachedConnection { - static public final int regport = 17340; + static public final int regport = TestLibrary.getUnusedRandomPort(); static public void main(String[] argv) throws Exception { -- GitLab