Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/MBeanServer/PostRegisterDeadlockTest2.java
38839 views
/*1* Copyright (c) 2006, 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 641704426* @summary Test that a failing MBean registration does not lead to a deadlock27* @author Eamonn McManus28* @run main PostRegisterDeadlockTest229*/3031import javax.management.*;3233public class PostRegisterDeadlockTest2 {34private static String failed;3536public static interface EmptyMBean {}3738public static class Empty implements EmptyMBean, MBeanRegistration {39public ObjectName preRegister(MBeanServer mbs, ObjectName on) {40this.mbs = mbs;41this.on = on;42return on;43}44public void postRegister(Boolean done) {45Thread t = new Thread() {46public void run() {47if (!mbs.isRegistered(on))48failed = "Not registered!";49}50};51t.start();52try {53t.join(5000L);54} catch (InterruptedException e) {55failed = "Interrupted: " + e;56}57if (t.isAlive())58failed = "Deadlock detected";59}60public void preDeregister() {}61public void postDeregister() {}6263private MBeanServer mbs;64private ObjectName on;65}6667public static void main(String[] args) throws Exception {68MBeanServer mbs = MBeanServerFactory.newMBeanServer();69ObjectName on = new ObjectName("a:b=c");70mbs.registerMBean(new Empty(), on);71try {72mbs.registerMBean(new Empty(), on);73throw new Exception("FAILED: did not get expected exception");74} catch (InstanceAlreadyExistsException e) {75System.out.println("OK: got expected exception");76}77if (failed != null)78throw new Exception("FAILED: " + failed);79System.out.println("TEST PASSED");80}81}828384