Path: blob/master/test/jdk/java/rmi/Naming/DefaultRegistryPort.java
41149 views
/*1* Copyright (c) 1999, 2018, 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* @modules java.rmi/sun.rmi.registry30* java.rmi/sun.rmi.server31* java.rmi/sun.rmi.transport32* java.rmi/sun.rmi.transport.tcp33* @build TestLibrary34* @run main/othervm DefaultRegistryPort35* @key intermittent36*/3738/*39* Ensure that the default registry port for java.rmi.Naming URLs40* is 1099. Test creates a registry on port 1099 and then does a41* lookup with a Naming URL that uses the default port.42*/4344import java.rmi.Naming;45import java.rmi.Remote;46import java.rmi.registry.LocateRegistry;47import java.rmi.registry.Registry;4849public class DefaultRegistryPort {5051public static void main(String args[]) throws Exception {5253Registry registry = null;54System.err.println("Starting registry on default port REGISTRY_PORT="55+ Registry.REGISTRY_PORT);56final int NUM = 10;57for (int loop = 0; loop < NUM; loop++) {58System.err.println("in loop: " + loop);59try {60registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);61System.err.println("Created registry=" + registry);62break;63} catch(java.rmi.RemoteException e) {64String err = e.getMessage();65if (err.contains("Address already in use")66|| err.contains("Port already in use")) {67try {68Thread.sleep((long)(TestLibrary.getTimeoutFactor() * 100));69} catch (InterruptedException ignore) { }70continue;71}72TestLibrary.bomb(e);73}74}75if (registry == null) {76throw new RuntimeException("can not create registry at "77+ Registry.REGISTRY_PORT + " after trying " + NUM + "times");78}7980registry.rebind("myself", registry);81Remote myself = Naming.lookup("rmi://localhost/myself");82System.err.println("Test PASSED");83}84}858687