1 /* 2 * Copyright (c) 2013, 2018, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package jdk.jfr.jmx.info; 27 28 29 import java.util.HashMap; 30 import java.util.List; 31 import java.util.Map; 32 33 import jdk.jfr.jmx.JmxHelper; 34 35 import jdk.jfr.Configuration; 36 import jdk.management.jfr.ConfigurationInfo; 37 import jdk.test.lib.Asserts; 38 39 /** 40 * @test 41 * @key jfr 42 * @summary Test for ConfigurationInfo. Compare infos from java API and jmx API. 43 * @requires vm.hasJFR 44 * @library /test/lib /test/jdk 45 * @run main/othervm jdk.jfr.jmx.info.TestConfigurationInfo 46 */ 47 public class TestConfigurationInfo { 48 public static void main(String[] args) throws Throwable { 49 List<ConfigurationInfo> configInfos = JmxHelper.getFlighteRecorderMXBean().getConfigurations(); 50 Asserts.assertFalse(configInfos.isEmpty(), "No ConfigurationInfos found"); 51 52 Map<String, Configuration> configs = new HashMap<>(); 53 for (Configuration config : Configuration.getConfigurations()) { 54 configs.put(config.getName(), config); 55 } 56 Asserts.assertFalse(configs.isEmpty(), "No Configurations found"); 57 58 for (ConfigurationInfo configInfo : configInfos) { 59 final String key = configInfo.getName(); 60 Configuration config = configs.remove(key); 61 Asserts.assertNotNull(config, "No Configuration for name " + key); 62 63 System.out.println("getDescription:" + configInfo.getDescription()); 64 System.out.println("getLabel:" + configInfo.getLabel()); 65 System.out.println("getName:" + configInfo.getName()); 66 System.out.println("getProvider:" + configInfo.getProvider()); 67 68 Asserts.assertEquals(configInfo.getContents(), config.getContents(), "Wrong contents"); 69 Asserts.assertEquals(configInfo.getDescription(), config.getDescription(), "Wrong description"); 70 Asserts.assertEquals(configInfo.getLabel(), config.getLabel(), "Wrong label"); 71 Asserts.assertEquals(configInfo.getName(), config.getName(), "Wrong name"); 72 Asserts.assertEquals(configInfo.getProvider(), config.getProvider(), "Wrong provider"); 73 74 verifySettingsEqual(config, configInfo); 75 } 76 77 // Verify that all EventTypes have been matched. 78 if (!configs.isEmpty()) { 79 for (String name : configs.keySet()) { 80 System.out.println("Found extra Configuration with name " + name); 81 } 82 Asserts.fail("Found extra Configuration"); 83 } 84 } 85 86 private static void verifySettingsEqual(Configuration config, ConfigurationInfo configInfo) { 87 Map<String, String> javaSettings = config.getSettings(); 88 Map<String, String> jmxSettings = configInfo.getSettings(); 89 90 Asserts.assertFalse(javaSettings.isEmpty(), "No Settings found in java apa"); 91 Asserts.assertFalse(jmxSettings.isEmpty(), "No Settings found in jmx api"); 92 93 for (String name : jmxSettings.keySet().toArray(new String[0])) { 94 System.out.printf("%s: jmx=%s, java=%s%n", name, jmxSettings.get(name), javaSettings.get(name)); 95 Asserts.assertNotNull(javaSettings.get(name), "No java setting for " + name); 96 Asserts.assertEquals(jmxSettings.get(name), javaSettings.get(name), "Wrong value for setting"); 97 javaSettings.remove(name); 98 } 99 100 // Verify that all Settings have been matched. 101 if (!javaSettings.isEmpty()) { 102 for (String name : javaSettings.keySet()) { 103 System.out.println("Found extra Settings name " + name); 104 } 105 Asserts.fail("Found extra Setting in java api"); 106 } 107 } 108 109 }