test/java/rmi/activation/CommandEnvironment/SetChildEnv.java

Print this page


   1 /*
   2  * Copyright (c) 1998, 2000, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  36  *
  37  * @library ../../testlibrary
  38  * @build TestLibrary RMID JavaVM StreamPipe
  39  * @build Eliza Retireable Doctor Doctor_Stub SetChildEnv
  40  * @run main/othervm/timeout=240/policy=security.policy -Djava.compiler=NONE  SetChildEnv
  41  */
  42 import java.rmi.*;
  43 import java.util.Properties;
  44 import java.io.*;
  45 import java.util.StringTokenizer;
  46 import java.util.Set;
  47 import java.util.HashSet;
  48 import java.util.Arrays;
  49 import java.rmi.activation.*;
  50 
  51 public class SetChildEnv
  52 {
  53     public static void main(String argv[])
  54         throws Exception
  55     {


  56         System.out.println("java.compiler=" + System.getProperty("java.compiler"));
  57         // don't embed spaces in any of the test args/props, because
  58         // they won't be parsed properly
  59         runwith (new String[0], new String[0]);
  60 
  61         runwith (
  62             new String[] { "-verbosegc" },
  63             new String[] { "foo.bar=SetChildEnvTest",
  64                            "sun.rmi.server.doSomething=true" }

  65             );
  66 
  67         runwith (
  68             new String[] { },
  69             new String[] { "parameter.count=zero" }

  70             );
  71 
  72         runwith (
  73             new String[] { "-Xmx32m" },
  74             new String[] { }

  75             );
  76     }
  77 
  78     private static void runwith(
  79         String[] params,        // extra args
  80         String[] props          // extra system properties

  81     )
  82         throws Exception
  83     {
  84         TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);
  85 
  86         // make a "watcher" which listens on a pipe and searches for
  87         // the debugExec line while teeing to System.err
  88         DebugExecWatcher watcher = DebugExecWatcher.makeWithPipe();
  89 
  90         RMID.removeLog();
  91         RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(),
  92                                     true); // debugExec turned on

  93 
  94         rmid.start();
  95 
  96         // compile props
  97         Properties p = new Properties();
  98         p.put("java.security.policy", TestParams.defaultGroupPolicy);
  99         p.put("java.security.manager", TestParams.defaultSecurityManager);
 100         //p.put("java.rmi.server.logCalls", "true");
 101         int i;
 102         for (i = 0; i < props.length; i++) {
 103             p.put(props[i].substring(0, props[i].indexOf('=')),
 104                   props[i].substring(props[i].indexOf('=')+1));
 105         }
 106 
 107         // create CommandEnvironment and ActivationGroupDesc
 108         ActivationGroupDesc.CommandEnvironment cmdenv =
 109                 new ActivationGroupDesc.CommandEnvironment(
 110                     null,
 111                     params);
 112 


 178 
 179         int m;
 180         for (m = 0; m < params.length; m++) {
 181             if(!argset.contains(params[m]))
 182                 TestLibrary.bomb("Parameter \"" + params[m] + "\" not set");
 183         }
 184 
 185         for (m = 0; m < props.length; m++) {
 186             if (!argset.contains("-D" + props[m])) {
 187                 TestLibrary.bomb("Property binding \"" + props[m] +
 188                                  "\" not set");
 189             }
 190         }
 191 
 192         // End doctor
 193         if (doctor instanceof Retireable)
 194             ((Retireable)doctor).retire();
 195         actsys.unregisterGroup(gid);
 196 
 197         Thread.sleep(5000);
 198         rmid.destroy();
 199     }
 200 
 201     public static class DebugExecWatcher
 202         extends Thread
 203     {
 204         public String found;
 205         private BufferedReader str;
 206         private OutputStream otherEnd;
 207 
 208         private DebugExecWatcher(InputStream readStream, OutputStream wrStream)
 209         {
 210             super("DebugExecWatcher");
 211             found = null;
 212             str = new BufferedReader(new InputStreamReader(readStream));
 213             otherEnd = wrStream;
 214         }
 215 
 216         static public DebugExecWatcher makeWithPipe()
 217             throws IOException
 218         {


 226         public OutputStream otherEnd()
 227         {
 228             return otherEnd;
 229         }
 230 
 231         public synchronized void notifyLine(String s)
 232         {
 233             if (s != null && s.indexOf("rmid: debugExec") != -1)
 234                 found = s;
 235         }
 236 
 237         public void run()
 238         {
 239             try {
 240                 String line;
 241                 while ((line = str.readLine()) != null) {
 242                     this.notifyLine(line);
 243                     System.err.println(line);
 244                 }
 245             } catch (IOException e) {











 246                 e.printStackTrace();

 247             }
 248         }
 249     }
 250 }
 251 
 252 /*
 253    code graveyard
 254 
 255         // activation should have proceeded by writing a wrapper.out
 256         // when test.src/actgrpwrapper was run.
 257 
 258         // Read and check wrapper.out
 259         BufferedReader r = new BufferedReader(new FileReader(wrapout));
 260         String[] realArgs = null;
 261         String line;
 262 
 263         while ( (line = r.readLine()) != null) {
 264             StringTokenizer tkz = new StringTokenizer(line);
 265             if (!tkz.nextToken().equals("actgrpwrapper")) {
 266                 // could throw an exception, but let's benignly


   1 /*
   2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  36  *
  37  * @library ../../testlibrary
  38  * @build TestLibrary RMID JavaVM StreamPipe
  39  * @build Eliza Retireable Doctor Doctor_Stub SetChildEnv
  40  * @run main/othervm/timeout=240/policy=security.policy -Djava.compiler=NONE  SetChildEnv
  41  */
  42 import java.rmi.*;
  43 import java.util.Properties;
  44 import java.io.*;
  45 import java.util.StringTokenizer;
  46 import java.util.Set;
  47 import java.util.HashSet;
  48 import java.util.Arrays;
  49 import java.rmi.activation.*;
  50 
  51 public class SetChildEnv
  52 {
  53     public static void main(String argv[])
  54         throws Exception
  55     {
  56         int runningPort = TestLibrary.getUnusedRandomPort();
  57 
  58         System.out.println("java.compiler=" + System.getProperty("java.compiler"));
  59         // don't embed spaces in any of the test args/props, because
  60         // they won't be parsed properly
  61         runwith (new String[0], new String[0], runningPort);
  62 
  63         runwith (
  64             new String[] { "-verbosegc" },
  65             new String[] { "foo.bar=SetChildEnvTest",
  66                            "sun.rmi.server.doSomething=true" },
  67             runningPort
  68             );
  69 
  70         runwith (
  71             new String[] { },
  72             new String[] { "parameter.count=zero" },
  73             runningPort
  74             );
  75 
  76         runwith (
  77             new String[] { "-Xmx32m" },
  78             new String[] { },
  79             runningPort
  80             );
  81     }
  82 
  83     private static void runwith(
  84         String[] params,        // extra args
  85         String[] props,         // extra system properties
  86         int port                // port on which to communicate
  87     )
  88         throws Exception
  89     {
  90         TestLibrary.suggestSecurityManager(TestParams.defaultSecurityManager);
  91 
  92         // make a "watcher" which listens on a pipe and searches for
  93         // the debugExec line while teeing to System.err
  94         DebugExecWatcher watcher = DebugExecWatcher.makeWithPipe();
  95 
  96         RMID.removeLog();
  97         RMID rmid = RMID.createRMID(watcher.otherEnd(), watcher.otherEnd(),
  98                                     true,  // debugExec turned on
  99                                     true, port);
 100 
 101         rmid.start();
 102 
 103         // compile props
 104         Properties p = new Properties();
 105         p.put("java.security.policy", TestParams.defaultGroupPolicy);
 106         p.put("java.security.manager", TestParams.defaultSecurityManager);
 107         //p.put("java.rmi.server.logCalls", "true");
 108         int i;
 109         for (i = 0; i < props.length; i++) {
 110             p.put(props[i].substring(0, props[i].indexOf('=')),
 111                   props[i].substring(props[i].indexOf('=')+1));
 112         }
 113 
 114         // create CommandEnvironment and ActivationGroupDesc
 115         ActivationGroupDesc.CommandEnvironment cmdenv =
 116                 new ActivationGroupDesc.CommandEnvironment(
 117                     null,
 118                     params);
 119 


 185 
 186         int m;
 187         for (m = 0; m < params.length; m++) {
 188             if(!argset.contains(params[m]))
 189                 TestLibrary.bomb("Parameter \"" + params[m] + "\" not set");
 190         }
 191 
 192         for (m = 0; m < props.length; m++) {
 193             if (!argset.contains("-D" + props[m])) {
 194                 TestLibrary.bomb("Property binding \"" + props[m] +
 195                                  "\" not set");
 196             }
 197         }
 198 
 199         // End doctor
 200         if (doctor instanceof Retireable)
 201             ((Retireable)doctor).retire();
 202         actsys.unregisterGroup(gid);
 203 
 204         Thread.sleep(5000);
 205         ActivationLibrary.rmidCleanup(rmid);
 206     }
 207 
 208     public static class DebugExecWatcher
 209         extends Thread
 210     {
 211         public String found;
 212         private BufferedReader str;
 213         private OutputStream otherEnd;
 214 
 215         private DebugExecWatcher(InputStream readStream, OutputStream wrStream)
 216         {
 217             super("DebugExecWatcher");
 218             found = null;
 219             str = new BufferedReader(new InputStreamReader(readStream));
 220             otherEnd = wrStream;
 221         }
 222 
 223         static public DebugExecWatcher makeWithPipe()
 224             throws IOException
 225         {


 233         public OutputStream otherEnd()
 234         {
 235             return otherEnd;
 236         }
 237 
 238         public synchronized void notifyLine(String s)
 239         {
 240             if (s != null && s.indexOf("rmid: debugExec") != -1)
 241                 found = s;
 242         }
 243 
 244         public void run()
 245         {
 246             try {
 247                 String line;
 248                 while ((line = str.readLine()) != null) {
 249                     this.notifyLine(line);
 250                     System.err.println(line);
 251                 }
 252             } catch (IOException e) {
 253                 /* During termination of distant rmid, StreamPipes will be broken when
 254                  * distant vm terminates. A "Pipe broken" exception is expected because
 255                  * DebugExecWatcher points to the same streams as StreamPipes used by RMID.
 256                  * If we get this exception. We just terminate the thread.
 257                  */
 258                 if (e.getMessage().equals("Pipe broken")) {
 259                     try {
 260                         str.close();
 261                     } catch (IOException ioe) {}
 262                 }
 263                 else {
 264                     e.printStackTrace();
 265                 }
 266             }
 267         }
 268     }
 269 }
 270 
 271 /*
 272    code graveyard
 273 
 274         // activation should have proceeded by writing a wrapper.out
 275         // when test.src/actgrpwrapper was run.
 276 
 277         // Read and check wrapper.out
 278         BufferedReader r = new BufferedReader(new FileReader(wrapout));
 279         String[] realArgs = null;
 280         String line;
 281 
 282         while ( (line = r.readLine()) != null) {
 283             StringTokenizer tkz = new StringTokenizer(line);
 284             if (!tkz.nextToken().equals("actgrpwrapper")) {
 285                 // could throw an exception, but let's benignly