7186111: fix bugs in java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup
Reviewed-by: smarks, jgish
This commit is contained in:
parent
37f0895031
commit
1625e2019e
@ -45,30 +45,23 @@ import java.rmi.registry.*;
|
||||
import java.util.Properties;
|
||||
|
||||
class Callback extends UnicastRemoteObject implements CallbackInterface {
|
||||
|
||||
public static int num_deactivated = 0;
|
||||
public int num_deactivated = 0;
|
||||
|
||||
public Callback() throws RemoteException { super(); }
|
||||
|
||||
public void inc() throws RemoteException {
|
||||
incNumDeactivated();
|
||||
}
|
||||
|
||||
public synchronized int getNumDeactivated() throws RemoteException {
|
||||
return(num_deactivated);
|
||||
}
|
||||
|
||||
public synchronized void incNumDeactivated() {
|
||||
public synchronized void inc() throws RemoteException {
|
||||
num_deactivated++;
|
||||
}
|
||||
|
||||
public synchronized int getNumDeactivated() throws RemoteException {
|
||||
return num_deactivated;
|
||||
}
|
||||
}
|
||||
|
||||
public class UnregisterGroup
|
||||
extends Activatable
|
||||
implements ActivateMe, Runnable
|
||||
{
|
||||
|
||||
private static Exception exception = null;
|
||||
private static String error = null;
|
||||
private static boolean done = false;
|
||||
@ -104,36 +97,47 @@ public class UnregisterGroup
|
||||
}
|
||||
|
||||
/**
|
||||
* Thread to deactivate object. First attempts to make object
|
||||
* inactive (via the inactive method). If that fails (the
|
||||
* object may still have pending/executing calls), then
|
||||
* unexport the object forcibly.
|
||||
* Thread to deactivate object. Get the callback object from the registry,
|
||||
* call inc() on it, and finally call deactivate(). The call to
|
||||
* deactivate() causes this JVM to be destroyed, so anything following
|
||||
* might not be executed.
|
||||
*/
|
||||
public void run() {
|
||||
String regPortStr = System.getProperty("unregisterGroup.port");
|
||||
int regPort = -1;
|
||||
|
||||
ActivationLibrary.deactivate(this, getID());
|
||||
System.err.println("\tActivationLibrary.deactivate returned");
|
||||
if (regPortStr != null) {
|
||||
regPort = Integer.parseInt(regPortStr);
|
||||
}
|
||||
|
||||
try {
|
||||
CallbackInterface cobj =
|
||||
(CallbackInterface)Naming.lookup("//:" + registryPort + "/Callback");
|
||||
(CallbackInterface)Naming.lookup("//:" + regPort + "/Callback");
|
||||
cobj.inc();
|
||||
System.err.println("cobj.inc called and returned ok");
|
||||
} catch (Exception e) {
|
||||
System.err.println("cobj.inc exception");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
ActivationLibrary.deactivate(this, getID());
|
||||
System.err.println("\tActivationLibrary.deactivate returned");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Registry registry;
|
||||
|
||||
public static void main(String[] args) throws RemoteException {
|
||||
System.err.println("\nRegression test for bug 4134233\n");
|
||||
|
||||
TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager");
|
||||
RMID rmid = null;
|
||||
|
||||
// Create registry and export callback object so they're
|
||||
// available to the objects that are activated below.
|
||||
// TODO: see if we can use RMID's registry instead of
|
||||
// creating one here.
|
||||
Registry registry = TestLibrary.createRegistryOnUnusedPort();
|
||||
registryPort = TestLibrary.getRegistryPort(registry);
|
||||
Callback robj = new Callback();
|
||||
registry.rebind("Callback", robj);
|
||||
|
||||
try {
|
||||
RMID.removeLog();
|
||||
rmid = RMID.createRMID();
|
||||
@ -149,8 +153,7 @@ public class UnregisterGroup
|
||||
TestParams.defaultGroupPolicy);
|
||||
p.put("java.security.manager",
|
||||
TestParams.defaultSecurityManager);
|
||||
|
||||
//final int NUM_OBJECTS = 10;
|
||||
p.put("unregisterGroup.port", Integer.toString(registryPort));
|
||||
|
||||
Thread t = new Thread() {
|
||||
public void run () {
|
||||
@ -219,8 +222,6 @@ public class UnregisterGroup
|
||||
} else {
|
||||
System.err.println("Test passed");
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
TestLibrary.bomb("test failed", e);
|
||||
} finally {
|
||||
@ -233,13 +234,6 @@ public class UnregisterGroup
|
||||
|
||||
// Wait for the object deactivation to take place first
|
||||
try {
|
||||
|
||||
// create reg and export callback object
|
||||
registry = TestLibrary.createRegistryOnUnusedPort();
|
||||
registryPort = TestLibrary.getRegistryPort(registry);
|
||||
Callback robj = new Callback();
|
||||
registry.bind("Callback", robj);
|
||||
|
||||
//get the callback object
|
||||
int maxwait=30;
|
||||
int nd = robj.getNumDeactivated();
|
||||
|
@ -7,4 +7,5 @@ grant {
|
||||
|
||||
// test needs to communicate with the activation system
|
||||
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
|
||||
permission java.util.PropertyPermission "unregisterGroup.port", "read";
|
||||
};
|
||||
|
@ -1,4 +1,5 @@
|
||||
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 "-DunregisterGroup.port=*";
|
||||
};
|
||||
|
@ -33,4 +33,10 @@ grant {
|
||||
|
||||
// test needs to export rmid and communicate with objects on arbitrary ports
|
||||
permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
|
||||
|
||||
// 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";
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user