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