Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/net/InetAddress/nameservice/chaining/Providers.java
38862 views
/*1* Copyright (c) 2007, 2011, 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 476234426* @summary 2nd nameservice provider is non functional27* @compile -XDignore.symbol.file=true SimpleNameService.java28* Simple1NameServiceDescriptor.java29* Simple2NameServiceDescriptor.java30* @run main/othervm -Dsun.net.spi.nameservice.provider.1=simple1,sun -Dsun.net.spi.nameservice.provider.2=simple2,sun Providers31*/3233import java.net.*;34import java.util.*;353637public class Providers {38private static String[][] hostnames = new String[][] {39// both providers know this host, but with different address40new String[] {"blade", "10.0.0.1"},41// provider1 knwos this host42new String[] {"blade.domain1", "10.0.0.2"},43// provider2 knows this host44new String[] {"blade.domain2", "20.0.0.2"}45};46private static String[][] hostaddrs = new String[][] {47new String[] {"10.0.0.1", "blade"},48new String[] {"10.0.0.2", "blade.domain1"},49new String[] {"20.0.0.2", "blade.domain2"}50};5152public static void main(String[] args) throws Exception {53for (int i = 0; i < hostnames.length; i++) {54doLookup(hostnames[i][0], hostnames[i][1]);55}56for (int i = 0; i < hostaddrs.length; i++) {57doReverseLookup(hostaddrs[i][0], hostaddrs[i][1]);58}59}6061private static void doLookup(String host, String addr) throws Exception {62String res = InetAddress.getByName(host).getHostAddress();63if (!res.equals(addr)) {64throw new RuntimeException("Test failed: wrong address for host " + host);65}66}6768private static void doReverseLookup(String addr, String host) throws Exception {69StringTokenizer tokenizer = new StringTokenizer(addr, ".");70byte addrs[] = new byte[4];71for (int i = 0; i < 4; i++) {72addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken());73}74String res = InetAddress.getByAddress(addrs).getHostName();75if (!res.equals(host)) {76throw new RuntimeException("Test failed: wrong host name for address " + addr);77}78}79}808182