Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanServerFactory/ReleaseMBeanServerTest.java
38839 views
/*1* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 495522226* @summary Test that the releaseMBeanServer(MBeanServer mbeanServer) method27* throws IllegalArgumentException as expected28* @author Luis-Miguel Alventosa29* @run clean ReleaseMBeanServerTest30* @run build ReleaseMBeanServerTest31* @run main ReleaseMBeanServerTest32*/3334/* Check that the releaseMBeanServer(MBeanServer mbeanServer) method throws35IllegalArgumentException if mbeanServer was not generated by one of the36createMBeanServer methods, or if releaseMBeanServer was already called37on it. */3839import javax.management.MBeanServer;40import javax.management.MBeanServerFactory;4142public class ReleaseMBeanServerTest {4344private static final String DOMAIN = "TestDomain";4546public static void main(String[] args) throws Exception {4748System.out.println("--------------------------------------" +49"-----------------------------------------");50System.out.println("- Testing IllegalArgumentException in " +51"MBeanServerFactory.releaseMBeanServer() -");52System.out.println("--------------------------------------" +53"-----------------------------------------");5455System.out.println("TEST_0: Call releaseMBeanServer() with " +56"a null MBeanServer reference.");57try {58MBeanServerFactory.releaseMBeanServer(null);59System.err.println("Didn't get expected IllegalArgumentException!");60System.exit(1);61} catch (IllegalArgumentException e) {62System.out.println("Got expected IllegalArgumentException!");63}6465System.out.println("TEST_1: Call releaseMBeanServer() with an " +66"MBeanServer reference corresponding to an " +67"MBeanServer created using newMBeanServer().");68MBeanServer mbs1 = MBeanServerFactory.newMBeanServer();69try {70MBeanServerFactory.releaseMBeanServer(mbs1);71System.err.println("Didn't get expected IllegalArgumentException!");72System.exit(1);73} catch (IllegalArgumentException e) {74System.out.println("Got expected IllegalArgumentException!");75}7677System.out.println("TEST_2: Call releaseMBeanServer() with an " +78"MBeanServer reference corresponding to an " +79"MBeanServer created using newMBeanServer(String).");80MBeanServer mbs2 = MBeanServerFactory.newMBeanServer(DOMAIN);81try {82MBeanServerFactory.releaseMBeanServer(mbs2);83System.err.println("Didn't get expected IllegalArgumentException!");84System.exit(1);85} catch (IllegalArgumentException e) {86System.out.println("Got expected IllegalArgumentException!");87}8889System.out.println("TEST_3: Call releaseMBeanServer() twice with an " +90"MBeanServer reference corresponding to an MBean" +91"Server created using createMBeanServer().");92MBeanServer mbs3 = MBeanServerFactory.createMBeanServer();93MBeanServerFactory.releaseMBeanServer(mbs3);94try {95MBeanServerFactory.releaseMBeanServer(mbs3);96System.err.println("Didn't get expected IllegalArgumentException!");97System.exit(1);98} catch (IllegalArgumentException e) {99System.out.println("Got expected IllegalArgumentException!");100}101102System.out.println("TEST_4: Call releaseMBeanServer() twice with an " +103"MBeanServer reference corresponding to an MBean" +104"Server created using createMBeanServer(String).");105MBeanServer mbs4 = MBeanServerFactory.createMBeanServer(DOMAIN);106MBeanServerFactory.releaseMBeanServer(mbs4);107try {108MBeanServerFactory.releaseMBeanServer(mbs4);109System.err.println("Didn't get expected IllegalArgumentException!");110System.exit(1);111} catch (IllegalArgumentException e) {112System.out.println("Got expected IllegalArgumentException!");113}114}115}116117118