test/java/rmi/testlibrary/TestLibrary.java

Print this page
rev 9344 : 8036095: RMI tests using testlibrary.RMID and testlibrary.JavaVM do not pass through vmoptions
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 1998, 2013, 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  */


 137     public static boolean checkIfRegistryRunning(int port, int msTimeout) {
 138         long stopTime = System.currentTimeMillis() + msTimeout;
 139         do {
 140             try {
 141                 Registry r = LocateRegistry.getRegistry(port);
 142                 String[] s = r.list();
 143                 // no exception. We're now happy that registry is running
 144                 return true;
 145             } catch (RemoteException e) {
 146                 // problem - not ready ? Try again
 147                 try {
 148                     Thread.sleep(500);
 149                 } catch (InterruptedException ie) {
 150                     // not expected
 151                 }
 152             }
 153         } while (stopTime > System.currentTimeMillis());
 154         return false;
 155     }
 156 
 157     public static String getProperty(String property, String defaultVal) {
 158         final String prop = property;
 159         final String def = defaultVal;
 160         return java.security.AccessController.doPrivileged(
 161             new java.security.PrivilegedAction<String>() {
 162                 public String run() {
 163                     return System.getProperty(prop, def);
 164                 }
 165             });




 166     }
 167 
 168     /**
 169      * Property mutators
 170      */
 171     public static void setBoolean(String property, boolean value) {
 172         setProperty(property, (new Boolean(value)).toString());
 173     }
 174     public static void setInteger(String property, int value) {
 175         setProperty(property, Integer.toString(value));
 176     }
 177     public static void setProperty(String property, String value) {
 178         final String prop = property;
 179         final String val = value;
 180         java.security.AccessController.doPrivileged(
 181             new java.security.PrivilegedAction<Void>() {
 182                 public Void run() {
 183                     System.setProperty(prop, val);
 184                     return null;
 185                 }


   1 /*
   2  * Copyright (c) 1998, 2014, 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  */


 137     public static boolean checkIfRegistryRunning(int port, int msTimeout) {
 138         long stopTime = System.currentTimeMillis() + msTimeout;
 139         do {
 140             try {
 141                 Registry r = LocateRegistry.getRegistry(port);
 142                 String[] s = r.list();
 143                 // no exception. We're now happy that registry is running
 144                 return true;
 145             } catch (RemoteException e) {
 146                 // problem - not ready ? Try again
 147                 try {
 148                     Thread.sleep(500);
 149                 } catch (InterruptedException ie) {
 150                     // not expected
 151                 }
 152             }
 153         } while (stopTime > System.currentTimeMillis());
 154         return false;
 155     }
 156 
 157     public static String getProperty(final String property,
 158                                      final String defaultVal) {
 159         try {
 160             return java.security.AccessController.doPrivileged(
 161                 new java.security.PrivilegedAction<String>() {
 162                     public String run() {
 163                         return System.getProperty(property, defaultVal);
 164                     }
 165                 });
 166         } catch (Exception ex) {
 167             bomb("Exception getting property " + property, ex);
 168             throw new AssertionError("this should be unreachable");
 169         }
 170     }
 171 
 172     /**
 173      * Property mutators
 174      */
 175     public static void setBoolean(String property, boolean value) {
 176         setProperty(property, (new Boolean(value)).toString());
 177     }
 178     public static void setInteger(String property, int value) {
 179         setProperty(property, Integer.toString(value));
 180     }
 181     public static void setProperty(String property, String value) {
 182         final String prop = property;
 183         final String val = value;
 184         java.security.AccessController.doPrivileged(
 185             new java.security.PrivilegedAction<Void>() {
 186                 public Void run() {
 187                     System.setProperty(prop, val);
 188                     return null;
 189                 }