Path: blob/master/test/jdk/sun/jvmstat/monitor/MonitoredVm/TestPollingInterval.java
41152 views
/*1* Copyright (c) 2004, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.IOException;24import java.net.URISyntaxException;25import java.util.ArrayList;26import java.util.List;2728import jdk.test.lib.Asserts;29import jdk.test.lib.Utils;30import jdk.test.lib.apps.LingeredApp;31import sun.jvmstat.monitor.MonitorException;32import sun.jvmstat.monitor.MonitoredHost;33import sun.jvmstat.monitor.MonitoredVm;34import sun.jvmstat.monitor.MonitoredVmUtil;35import sun.jvmstat.monitor.VmIdentifier;3637/**38*39* @test40* @bug 667213541* @summary setInterval() for local MonitoredHost and local MonitoredVm42*43* @library /test/lib44*45* @build jdk.test.lib.apps.*46* @run main TestPollingInterval47*/48public class TestPollingInterval {4950private static final int INTERVAL = 2000;5152public static void main(String[] args) throws IOException,53MonitorException, URISyntaxException {54LingeredApp app = null;55try {56app = LingeredApp.startApp("-XX:+UsePerfData");5758MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost");59String uriString = "//" + app.getPid() + "?mode=r"; // NOI18N60VmIdentifier vmId = new VmIdentifier(uriString);61MonitoredVm vm = localHost.getMonitoredVm(vmId);62System.out.println("Monitored vm command line: " + MonitoredVmUtil.commandLine(vm));6364vm.setInterval(INTERVAL);65localHost.setInterval(INTERVAL);6667Asserts.assertEquals(vm.getInterval(), INTERVAL, "Monitored vm interval should be equal the test value");68Asserts.assertEquals(localHost.getInterval(), INTERVAL, "Monitored host interval should be equal the test value");69} finally {70LingeredApp.stopApp(app);71}7273}7475}767778