< prev index next >

test/jdk/sun/jvmstat/monitor/MonitoredVm/MonitorVmStartTerminate.java

Print this page
rev 51638 : [mq]: 8210112


   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  */
  23 
  24 import java.io.File;
  25 import java.io.IOException;
  26 import java.net.URISyntaxException;
  27 import java.nio.file.Files;
  28 import java.nio.file.Path;
  29 import java.nio.file.Paths;
  30 import java.nio.file.StandardOpenOption;
  31 import java.util.ArrayList;
  32 import java.util.List;
  33 import java.util.Set;
  34 import java.util.UUID;
  35 import java.util.concurrent.Semaphore;
  36 
  37 import jdk.testlibrary.OutputAnalyzer;
  38 import jdk.testlibrary.ProcessTools;
  39 import sun.jvmstat.monitor.MonitorException;
  40 import sun.jvmstat.monitor.MonitoredHost;
  41 import sun.jvmstat.monitor.MonitoredVm;
  42 import sun.jvmstat.monitor.MonitoredVmUtil;
  43 import sun.jvmstat.monitor.VmIdentifier;
  44 import sun.jvmstat.monitor.event.HostEvent;
  45 import sun.jvmstat.monitor.event.HostListener;
  46 import sun.jvmstat.monitor.event.VmStatusChangeEvent;
  47 
  48 /*
  49 
  50  Test starts ten Java processes, each with a unique id.
  51 
  52  Each process creates a file named after the id and then it waits for
  53  the test to remove the file, at which the Java process exits.
  54 
  55  The processes are monitored by the test to make sure notifications
  56  are sent when they are started/terminated.
  57 
  58  To avoid Java processes being left behind, in case of an unexpected
  59  failure, shutdown hooks are installed that remove files when the test
  60  exits. If files are not removed, i.e. due to a JVM crash, the Java
  61  processes will exit themselves after 1000 s.
  62 
  63 */
  64 
  65 /*
  66  * @test
  67  * @bug 4990825
  68  * @summary attach to external but local JVM processes
  69  * @library /lib/testlibrary
  70  * @modules java.management
  71  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  72  *          jdk.internal.jvmstat/sun.jvmstat.monitor.event
  73  * @build jdk.testlibrary.*
  74  * @run main/othervm MonitorVmStartTerminate
  75  */
  76 public final class MonitorVmStartTerminate {
  77 
  78     private static final int PROCESS_COUNT = 10;
  79 
  80     public static void main(String... args) throws Exception {
  81 
  82         MonitoredHost host = MonitoredHost.getMonitoredHost("localhost");
  83         host.setInterval(1); // 1 ms
  84 
  85         String id = UUID.randomUUID().toString();
  86 
  87         List<JavaProcess> javaProcesses = new ArrayList<>();
  88         for (int i = 0; i < PROCESS_COUNT; i++) {
  89             javaProcesses.add(new JavaProcess(id + "_" + i));
  90         }
  91 
  92         Listener listener = new Listener(host, javaProcesses);
  93         host.addHostListener(listener);




   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  */
  23 

  24 import java.io.IOException;
  25 import java.net.URISyntaxException;
  26 import java.nio.file.Files;
  27 import java.nio.file.Path;
  28 import java.nio.file.Paths;
  29 import java.nio.file.StandardOpenOption;
  30 import java.util.ArrayList;
  31 import java.util.List;
  32 import java.util.Set;
  33 import java.util.UUID;
  34 import java.util.concurrent.Semaphore;
  35 
  36 import jdk.test.lib.process.OutputAnalyzer;
  37 import jdk.test.lib.process.ProcessTools;
  38 import sun.jvmstat.monitor.MonitorException;
  39 import sun.jvmstat.monitor.MonitoredHost;
  40 import sun.jvmstat.monitor.MonitoredVm;
  41 import sun.jvmstat.monitor.MonitoredVmUtil;
  42 import sun.jvmstat.monitor.VmIdentifier;
  43 import sun.jvmstat.monitor.event.HostEvent;
  44 import sun.jvmstat.monitor.event.HostListener;
  45 import sun.jvmstat.monitor.event.VmStatusChangeEvent;
  46 
  47 /*
  48 
  49  Test starts ten Java processes, each with a unique id.
  50 
  51  Each process creates a file named after the id and then it waits for
  52  the test to remove the file, at which the Java process exits.
  53 
  54  The processes are monitored by the test to make sure notifications
  55  are sent when they are started/terminated.
  56 
  57  To avoid Java processes being left behind, in case of an unexpected
  58  failure, shutdown hooks are installed that remove files when the test
  59  exits. If files are not removed, i.e. due to a JVM crash, the Java
  60  processes will exit themselves after 1000 s.
  61 
  62 */
  63 
  64 /*
  65  * @test
  66  * @bug 4990825
  67  * @summary attach to external but local JVM processes
  68  * @library /test/lib
  69  * @modules java.management
  70  *          jdk.internal.jvmstat/sun.jvmstat.monitor
  71  *          jdk.internal.jvmstat/sun.jvmstat.monitor.event

  72  * @run main/othervm MonitorVmStartTerminate
  73  */
  74 public final class MonitorVmStartTerminate {
  75 
  76     private static final int PROCESS_COUNT = 10;
  77 
  78     public static void main(String... args) throws Exception {
  79 
  80         MonitoredHost host = MonitoredHost.getMonitoredHost("localhost");
  81         host.setInterval(1); // 1 ms
  82 
  83         String id = UUID.randomUUID().toString();
  84 
  85         List<JavaProcess> javaProcesses = new ArrayList<>();
  86         for (int i = 0; i < PROCESS_COUNT; i++) {
  87             javaProcesses.add(new JavaProcess(id + "_" + i));
  88         }
  89 
  90         Listener listener = new Listener(host, javaProcesses);
  91         host.addHostListener(listener);


< prev index next >