8224014: Don't run test/jdk/java/net/NetworkInterface/IPv4Only.java in IPv6 only environment

Reviewed-by: chegar, dfuchs
This commit is contained in:
Arthur Eubanks 2019-05-15 16:21:51 -07:00 committed by Arthur Eubanks
parent 21d398288d
commit 905330d4ea

View File

@ -23,6 +23,7 @@
/* @test
* @bug 6964714
* @library /test/lib
* @run main/othervm -Djava.net.preferIPv4Stack=true IPv4Only
* @summary Test the networkinterface listing with java.net.preferIPv4Stack=true.
*/
@ -30,19 +31,36 @@
import java.net.*;
import java.util.*;
import jdk.test.lib.net.IPSupport;
public class IPv4Only {
public static void main(String[] args) throws Exception {
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface nif = nifs.nextElement();
Enumeration<InetAddress> addrs = nif.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress hostAddr = addrs.nextElement();
if ( hostAddr instanceof Inet6Address ){
throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
}
if (IPSupport.hasIPv4()) {
System.out.println("Testing IPv4");
Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
while (nifs.hasMoreElements()) {
NetworkInterface nif = nifs.nextElement();
Enumeration<InetAddress> addrs = nif.getInetAddresses();
while (addrs.hasMoreElements()) {
InetAddress hostAddr = addrs.nextElement();
if ( hostAddr instanceof Inet6Address ){
throw new RuntimeException( "NetworkInterfaceV6List failed - found v6 address " + hostAddr.getHostAddress() );
}
}
}
} else {
try {
NetworkInterface.getNetworkInterfaces();
throw new RuntimeException("NetworkInterface.getNetworkInterfaces() should throw SocketException");
} catch (SocketException expected) {
System.out.println("caught expected exception: " + expected);
}
try {
NetworkInterface.networkInterfaces();
throw new RuntimeException("NetworkInterface.networkInterfaces() should throw SocketException");
} catch (SocketException expected) {
System.out.println("caught expected exception: " + expected);
}
}
}