Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/Naming/DefaultRegistryPort.java
38813 views
/*1* Copyright (c) 1999, 2012, 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 425187826* @summary change in default URL port causes regression in java.rmi.Naming27* @author Dana Burns28* @library ../testlibrary29* @build TestLibrary30* @run main DefaultRegistryPort31*/3233/*34* Ensure that the default registry port for java.rmi.Naming URLs35* is 1099. Test creates a registry on port 1099 and then does a36* lookup with a Naming URL that uses the default port. Test fails37* if the lookup yields a NotBoundException. If the registry could38* not be created, a fallback strategy of using an existing one is39* tried.40*/4142import java.rmi.Naming;43import java.rmi.Remote;44import java.rmi.registry.LocateRegistry;45import java.rmi.registry.Registry;4647public class DefaultRegistryPort {4849public static void main(String args[]) {5051Registry registry = null;52try {5354System.err.println(55"Starting registry on default port REGISTRY_PORT=" +56Registry.REGISTRY_PORT);5758registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);5960System.err.println("Created registry=" + registry);6162} catch(java.rmi.RemoteException e) {6364try {6566System.err.println(67"Failed to create a registry, try using existing one");68registry = LocateRegistry.getRegistry();6970System.err.println("Found registry=" + registry);7172} catch (Exception ge) {7374TestLibrary.bomb(75"Test Failed: cound not find or create a registry");76}7778}7980try {8182if (registry != null) {8384registry.rebind("myself", registry);8586Remote myself = Naming.lookup("rmi://localhost/myself");8788System.err.println("Test PASSED");8990} else {9192TestLibrary.bomb(93"Test Failed: cound not find or create a registry");9495}9697} catch(java.rmi.NotBoundException e) {9899TestLibrary.bomb(100"Test Failed: could not find myself");101102} catch(Exception e) {103104e.printStackTrace();105TestLibrary.bomb(106"Test failed: unexpected exception");107108}109110}111112}113114115