changeset 5252:e63a54172486

7186111: fix bugs in java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup Reviewed-by: smarks, jgish
author dmocek
date Fri, 27 Jul 2012 16:53:15 -0700
parents 295bad1785ee
children 0ec52ab2f2f0
files test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy
diffstat 4 files changed, 40 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/test/java/rmi/activation/ActivationSystem/unregisterGroup/UnregisterGroup.java	Wed Jul 18 10:04:45 2012 -0700
+++ b/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 int num_deactivated = 0;
 
-  public static int num_deactivated = 0;
+    public Callback() throws RemoteException { super(); }
 
-  public Callback() throws RemoteException { super(); }
+    public synchronized void inc() throws RemoteException {
+        num_deactivated++;
+    }
 
-  public void inc() throws RemoteException {
-    incNumDeactivated();
-  }
-
-  public synchronized int getNumDeactivated() throws RemoteException {
-    return(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/test/java/rmi/activation/ActivationSystem/unregisterGroup/group.security.policy	Wed Jul 18 10:04:45 2012 -0700
+++ b/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/test/java/rmi/activation/ActivationSystem/unregisterGroup/rmid.security.policy	Wed Jul 18 10:04:45 2012 -0700
+++ b/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/test/java/rmi/activation/ActivationSystem/unregisterGroup/security.policy	Wed Jul 18 10:04:45 2012 -0700
+++ b/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";
 };