Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/Naming/legalRegistryNames/LegalRegistryNames.java
38828 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 425480826* @summary Naming assumes '/' is present in relative URL; change in URL causes regression27* @author Dana Burns28* @library ../../testlibrary29* @build TestLibrary Legal LegalRegistryNames_Stub30* @run main LegalRegistryNames31*/3233import java.net.InetAddress;34import java.net.UnknownHostException;35import java.rmi.Naming;36import java.rmi.RemoteException;37import java.rmi.Remote;38import java.rmi.registry.LocateRegistry;39import java.rmi.registry.Registry;40import java.rmi.server.UnicastRemoteObject;41import java.util.Enumeration;42import java.util.Vector;4344/**45* Ensure that all legal forms of Naming URLs operate with the46* java.rmi.Naming interface. This test requires using the default RMI Registry47* port as it tests all of the RMI naming URL's, including the ones which do not48* take a port (and therefore uses the default port).49*/50public class LegalRegistryNames extends UnicastRemoteObject51implements Legal52{5354public LegalRegistryNames() throws java.rmi.RemoteException {}5556public static void main(String args[]) throws RuntimeException {5758System.err.println("\nRegression test for bug/rfe 4254808\n");5960Registry registry = null;61LegalRegistryNames legal = null;6263boolean oneFormFailed = false;64String[] names = null;65Vector legalForms = getLegalForms();66Remote shouldFind = null;6768// create a registry and the test object69try {70legal = new LegalRegistryNames();7172System.err.println("Starting registry on default port");73registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT);74} catch (Exception e) {75TestLibrary.bomb("registry already running on test port");76}7778// enumerate through all legal URLs to verify that a remote79// object can be bound and unbound80String s = null;81Enumeration en = legalForms.elements();82while (en.hasMoreElements()) {83s = (String) en.nextElement();8485System.err.println("\ntesting form: " + s);8687try {88Naming.rebind(s, legal);89names = registry.list();9091// ensure that the name in the registry is what is expected92if ((names.length > 0) &&93(names[0].compareTo("MyName") != 0))94{95oneFormFailed = true;96System.err.println("\tRegistry entry for form: " +97s + " is incorrect: " + names[0]);98}99100// ensure that the object can be unbound under the URL string101shouldFind = Naming.lookup(s);102Naming.unbind(s);103System.err.println("\tform " + s + " OK");104105} catch (Exception e) {106107e.printStackTrace();108oneFormFailed = true;109System.err.println("\tunexpected lookup or unbind " +110"exception for form: " + s + e.getMessage() );111}112}113if (oneFormFailed) {114TestLibrary.bomb("Test failed");115}116117// get the test to exit quickly118TestLibrary.unexport(legal);119}120121/**122* return a vector of valid legal RMI naming URLs.123*/124private static Vector getLegalForms() {125String localHostAddress = null;126String localHostName = null;127128// get the local host name and address129try {130localHostName = InetAddress.getLocalHost().getHostName();131localHostAddress = InetAddress.getLocalHost().getHostAddress();132} catch(UnknownHostException e) {133TestLibrary.bomb("Test failed: unexpected exception", e);134}135136Vector legalForms = new Vector();137legalForms.add("///MyName");138legalForms.add("//:" + Registry.REGISTRY_PORT + "/MyName");139legalForms.add("//" + localHostAddress + "/MyName");140legalForms.add("//" + localHostAddress + ":" +141Registry.REGISTRY_PORT + "/MyName");142legalForms.add("//localhost/MyName");143legalForms.add("//localhost:" + Registry.REGISTRY_PORT + "/MyName");144legalForms.add("//" + localHostName + "/MyName");145legalForms.add("//" + localHostName + ":" + Registry.REGISTRY_PORT +146"/MyName");147legalForms.add("MyName");148legalForms.add("/MyName");149legalForms.add("rmi:///MyName");150legalForms.add("rmi://:" + Registry.REGISTRY_PORT + "/MyName");151legalForms.add("rmi://" + localHostAddress + "/MyName");152legalForms.add("rmi://" + localHostAddress + ":" +153Registry.REGISTRY_PORT + "/MyName");154legalForms.add("rmi://localhost/MyName");155legalForms.add("rmi://localhost:" + Registry.REGISTRY_PORT + "/MyName");156legalForms.add("rmi://" + localHostName + "/MyName");157legalForms.add("rmi://" + localHostName + ":" +158Registry.REGISTRY_PORT + "/MyName");159return legalForms;160}161}162163164