0N/A/*
3909N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4762344
0N/A * @summary 2nd nameservice provider is non functional
3406N/A * @compile -XDignore.symbol.file=true SimpleNameService.java
3406N/A * Simple1NameServiceDescriptor.java
3406N/A * Simple2NameServiceDescriptor.java
3406N/A * @run main/othervm -Dsun.net.spi.nameservice.provider.1=simple1,sun -Dsun.net.spi.nameservice.provider.2=simple2,sun Providers
0N/A */
0N/A
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/A
0N/A
3406N/Apublic class Providers {
0N/A private static String[][] hostnames = new String[][] {
0N/A // both providers know this host, but with different address
0N/A new String[] {"blade", "10.0.0.1"},
0N/A // provider1 knwos this host
0N/A new String[] {"blade.domain1", "10.0.0.2"},
0N/A // provider2 knows this host
0N/A new String[] {"blade.domain2", "20.0.0.2"}
0N/A };
0N/A private static String[][] hostaddrs = new String[][] {
0N/A new String[] {"10.0.0.1", "blade"},
0N/A new String[] {"10.0.0.2", "blade.domain1"},
0N/A new String[] {"20.0.0.2", "blade.domain2"}
0N/A };
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A for (int i = 0; i < hostnames.length; i++) {
0N/A doLookup(hostnames[i][0], hostnames[i][1]);
0N/A }
0N/A for (int i = 0; i < hostaddrs.length; i++) {
0N/A doReverseLookup(hostaddrs[i][0], hostaddrs[i][1]);
0N/A }
0N/A }
0N/A
0N/A private static void doLookup(String host, String addr) throws Exception {
0N/A String res = InetAddress.getByName(host).getHostAddress();
0N/A if (!res.equals(addr)) {
0N/A throw new RuntimeException("Test failed: wrong address for host " + host);
0N/A }
0N/A }
0N/A
0N/A private static void doReverseLookup(String addr, String host) throws Exception {
0N/A StringTokenizer tokenizer = new StringTokenizer(addr, ".");
0N/A byte addrs[] = new byte[4];
0N/A for (int i = 0; i < 4; i++) {
0N/A addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken());
0N/A }
0N/A String res = InetAddress.getByAddress(addrs).getHostName();
0N/A if (!res.equals(host)) {
0N/A throw new RuntimeException("Test failed: wrong host name for address " + addr);
0N/A }
0N/A }
0N/A}