1 /* 2 * Copyright (c) 2004, 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 */ 23 24 import java.io.IOException; 25 import java.net.URISyntaxException; 26 import java.util.ArrayList; 27 import java.util.List; 28 29 import jdk.testlibrary.Asserts; 30 import jdk.testlibrary.Utils; 31 import jdk.test.lib.apps.LingeredApp; 32 import sun.jvmstat.monitor.MonitorException; 33 import sun.jvmstat.monitor.MonitoredHost; 34 import sun.jvmstat.monitor.MonitoredVm; 35 import sun.jvmstat.monitor.MonitoredVmUtil; 36 import sun.jvmstat.monitor.VmIdentifier; 37 38 /** 39 * 40 * @test 41 * @bug 6672135 42 * @summary setInterval() for local MonitoredHost and local MonitoredVm 43 * @modules jdk.internal.jvmstat/sun.jvmstat.monitor 44 * @library /lib/testlibrary 45 * @library /test/lib 46 * @build jdk.testlibrary.* 47 * @build jdk.test.lib.apps.* 48 * @run main TestPollingInterval 49 */ 50 public class TestPollingInterval { 51 52 private static final int INTERVAL = 2000; 53 54 public static void main(String[] args) throws IOException, 55 MonitorException, URISyntaxException { 56 LingeredApp app = null; 57 try { 58 List<String> vmArgs = new ArrayList<String>(); 59 vmArgs.add("-XX:+UsePerfData"); 60 vmArgs.addAll(Utils.getVmOptions()); 61 app = LingeredApp.startApp(vmArgs); 62 63 MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost"); 64 String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N 65 VmIdentifier vmId = new VmIdentifier(uriString); 66 MonitoredVm vm = localHost.getMonitoredVm(vmId); 67 System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm)); 68 69 vm.setInterval(INTERVAL); 70 localHost.setInterval(INTERVAL); 71 72 Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value"); 73 Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value"); 74 } finally { 75 LingeredApp.stopApp(app); 76 } 77 78 } 79 80 }