Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/FailedConnectionTest.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*/222324/*25* @test FailedConnectionTest 1.1 03/11/2626* @bug 493957827* @summary test to get an IOException.28* @author Shanliang JIANG29* @run clean FailedConnectionTest30* @run build FailedConnectionTest31* @run main FailedConnectionTest32*/3334import java.net.MalformedURLException;35import java.io.IOException;36import java.util.HashMap;3738import javax.management.*;39import javax.management.remote.*;4041public class FailedConnectionTest {42private static final String[] protocols = {"rmi", "iiop", "jmxmp"};43private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();4445public static void main(String[] args) {46System.out.println(">>> test to get an IOException when calling"+47" getConnectionID on a closed connection.");4849boolean ok = true;50for (int i = 0; i < protocols.length; i++) {51try {52if (!test(protocols[i])) {53System.out.println(">>> Test failed for " + protocols[i]);54ok = false;55} else {56System.out.println(">>> Test successed for " + protocols[i]);57}58} catch (Exception e) {59System.out.println(">>> Test failed for " + protocols[i]);60e.printStackTrace(System.out);61ok = false;62}63}6465if (ok) {66System.out.println(">>> Test passed");67} else {68System.out.println(">>> TEST FAILED");69System.exit(1);70}71}7273private static boolean test(String proto)74throws Exception {75System.out.println(">>> Test for protocol " + proto);7677JMXServiceURL u = null;78JMXConnectorServer server = null;7980try {81u = new JMXServiceURL(proto, null, 0);82server = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);83} catch (MalformedURLException e) {84System.out.println("Skipping unsupported URL " + proto);85return true;86}8788server.start();8990JMXServiceURL addr = server.getAddress();9192HashMap env = new HashMap(1);93env.put("jmx.remote.x.client.connection.check.period", "0");9495JMXConnector client = JMXConnectorFactory.connect(addr, env);96server.stop();97Thread.sleep(1000);98try {99client.getConnectionId();100101System.out.println("Do not get expected IOException, failed.");102return false;103} catch (IOException ioe) {104// Good105return true;106}107}108}109110111