Path: blob/master/test/jdk/javax/management/remote/mandatory/connection/CloseUnconnectedTest.java
41159 views
/*1* Copyright (c) 2003, 2015, 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* @test CloseUnconnectedTest.java 1.1 03/07/2825* @bug 489705226* @summary Tests that opening and immediately closing a connector works27* @author Eamonn McManus28*29* @run clean CloseUnconnectedTest30* @run build CloseUnconnectedTest31* @run main CloseUnconnectedTest32*/3334/*35* Test that we can create a connection, but never call connect() on it,36* then close it again without anything surprising happening.37*/3839import java.net.MalformedURLException;4041import javax.management.*;42import javax.management.remote.*;4344public class CloseUnconnectedTest {45private static final String[] protocols = {"rmi", "iiop", "jmxmp"};4647public static void main(String[] args) {48System.out.println("Test that a connection can be opened and " +49"immediately closed without any operations");5051MBeanServer mbs = MBeanServerFactory.createMBeanServer();5253boolean ok = true;54for (int i = 0; i < protocols.length; i++) {55try {56if (!test(protocols[i], mbs)) {57System.out.println("Test failed for " + protocols[i]);58ok = false;59} else {60System.out.println("Test successed for " + protocols[i]);61}62} catch (Exception e) {63System.out.println("Test failed for " + protocols[i]);64e.printStackTrace(System.out);65ok = false;66}67}6869if (ok) {70System.out.println("Test passed");71return;72} else {73System.out.println("TEST FAILED");74System.exit(1);75}76}7778private static boolean test(String proto, MBeanServer mbs)79throws Exception {80System.out.println("Test immediate client close for protocol " +81proto);82JMXServiceURL u = new JMXServiceURL(proto, null, 0);83JMXConnectorServer s;84try {85s = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);86} catch (MalformedURLException e) {87System.out.println("Skipping unsupported URL " + u);88return true;89}90s.start();91JMXServiceURL a = s.getAddress();92JMXConnector c = JMXConnectorFactory.newJMXConnector(a, null);93c.close();94s.stop();95return true;96}97}9899100