7186111: fix bugs in java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup
authordmocek
Fri, 27 Jul 2012 16:53:15 -0700
changeset 13371 ccc8ddc94dda
parent 13370 785cedd026db
child 13372 5d8d9440d223
7186111: fix bugs in java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup Reviewed-by: smarks, jgish
jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java
jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy
jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy
jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy
--- a/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java	Thu Jul 26 22:00:55 2012 +0100
+++ b/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java	Fri Jul 27 16:53:15 2012 -0700
@@ -45,30 +45,23 @@
 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 Callback() throws RemoteException { super(); }
 
-  public synchronized int getNumDeactivated() throws RemoteException {
-    return(num_deactivated);
-  }
+    public synchronized void inc() throws RemoteException {
+        num_deactivated++;
+    }
 
-  public synchronized void incNumDeactivated() {
-    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 @@
     }
 
     /**
-     * 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 @@
                   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 @@
             } else {
                 System.err.println("Test passed");
             }
-
-
         } catch (Exception e) {
             TestLibrary.bomb("test failed", e);
         } finally {
@@ -233,13 +234,6 @@
 
             // 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();
--- a/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy	Thu Jul 26 22:00:55 2012 +0100
+++ b/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy	Fri Jul 27 16:53:15 2012 -0700
@@ -7,4 +7,5 @@
 
   // test needs to communicate with the activation system
   permission java.net.SocketPermission "*:1024-", "connect,accept,listen";
+  permission java.util.PropertyPermission "unregisterGroup.port", "read";
 };
--- a/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy	Thu Jul 26 22:00:55 2012 +0100
+++ b/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy	Fri Jul 27 16:53:15 2012 -0700
@@ -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=*";
 };
--- a/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy	Thu Jul 26 22:00:55 2012 +0100
+++ b/jdk/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy	Fri Jul 27 16:53:15 2012 -0700
@@ -33,4 +33,10 @@
 
   // 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";
 };