8085192: java/rmi/activation/Activatable tests fail intermittently due to "Port already in use"

Reviewed-by: rriggs, mli
This commit is contained in:
Chris Hegarty 2016-10-25 10:31:49 +01:00
parent 6ce08d0985
commit 905cdfdf66
62 changed files with 366 additions and 48 deletions

View File

@ -1970,6 +1970,11 @@ public class Activation implements Serializable {
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws IOException {
boolean disable = Boolean.getBoolean(
"sun.rmi.server.activation.disableErrRedirect");
if (disable)
return null;
File file =
Files.createTempFile("rmid-err", null).toFile();
PrintStream errStream =

View File

@ -40,7 +40,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivateMe CheckActivateRef_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivateMe CheckActivateRef_Stub
* @run main/othervm/policy=security.policy/timeout=240 -Djava.rmi.server.ignoreStubClasses=true CheckActivateRef
* @run main/othervm/policy=security.policy/timeout=240 -Djava.rmi.server.ignoreStubClasses=false CheckActivateRef
* @key intermittent
@ -118,7 +119,7 @@ public class CheckActivateRef
// start an rmid.
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -2,4 +2,6 @@ grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.rmi.server.useDynamicProxies=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -38,4 +38,6 @@ grant {
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID MyRMI CheckAnnotations_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider MyRMI CheckAnnotations_Stub
* @run main/othervm/policy=security.policy/timeout=480 CheckAnnotations
*/
@ -77,7 +78,7 @@ public class CheckAnnotations
// start an rmid.
RMID.removeLog();
rmid = RMID.createRMID(rmidOut, rmidErr, false);
rmid = RMID.createRMIDOnEphemeralPort(rmidOut, rmidErr, false);
rmid.start();
/* Cause activation groups to have a security policy that will
@ -228,6 +229,7 @@ public class CheckAnnotations
return false;
}
// just make sure that last two strings are what we expect.
if (execOut.equals("ExecGroup-" + iteration)
&& (new String(destOut.substring(0,4)).equals("out" +

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -28,4 +28,7 @@ grant {
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider
* MyRMI ActivatableImpl ActivatableImpl ActivatableImpl_Stub
* @run main/othervm/policy=security.policy/timeout=150 CheckImplClassLoader
*/
@ -80,7 +81,7 @@ public class CheckImplClassLoader {
TestParams.defaultSecurityManager);
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("Create activation group in this VM");

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -39,4 +39,7 @@ grant {
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe CheckRegisterInLog_Stub
* @run main/othervm/policy=security.policy/timeout=240 CheckRegisterInLog
*/
@ -99,7 +100,7 @@ public class CheckRegisterInLog
* Start up activation system daemon "rmid".
*/
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,4 +31,7 @@ grant {
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivateMe
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivateMe
* @run main/othervm/policy=security.policy/timeout=240 CreatePrivateActivatable
*/
@ -103,7 +104,7 @@ public class CreatePrivateActivatable
// start an rmid.
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,4 +31,7 @@ grant {
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -35,7 +35,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* Foo FooReceiverImpl FooReceiverImpl_Stub Bar
* @run main/othervm/policy=security.policy/timeout=240 DownloadParameterClass
*/
@ -90,7 +91,7 @@ public class DownloadParameterClass {
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -34,4 +34,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -35,4 +35,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivateMe ElucidateNoSuchMethod_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivateMe ElucidateNoSuchMethod_Stub
* @run main/othervm/policy=security.policy/timeout=240 ElucidateNoSuchMethod
*/
@ -91,7 +92,7 @@ public class ElucidateNoSuchMethod
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,7 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -37,4 +37,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -37,7 +37,7 @@ public class ExtLoadedImplTest {
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
Properties p = new Properties();
p.put("java.security.policy",

View File

@ -27,7 +27,7 @@
# loader, the context class loader should remain unchanged (i.e., not be
# set to the impl's class loader) when the impl is activated.
# @library ../../../testlibrary
# @build TestLibrary RMID ActivationLibrary
# @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
# @build ExtLoadedImplTest ExtLoadedImpl ExtLoadedImpl_Stub CheckLoader
# @run shell ext.sh

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe ForceLogSnapshot_Stub
* @run main/othervm/policy=security.policy/timeout=640 ForceLogSnapshot
*/
@ -129,7 +130,7 @@ public class ForceLogSnapshot
SNAPSHOT_INTERVAL;
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.addOptions(new String[] {option, "-Djava.compiler="});
rmid.start();

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,4 +31,7 @@ grant {
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -33,7 +33,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary ActivateMe InactiveGroup_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe InactiveGroup_Stub
* @run main/othervm/policy=security.policy/timeout=240 InactiveGroup
*/
@ -101,7 +102,7 @@ public class InactiveGroup
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,4 +31,7 @@ grant {
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -33,7 +33,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* @run main/othervm/timeout=240 LookupActivationSystem
*/
@ -55,7 +56,7 @@ public class LookupActivationSystem implements Remote, Serializable {
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("look up activation system");

View File

@ -0,0 +1,4 @@
grant {
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary ActivateMe NestedActivate_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe NestedActivate_Stub
* @run main/othervm/policy=security.policy/timeout=240 NestedActivate
*/
@ -101,7 +102,7 @@ public class NestedActivate
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,4 +31,7 @@ grant {
// allow exporting of non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe NonExistentActivatable_Stub
* @run main/othervm/policy=security.policy/timeout=240 NonExistentActivatable
*/
@ -91,7 +92,7 @@ public class NonExistentActivatable
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,4 +32,6 @@ grant {
// allow exporting object with non-public remote interface
permission java.rmi.RMIPermission "exportRemoteInterface.ActivateMe";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivateMe RestartCrashedService_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivateMe RestartCrashedService_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartCrashedService
*/
@ -119,7 +120,7 @@ public class RestartCrashedService
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -28,4 +28,7 @@ grant {
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -31,7 +31,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* RestartLatecomer RestartLatecomer_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartLatecomer
*/
@ -166,7 +167,7 @@ public class RestartLatecomer
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -33,4 +33,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary ActivateMe RestartService_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe RestartService_Stub
* @run main/othervm/policy=security.policy/timeout=240 RestartService
*/
@ -129,7 +130,7 @@ public class RestartService
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -33,4 +33,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider
* TestSecurityManager RegisteringActivatable ShutdownGracefully_Stub
* @run main/othervm/policy=security.policy/timeout=700 ShutdownGracefully
*/
@ -76,7 +77,7 @@ public class ShutdownGracefully
// start an rmid.
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
// rmid needs to run with a security manager that
// simulates a log problem; rmid should also snapshot

View File

@ -2,4 +2,6 @@ grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=java.lang.SecurityManager";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission com.sun.rmi.rmid.ExecOptionPermission "-Ddummyname=dummyvalue";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -25,4 +25,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -32,7 +32,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary ActivateMe UnregisterInactive_Stub
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary ActivateMe UnregisterInactive_Stub
* @run main/othervm/policy=security.policy/timeout=240 UnregisterInactive
*/
@ -89,7 +90,7 @@ public class UnregisterInactive
try {
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
System.err.println("Creating descriptor");

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -28,4 +28,7 @@ grant {
// allow exporting of remote objects on an arbitrary port.
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -35,7 +35,8 @@
* java.rmi/sun.rmi.server
* java.rmi/sun.rmi.transport
* java.rmi/sun.rmi.transport.tcp
* @build TestLibrary RMID ActivationLibrary
* java.base/sun.nio.ch
* @build TestLibrary RMID RMIDSelectorProvider ActivationLibrary
* ActivateMe ActivateFails_Stub ShutdownThread
* @run main/othervm/java.security.policy=security.policy/timeout=240 ActivateFails
*/
@ -93,7 +94,7 @@ public class ActivateFails
* First run "rmid" and wait for it to start up.
*/
RMID.removeLog();
rmid = RMID.createRMID();
rmid = RMID.createRMIDOnEphemeralPort();
rmid.start();
/* Cause activation groups to have a security policy that will

View File

@ -1,4 +1,6 @@
grant {
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.manager=default";
permission com.sun.rmi.rmid.ExecOptionPermission "-Djava.security.policy=*";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -28,4 +28,7 @@ grant {
// test needs to export rmid and communicate with objects on arbitrary ports
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
permission java.lang.RuntimePermission "selectorProvider";
permission java.lang.RuntimePermission "accessClassInPackage.sun.nio.ch";
};

View File

@ -51,6 +51,8 @@ import java.rmi.activation.ActivationSystem;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import static java.net.StandardSocketOptions.SO_REUSEADDR;
import static java.net.StandardSocketOptions.SO_REUSEPORT;
public class RmidViaInheritedChannel implements Callback {
private static final Object lock = new Object();
@ -185,6 +187,15 @@ public class RmidViaInheritedChannel implements Callback {
*/
channel = ServerSocketChannel.open();
ServerSocket serverSocket = channel.socket();
// Enable SO_REUSEADDR before binding
serverSocket.setOption(SO_REUSEADDR, true);
// Enable SO_REUSEPORT, if supported, before binding
if (serverSocket.supportedOptions().contains(SO_REUSEPORT)) {
serverSocket.setOption(SO_REUSEPORT, true);
}
serverSocket.bind(
new InetSocketAddress(InetAddress.getLocalHost(),
TestLibrary.RMIDVIAINHERITEDCHANNEL_ACTIVATION_PORT));

View File

@ -21,8 +21,11 @@
* questions.
*/
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.StringTokenizer;
@ -39,8 +42,8 @@ public class JavaVM {
protected Process vm = null;
private String classname = "";
private String args = "";
private String options = "";
protected String args = "";
protected String options = "";
private OutputStream outputStream = System.out;
private OutputStream errorStream = System.err;
private String policyFileName = null;
@ -113,7 +116,7 @@ public class JavaVM {
/**
* Exec the VM as specified in this object's constructor.
*/
public void start() throws IOException {
private void start0() throws IOException {
if (vm != null)
throw new IllegalStateException("JavaVM already started");
@ -152,12 +155,50 @@ public class JavaVM {
mesg("command = " + Arrays.asList(javaCommand).toString());
vm = Runtime.getRuntime().exec(javaCommand);
}
/* output from the execed process may optionally be captured. */
public void start() throws IOException {
start0();
/* output from the exec'ed process may optionally be captured. */
outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
}
public int startAndGetPort() throws IOException {
start0();
int port = -1;
if (options.contains("java.nio.channels.spi.SelectorProvider=RMIDSelectorProvider")) {
// Obtain the server socket channel's ephemeral port number of the
// child rmid process.
BufferedReader reader = new BufferedReader(
new InputStreamReader(vm.getInputStream()));
String s;
while ((s = reader.readLine()) != null) {
System.out.println(s);
int i = s.indexOf(RMID.EPHEMERAL_MSG);
if (i != -1) {
String v = s.substring(RMID.EPHEMERAL_MSG.length());
port = Integer.valueOf(v);
break;
}
}
if (port == -1) {
// something failed
reader = new BufferedReader(new InputStreamReader(vm.getErrorStream()));
while ((s = reader.readLine()) != null)
System.err.println(s);
}
}
/* output from the exec'ed process may optionally be captured. */
outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
return port;
}
public void destroy() {
if (vm != null) {
vm.destroy();

View File

@ -49,20 +49,31 @@ public class RMID extends JavaVM {
public static String MANAGER_OPTION="-Djava.security.manager=";
/** Test port for rmid */
private final int port;
/**
* Test port for rmid.
*
* May initially be 0, which means that the child rmid process will choose
* an ephemeral port and report it back to the parent process. This field
* will then be set to the child rmid's ephemeral port value.
*/
private volatile int port;
//private final boolean ephemeralPort
/** Initial log name */
protected static String log = "log";
/** rmid's logfile directory; currently must be "." */
protected static String LOGDIR = ".";
/** The output message from the child rmid process that directly precedes
* the ephemeral port number.*/
public static final String EPHEMERAL_MSG = "RmidSelectorProvider-listening-On:";
private static void mesg(Object mesg) {
System.err.println("RMID: " + mesg.toString());
}
/** make test options and arguments */
private static String makeOptions(boolean debugExec) {
private static String makeOptions(int port, boolean debugExec) {
String options = " -Dsun.rmi.server.activation.debugExec=" +
debugExec;
@ -87,6 +98,17 @@ public class RMID extends JavaVM {
// to avoid spurious timeouts on slow machines.
options += " -Dsun.rmi.activation.execTimeout=60000";
if (port == 0) {
// Ephemeral port, so have the rmid child process create the
// server socket channel and report its port number, over stdin.
options += " -classpath " + TestParams.testClassPath;
options += " --add-exports=java.base/sun.nio.ch=ALL-UNNAMED";
options += " -Djava.nio.channels.spi.SelectorProvider=RMIDSelectorProvider";
// Disable redirection of System.err to /tmp
options += " -Dsun.rmi.server.activation.disableErrRedirect=true";
}
return options;
}
@ -107,7 +129,8 @@ public class RMID extends JavaVM {
String args =
" -log " + (new File(LOGDIR, log)).getAbsolutePath();
if (includePortArg) {
// 0 = ephemeral port, do not include an explicit port number
if (includePortArg && port != 0) {
args += " -port " + port;
}
@ -160,7 +183,7 @@ public class RMID extends JavaVM {
boolean debugExec, boolean includePortArg,
int port)
{
String options = makeOptions(debugExec);
String options = makeOptions(port, debugExec);
String args = makeArgs(includePortArg, port);
RMID rmid = new RMID("sun.rmi.server.Activation", options, args,
out, err, port);
@ -169,6 +192,17 @@ public class RMID extends JavaVM {
return rmid;
}
public static RMID createRMIDOnEphemeralPort() {
return createRMID(System.out, System.err, true, true, 0);
}
public static RMID createRMIDOnEphemeralPort(OutputStream out,
OutputStream err,
boolean debugExec)
{
return createRMID(out, err, debugExec, true, 0);
}
/**
* Private constructor. RMID instances should be created
@ -247,7 +281,10 @@ public class RMID extends JavaVM {
// a well recognized exception (port already in use...).
mesg("Starting rmid on port " + port + ".");
super.start();
int p = super.startAndGetPort();
if (p != -1)
port = p;
mesg("Started rmid on port " + port + ".");
// int slopFactor = 1;
// try {
@ -271,8 +308,11 @@ public class RMID extends JavaVM {
try {
int status = vm.exitValue();
waitFor(TIMEOUT_SHUTDOWN_MS);
TestLibrary.bomb("Rmid process exited with status " + status + " after " +
(System.currentTimeMillis() - startTime) + "ms.");
} catch (InterruptedException | TimeoutException e) {
mesg(e);
} catch (IllegalThreadStateException ignore) { }
// The rmid process is alive; check to see whether
@ -307,6 +347,8 @@ public class RMID extends JavaVM {
*/
public void restart() throws IOException {
destroy();
options = makeOptions(port, true);
args = makeArgs(true, port);
start();
}

View File

@ -0,0 +1,107 @@
/*
* Copyright (c) 2016, 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.
*/
import java.io.*;
import java.net.InetSocketAddress;
import java.net.ProtocolFamily;
import java.nio.channels.Channel;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Pipe;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.spi.AbstractSelector;
import java.nio.channels.spi.SelectorProvider;
import static java.net.StandardSocketOptions.SO_REUSEADDR;
import static java.net.StandardSocketOptions.SO_REUSEPORT;
/**
* A SelectorProvider, that can be loaded by the child rmid process, whose
* inheritedChannel method will create a new server socket channel and report
* it back to the parent process, over stdout.
*/
public class RMIDSelectorProvider extends SelectorProvider {
private final SelectorProvider provider;
private ServerSocketChannel channel;
public RMIDSelectorProvider() {
provider = sun.nio.ch.DefaultSelectorProvider.create();
}
public DatagramChannel openDatagramChannel()
throws IOException
{
return provider.openDatagramChannel();
}
public DatagramChannel openDatagramChannel(ProtocolFamily family)
throws IOException
{
return provider.openDatagramChannel(family);
}
public Pipe openPipe()
throws IOException
{
return provider.openPipe();
}
public AbstractSelector openSelector()
throws IOException
{
return provider.openSelector();
}
public ServerSocketChannel openServerSocketChannel()
throws IOException
{
return provider.openServerSocketChannel();
}
public SocketChannel openSocketChannel()
throws IOException
{
return provider.openSocketChannel();
}
public synchronized Channel inheritedChannel() throws IOException {
System.out.println("RMIDSelectorProvider.inheritedChannel");
if (channel == null) {
// Create and bind a new server socket channel
channel = ServerSocketChannel.open();
// Enable SO_REUSEADDR before binding
channel.setOption(SO_REUSEADDR, true);
// Enable SO_REUSEPORT, if supported, before binding
if (channel.supportedOptions().contains(SO_REUSEPORT)) {
channel.setOption(SO_REUSEPORT, true);
}
channel.bind(new InetSocketAddress(0));
System.out.println(RMID.EPHEMERAL_MSG + channel.socket().getLocalPort());
}
return channel;
}
}

View File

@ -34,6 +34,7 @@ public class TestParams {
/** variables that hold value property values */
public static final String testSrc;
public static final String testClasses;
public static final String testClassPath;
/** name of default security policy for test JVM */
public static final String defaultPolicy;
@ -57,6 +58,7 @@ public class TestParams {
static {
testSrc = TestLibrary.getProperty("test.src", ".");
testClasses = TestLibrary.getProperty("test.classes", ".");
testClassPath = TestLibrary.getProperty("test.class.path", ".");
String dp = TestLibrary.getProperty("java.security.policy", null);
if (dp == null) {