Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/lang/management/MXBean/MXBeanBehavior.java
          +++ new/test/java/lang/management/MXBean/MXBeanBehavior.java
   1    1  /*
   2      - * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
        2 + * Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
   3    3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4    4   *
   5    5   * This code is free software; you can redistribute it and/or modify it
   6    6   * under the terms of the GNU General Public License version 2 only, as
   7    7   * published by the Free Software Foundation.
   8    8   *
   9    9   * This code is distributed in the hope that it will be useful, but WITHOUT
  10   10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11   11   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12   12   * version 2 for more details (a copy is included in the LICENSE file that
↓ open down ↓ 16 lines elided ↑ open up ↑
  29   29   * @author  Eamonn McManus
  30   30   * @run     main/othervm MXBeanBehavior
  31   31   */
  32   32  
  33   33  import java.lang.management.*;
  34   34  import java.lang.reflect.*;
  35   35  import java.util.*;
  36   36  import javax.management.*;
  37   37  
  38   38  public class MXBeanBehavior {
       39 +    // Exclude list: list of platform MBeans that are not MXBeans
       40 +    public static final HashSet<String> excludeList = new HashSet<>(
       41 +            Arrays.asList("com.sun.management:type=DiagnosticCommand"));
       42 +
  39   43      public static void main(String[] args) throws Exception {
  40   44          MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
  41   45  
  42   46          /* Test that all the MBeans in the java.* and com.sun.management*
  43   47             domains are MXBeans with the appropriate behavior.  */
  44   48          Set<ObjectName> names = mbs.queryNames(new ObjectName("java.*:*"),
  45   49                                                 null);
  46   50          names.addAll(mbs.queryNames(new ObjectName("com.sun.management*:*"),
  47   51                                      null));
  48   52          for (ObjectName name : names)
↓ open down ↓ 36 lines elided ↑ open up ↑
  85   89         here.  Each attribute should have Descriptor with the fields
  86   90         openType and originalType that have appropriate values.  We
  87   91         don't currently check operations though the same considerations
  88   92         would apply there.  (If the MBeanInfo and MBeanAttributeInfo
  89   93         tests pass we can reasonably suppose that this MXBean will
  90   94         behave the same as all other MXBeans, so MBeanOperationInfo,
  91   95         MBeanNotificationInfo, and MBeanConstructorInfo will be covered
  92   96         by generic MXBean tests.
  93   97       */
  94   98      private static void test(MBeanServer mbs, ObjectName name) throws Exception {
       99 +        if(excludeList.contains(name.getCanonicalName())) {
      100 +            // Skipping not MXBean objects.
      101 +            return;
      102 +        }
  95  103          System.out.println("Testing: " + name);
  96  104  
  97  105          MBeanInfo mbi = mbs.getMBeanInfo(name);
  98  106          Descriptor mbid = mbi.getDescriptor();
  99  107          Object[] values = mbid.getFieldValues("immutableInfo",
 100  108                                                "interfaceClassName",
 101  109                                                "mxbean");
 102      -        checkEqual(values[0], "true", name + " immutableInfo field");
 103      -        checkEqual(values[2], "true", name + " mxbean field");
      110 +        checkEqual(values[0], "true", name + " immutableInfo field");
      111 +        checkEqual(values[2], "true", name + " mxbean field");
 104  112          String interfaceClassName = (String) values[1];
 105  113          if (!mbs.isInstanceOf(name, interfaceClassName)) {
 106  114              throw new RuntimeException(name + " not instance of " +
 107  115                                         interfaceClassName);
 108  116          }
 109  117          Class interfaceClass = Class.forName(interfaceClassName);
 110  118          for (MBeanAttributeInfo mbai : mbi.getAttributes()) {
 111  119              Descriptor mbaid = mbai.getDescriptor();
 112  120              Object[] avalues = mbaid.getFieldValues("openType",
 113  121                                                      "originalType");
↓ open down ↓ 59 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX