test/jdk/com/sun/management/CheckSomeMXBeanImplPackage.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 30355 jdk/test/com/sun/management/CheckSomeMXBeanImplPackage.java@e37c7eba132f
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30355
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     1
/*
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     4
 *
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     8
 *
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    13
 * accompanied this code).
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    14
 *
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    18
 *
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    21
 * questions.
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    22
 */
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    23
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    24
import java.lang.management.ManagementFactory;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    25
import java.lang.management.PlatformManagedObject;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    26
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    27
/*
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    28
 * @test
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    29
 * @bug     8042901
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    30
 * @summary If jdk.management is present, GarbageCollectorMXBean and ThreadMXBean
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    31
 *          must be from com.sun.management.internal
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    32
 * @author  Shanliang Jiang
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    33
 */
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    34
public class CheckSomeMXBeanImplPackage {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    35
    private static String implPackageName = "com.sun.management.internal";
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    36
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    37
    public static void main(String[] args) throws Exception {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    38
        boolean present = false;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    39
        try {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    40
            Class.forName("com.sun.management.GarbageCollectorMXBean");
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    41
            present = true;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    42
        } catch (ClassNotFoundException cnfe) {}
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    43
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    44
        if (present) {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    45
            Class <? extends PlatformManagedObject> klazz =
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    46
                    java.lang.management.GarbageCollectorMXBean.class;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    47
            for (Object obj :
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    48
                    ManagementFactory.getPlatformMXBeans(klazz)) {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    49
                check(klazz.getName(), obj);
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    50
            }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    51
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    52
            klazz = com.sun.management.GarbageCollectorMXBean.class;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    53
            for (Object obj :
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    54
                    ManagementFactory.getPlatformMXBeans(klazz)) {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    55
                check(klazz.getName(), obj);
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    56
            }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    57
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    58
            klazz = java.lang.management.ThreadMXBean.class;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    59
            check(klazz.getName(),
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    60
                    ManagementFactory.getPlatformMXBean(klazz));
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    61
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    62
            klazz = com.sun.management.ThreadMXBean.class;
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    63
            check(klazz.getName(),
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    64
                    ManagementFactory.getPlatformMXBean(klazz));
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    65
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    66
            System.out.println("--- PASSED!");
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    67
        } else {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    68
            System.out.println("--- Skip the test, jdk.management module is not present!");
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    69
        }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    70
    }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    71
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    72
    private static void check(String mbeanName, Object impl) {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    73
        if (!impl.getClass().getName().startsWith(implPackageName)) {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    74
            throw new RuntimeException(mbeanName+" implementation package "
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    75
                    + "should be: " + implPackageName
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    76
                    + ", but got: " + impl.getClass());
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    77
        } else {
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    78
            System.out.println("--- Good, "+mbeanName+" got right implementation: " + impl);
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    79
        }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    80
    }
e37c7eba132f 8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
diff changeset
    81
}