Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/GetConnectionTest.java
38867 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 495141426* @summary Try to get an IOException.27* @author Shanliang JIANG28* @run clean GetConnectionTest29* @run build GetConnectionTest30* @run main GetConnectionTest31*/3233import java.io.IOException;34import java.net.MalformedURLException;3536import javax.management.MBeanServer;37import javax.management.MBeanServerConnection;38import javax.management.MBeanServerFactory;39import javax.management.Notification;40import javax.management.NotificationListener;41import javax.management.ObjectName;4243import javax.management.remote.JMXConnector;44import javax.management.remote.JMXConnectorFactory;4546import javax.management.remote.JMXServiceURL;474849public class GetConnectionTest {50public static void main(String[] args) {51System.out.println("Verify whether getting an IOException when "+52"calling getMBeanServerConnection to a unconnected connector.");5354boolean ok = true;55String[] protocols = {"rmi", "iiop", "jmxmp"};5657for (int i = 0; i < protocols.length; i++) {58final String proto = protocols[i];59System.out.println("Testing for protocol " + proto);60try {61ok &= test(proto);62} catch (Exception e) {63System.err.println("Unexpected exception: " + e);64e.printStackTrace();65ok = false;66}67}6869if (ok)70System.out.println("All Tests passed");71else {72System.out.println("TEST FAILED");73System.exit(1);74}75}7677private static boolean test(String proto) throws Exception {78JMXConnector client;79try {80JMXServiceURL url = new JMXServiceURL(proto, null, 0);81client = JMXConnectorFactory.newJMXConnector(url, null);82} catch (MalformedURLException e) {83System.out.println("Protocol " + proto +84" not supported, ignoring");85return true;86}8788// IOException is expected89try {90MBeanServerConnection connection =91client.getMBeanServerConnection();9293System.out.println("FAILED: Expected IOException is not thrown.");94return false;95} catch (IOException e) {96System.out.println("PASSED");97return true;98}99}100}101102103