jdk/test/javax/management/mxbean/SameObjectTwoNamesTest.java
author emcmanus
Fri, 04 Jul 2008 18:55:37 +0200
changeset 831 50f701930577
child 1247 b4c26443dee5
permissions -rw-r--r--
6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator() Summary: Forward-port this bug fix from JDK 6 Reviewed-by: dfuchs, lmalvent
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
831
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     1
/*
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     2
 * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     4
 *
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     7
 * published by the Free Software Foundation.
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     8
 *
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    13
 * accompanied this code).
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    14
 *
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    18
 *
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    21
 * have any questions.
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    22
 */
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    23
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    24
/*
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    25
 * @test SameObjectTwoNamesTest.java
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    26
 * @bug 6283873
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    27
 * @summary Check that registering the same MXBean under two different
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    28
 * names produces an exception
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    29
 * @author Alexander Shusherov
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    30
 * @author Eamonn McManus
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    31
 * @run main SameObjectTwoNamesTest
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    32
 * @run main/othervm -Djmx.mxbean.multiname=true SameObjectTwoNamesTest
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    33
 */
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    34
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    35
import javax.management.InstanceAlreadyExistsException;
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    36
import javax.management.MBeanServer;
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    37
import javax.management.MBeanServerFactory;
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    38
import javax.management.ObjectName;
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    39
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    40
public class SameObjectTwoNamesTest {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    41
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    43
        boolean expectException =
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    44
                (System.getProperty("jmx.mxbean.multiname") == null);
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    45
        try {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    46
            ObjectName objectName1 = new ObjectName("test:index=1");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    47
            ObjectName objectName2 = new ObjectName("test:index=2");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    48
            MBeanServer mbs = MBeanServerFactory.createMBeanServer();
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    49
            MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    50
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    51
            mbs.registerMBean(mxBeanObject, objectName1);
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    52
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    53
            mbs.registerMBean(mxBeanObject, objectName2);
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    54
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    55
            if (expectException) {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    56
                throw new Exception("TEST FAILED: " +
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    57
                        "InstanceAlreadyExistsException was not thrown");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    58
            } else
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    59
                System.out.println("Correctly got no exception with compat property");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    60
        } catch (InstanceAlreadyExistsException e) {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    61
            if (expectException) {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    62
                System.out.println("Got expected InstanceAlreadyExistsException:");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    63
                e.printStackTrace(System.out);
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    64
            } else {
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    65
                throw new Exception(
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    66
                        "TEST FAILED: Got exception even though compat property set", e);
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    67
            }
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    68
        }
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    69
        System.out.println("TEST PASSED");
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    70
    }
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    71
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    72
    public interface MXBC_Simple01MXBean {}
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    73
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    74
    public static class MXBC_SimpleClass01 implements MXBC_Simple01MXBean {}
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    75
50f701930577 6601652: MXBeans: no IllegalArgumentException in the ex. chain for SortedSet/Map with a non-null comparator()
emcmanus
parents:
diff changeset
    76
}