Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/remote/mandatory/connection/MultiOpenCloseTest.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/08/2825* @bug 123456726* @summary Open, connect then close multi-connectors.27* @author Shanliang JIANG28* @run clean MultiOpenCloseTest29* @run build MultiOpenCloseTest30* @run main MultiOpenCloseTest31*/3233/*34* Test that we can create a connection, call connect() on it,35* then close it without anything surprising happening.36*/3738import java.net.MalformedURLException;39import java.io.IOException;4041import javax.management.*;42import javax.management.remote.*;4344public class MultiOpenCloseTest {45private static final String[] protocols = {"rmi", "iiop", "jmxmp"};46private static final MBeanServer mbs = MBeanServerFactory.createMBeanServer();4748public static void main(String[] args) {49System.out.println("Open, connect then close multi-connectors.");5051boolean ok = true;52for (int i = 0; i < protocols.length; i++) {53try {54if (!test(protocols[i])) {55System.out.println("Test failed for " + protocols[i]);56ok = false;57} else {58System.out.println("Test successed for " + protocols[i]);59}60} catch (Exception e) {61System.out.println("Test failed for " + protocols[i]);62e.printStackTrace(System.out);63ok = false;64}65}6667if (ok) {68System.out.println("Test passed");69return;70} else {71System.out.println("TEST FAILED");72System.exit(1);73}74}7576private static boolean test(String proto)77throws Exception {78System.out.println("Test for protocol " + proto);79JMXServiceURL u = new JMXServiceURL(proto, null, 0);80JMXConnectorServer s;81try {82s = JMXConnectorServerFactory.newJMXConnectorServer(u, null, mbs);83} catch (MalformedURLException e) {84System.out.println("Skipping unsupported URL " + u);85return true;86}87s.start();88JMXServiceURL a = s.getAddress();8990final int MAX_ITERS = 10;91System.out.println("Looping for " + MAX_ITERS + "iterations...");9293for (int i=0; i<MAX_ITERS; i++) {94JMXConnector c = JMXConnectorFactory.newJMXConnector(a, null);95c.connect(null);96c.close();97}9899JMXConnector[] cs = new JMXConnector[MAX_ITERS];100for (int i=0; i<MAX_ITERS; i++) {101cs[i] = JMXConnectorFactory.newJMXConnector(a, null);102cs[i].connect(null);103}104105for (int i=0; i<MAX_ITERS; i++) {106cs[i].close();107}108109try {110Thread.sleep(100);111} catch (Exception ee) {112// should not113}114115// check state116for (int i=0; i<MAX_ITERS; i++) {117try {118cs[i].getMBeanServerConnection(null);119// no exception120System.out.println("Did not get an IOException as expected, failed to close a client.");121return false;122} catch (IOException ioe) {123// as expected124}125}126127s.stop();128return true;129}130}131132133