404N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
404N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
404N/A *
404N/A * This code is free software; you can redistribute it and/or modify it
404N/A * under the terms of the GNU General Public License version 2 only, as
404N/A * published by the Free Software Foundation.
404N/A *
404N/A * This code is distributed in the hope that it will be useful, but WITHOUT
404N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
404N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
404N/A * version 2 for more details (a copy is included in the LICENSE file that
404N/A * accompanied this code).
404N/A *
404N/A * You should have received a copy of the GNU General Public License version
404N/A * 2 along with this work; if not, write to the Free Software Foundation,
404N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
404N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
404N/A */
404N/A
404N/A/*
404N/A * @test SameObjectTwoNamesTest.java
404N/A * @bug 6283873
404N/A * @summary Check that registering the same MXBean under two different
404N/A * names produces an exception
404N/A * @author Alexander Shusherov
404N/A * @author Eamonn McManus
404N/A * @run main SameObjectTwoNamesTest
404N/A * @run main/othervm -Djmx.mxbean.multiname=true SameObjectTwoNamesTest
404N/A */
404N/A
404N/Aimport javax.management.InstanceAlreadyExistsException;
404N/Aimport javax.management.MBeanServer;
404N/Aimport javax.management.MBeanServerFactory;
404N/Aimport javax.management.ObjectName;
404N/A
404N/Apublic class SameObjectTwoNamesTest {
404N/A
404N/A public static void main(String[] args) throws Exception {
404N/A boolean expectException =
404N/A (System.getProperty("jmx.mxbean.multiname") == null);
404N/A try {
404N/A ObjectName objectName1 = new ObjectName("test:index=1");
404N/A ObjectName objectName2 = new ObjectName("test:index=2");
404N/A MBeanServer mbs = MBeanServerFactory.createMBeanServer();
404N/A MXBC_SimpleClass01 mxBeanObject = new MXBC_SimpleClass01();
404N/A
404N/A mbs.registerMBean(mxBeanObject, objectName1);
404N/A
404N/A mbs.registerMBean(mxBeanObject, objectName2);
404N/A
404N/A if (expectException) {
404N/A throw new Exception("TEST FAILED: " +
404N/A "InstanceAlreadyExistsException was not thrown");
404N/A } else
404N/A System.out.println("Correctly got no exception with compat property");
404N/A } catch (InstanceAlreadyExistsException e) {
404N/A if (expectException) {
404N/A System.out.println("Got expected InstanceAlreadyExistsException:");
404N/A e.printStackTrace(System.out);
404N/A } else {
404N/A throw new Exception(
404N/A "TEST FAILED: Got exception even though compat property set", e);
404N/A }
404N/A }
404N/A System.out.println("TEST PASSED");
404N/A }
404N/A
404N/A public interface MXBC_Simple01MXBean {}
404N/A
404N/A public static class MXBC_SimpleClass01 implements MXBC_Simple01MXBean {}
404N/A
404N/A}