1 /* 2 * Copyright (c) 2004, 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.net.URISyntaxException; 25 import java.util.Set; 26 import sun.jvmstat.monitor.MonitorException; 27 import sun.jvmstat.monitor.MonitoredHost; 28 import sun.jvmstat.monitor.MonitoredVm; 29 import sun.jvmstat.monitor.VmIdentifier; 30 31 /** 32 * 33 * @test 34 * @bug 6672135 35 * @summary setInterval() for local MonitoredHost and local MonitoredVm 36 * @author Tomas Hurka 37 * @run main/othervm -XX:+UsePerfData CR6672135 38 */ 39 public class CR6672135 { 40 41 private static final int INTERVAL = 2000; 42 43 public static void main(String[] args) { 44 int vmInterval; 45 int hostInterval; 46 47 try { 48 MonitoredHost localHost = MonitoredHost.getMonitoredHost("localhost"); 49 Set vms = localHost.activeVms(); 50 Integer vmInt = (Integer) vms.iterator().next(); 51 String uriString = "//" + vmInt + "?mode=r"; // NOI18N 52 VmIdentifier vmId = new VmIdentifier(uriString); 53 MonitoredVm vm = localHost.getMonitoredVm(vmId); 54 55 vm.setInterval(INTERVAL); 56 localHost.setInterval(INTERVAL); 57 vmInterval = vm.getInterval(); 58 hostInterval = localHost.getInterval(); 59 } catch (Exception ex) { 60 throw new Error ("Test failed",ex); 61 } 62 System.out.println("VM "+vmInterval); 63 if (vmInterval != INTERVAL) { 64 throw new Error("Test failed"); 65 } 66 System.out.println("Host "+hostInterval); 67 if (hostInterval != INTERVAL) { 68 throw new Error("Test failed"); 69 } 70 } 71 } 72