< prev index next >

test/jdk/com/sun/tools/attach/StartManagementAgent.java

Print this page


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


  82         } catch (NullPointerException e) {
  83             exception = true;
  84         }
  85         if (!exception) {
  86             throw new Exception("startManagementAgent(null) should throw NPE");
  87         }
  88 
  89         // Try calling with a property value with a space in it
  90         Properties p = new Properties();
  91         File f = new File("file with space");
  92         try (FileWriter fw = new FileWriter(f)) {
  93             fw.write("com.sun.management.jmxremote.port=apa");
  94         }
  95         p.put("com.sun.management.config.file", f.getAbsolutePath());
  96         try {
  97             System.out.println("Starting management agent with bogus port");
  98             vm.startManagementAgent(p);
  99         } catch(AttachOperationFailedException ex) {
 100             // We expect parsing of "apa" above to fail, but if the file path
 101             // can't be read we get a different exception message
 102             if (!ex.getMessage().contains("Invalid com.sun.management.jmxremote.port number")) {
 103                 throw ex;
 104             }
 105             ex.printStackTrace(System.err);
 106         } catch (Throwable t) {
 107             t.printStackTrace(System.err);
 108             throw t;
 109         }
 110     }
 111 
 112     private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
 113         "com.sun.management.jmxremote.localConnectorAddress";
 114 
 115     private static final int MAX_RETRIES = 10;
 116 
 117     public static void runTests(long pid) throws Exception {
 118         VirtualMachine vm = VirtualMachine.attach(""+pid);
 119         try {
 120 
 121             basicTests(vm);
 122 


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


  82         } catch (NullPointerException e) {
  83             exception = true;
  84         }
  85         if (!exception) {
  86             throw new Exception("startManagementAgent(null) should throw NPE");
  87         }
  88 
  89         // Try calling with a property value with a space in it
  90         Properties p = new Properties();
  91         File f = new File("file with space");
  92         try (FileWriter fw = new FileWriter(f)) {
  93             fw.write("com.sun.management.jmxremote.port=apa");
  94         }
  95         p.put("com.sun.management.config.file", f.getAbsolutePath());
  96         try {
  97             System.out.println("Starting management agent with bogus port");
  98             vm.startManagementAgent(p);
  99         } catch(AttachOperationFailedException ex) {
 100             // We expect parsing of "apa" above to fail, but if the file path
 101             // can't be read we get a different exception message
 102             if (!ex.getMessage().contains("For input string: \"apa\"")) {
 103                 throw ex;
 104             }
 105             ex.printStackTrace(System.err);
 106         } catch (Throwable t) {
 107             t.printStackTrace(System.err);
 108             throw t;
 109         }
 110     }
 111 
 112     private static final String LOCAL_CONNECTOR_ADDRESS_PROP =
 113         "com.sun.management.jmxremote.localConnectorAddress";
 114 
 115     private static final int MAX_RETRIES = 10;
 116 
 117     public static void runTests(long pid) throws Exception {
 118         VirtualMachine vm = VirtualMachine.attach(""+pid);
 119         try {
 120 
 121             basicTests(vm);
 122 


< prev index next >