8131155: java/net/NetworkInterface/NetworkInterfaceStreamTest.java failed because of Teredo Tunneling Pseudo-Interface
authorxiaofeya
Mon, 21 Dec 2015 13:43:53 +0800
changeset 34722 1d23e916f189
parent 34721 59801fbd042e
child 34723 734a1c90ce86
8131155: java/net/NetworkInterface/NetworkInterfaceStreamTest.java failed because of Teredo Tunneling Pseudo-Interface Reviewed-by: amlu, chegar, psandoz
jdk/test/java/net/NetworkInterface/NetworkInterfaceStreamTest.java
--- a/jdk/test/java/net/NetworkInterface/NetworkInterfaceStreamTest.java	Mon Dec 21 09:40:00 2015 +0530
+++ b/jdk/test/java/net/NetworkInterface/NetworkInterfaceStreamTest.java	Mon Dec 21 13:43:53 2015 +0800
@@ -22,13 +22,12 @@
  */
 
 /* @test
- * @bug 8081678
+ * @bug 8081678 8131155
  * @summary Tests for stream returning methods
  * @library ../../util/stream/bootlib/java.base
  * @build java.util.stream.OpTestCase
  * @run testng/othervm NetworkInterfaceStreamTest
  * @run testng/othervm -Djava.net.preferIPv4Stack=true NetworkInterfaceStreamTest
- * @key intermittent
  */
 
 import org.testng.annotations.Test;
@@ -46,6 +45,8 @@
 
 public class NetworkInterfaceStreamTest extends OpTestCase {
 
+    private final static boolean IS_WINDOWS = System.getProperty("os.name").startsWith("Windows");
+
     @Test
     public void testNetworkInterfaces() throws SocketException {
         Supplier<Stream<NetworkInterface>> ss = () -> {
@@ -74,7 +75,9 @@
     }
 
     private void getAllSubNetworkInterfaces(NetworkInterface ni, Collection<NetworkInterface> result) {
-        result.add(ni);
+        if (isIncluded(ni)) {
+            result.add(ni);
+        }
 
         for (NetworkInterface sni : Collections.list(ni.getSubInterfaces())) {
             getAllSubNetworkInterfaces(sni, result);
@@ -114,7 +117,9 @@
     public void testInetAddresses() throws SocketException {
         Supplier<Stream<InetAddress>> ss = () -> {
             try {
-                return NetworkInterface.networkInterfaces().flatMap(NetworkInterface::inetAddresses);
+                return NetworkInterface.networkInterfaces()
+                        .filter(ni -> isIncluded(ni))
+                        .flatMap(NetworkInterface::inetAddresses);
             }
             catch (SocketException e) {
                 throw new RuntimeException(e);
@@ -132,5 +137,21 @@
                 .exercise();
     }
 
+    /**
+     * Check if the input network interface should be included in the test. It is necessary to exclude
+     * "Teredo Tunneling Pseudo-Interface" whose configuration can be variable during a test run.
+     *
+     * @param ni a network interace
+     * @return false if it is a "Teredo Tunneling Pseudo-Interface", otherwise true.
+     */
+    private boolean isIncluded(NetworkInterface ni) {
+        if (!IS_WINDOWS) {
+            return true;
+        }
+
+        String dName = ni.getDisplayName();
+        return dName == null || !dName.contains("Teredo");
+    }
 
 }
+