8078219: Verify lack of @test tag in files in java/net test directory
authoraefimov
Thu, 22 Aug 2019 18:54:56 +0100
changeset 57846 01d9a1cff83a
parent 57845 db6829c1cc3a
child 57847 bc14eec6f4bc
8078219: Verify lack of @test tag in files in java/net test directory Reviewed-by: alanb Contributed-by: Patrick Concannon <patrick.concannon@oracle.com>
test/jdk/java/net/MulticastSocket/MulticastAddresses.java
test/jdk/java/net/MulticastSocket/Reuse.java
test/jdk/java/net/URLClassLoader/GetURLsTest.java
--- a/test/jdk/java/net/MulticastSocket/MulticastAddresses.java	Thu Aug 22 10:41:07 2019 -0700
+++ b/test/jdk/java/net/MulticastSocket/MulticastAddresses.java	Thu Aug 22 18:54:56 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -22,76 +22,32 @@
  */
 
 /*
- *
+ * @test
  * @bug 4488458
+ * @library /test/lib
  * @summary Test that MutlicastSocket.joinGroup is working for
  *          various multicast and non-multicast addresses.
  */
+
+import jdk.test.lib.NetworkConfiguration;
+
 import java.net.*;
-import java.util.Enumeration;
 import java.io.IOException;
+import java.util.stream.Collectors;
 
 public class MulticastAddresses {
-
-    public static void main(String args[]) throws Exception {
-
-        boolean ipv6_available = false;
-        NetworkInterface ni = null;
-
-        /*
-         * Examine the network interfaces and determine :-
-         *
-         * 1. If host has IPv6 support
-         * 2. Get reference to a non-loopback interface
-         */
-        Enumeration nifs = NetworkInterface.getNetworkInterfaces();
-        while (nifs.hasMoreElements()) {
-            NetworkInterface this_ni = (NetworkInterface)nifs.nextElement();
-
-            Enumeration addrs = this_ni.getInetAddresses();
-            while (addrs.hasMoreElements()) {
-                InetAddress addr = (InetAddress)addrs.nextElement();
-                if (addr instanceof Inet6Address) {
-                    ipv6_available = true;
-                }
-
-                if (!addr.isLoopbackAddress() && ni == null) {
-                    ni = this_ni;
-                }
-            }
-
-            if (ipv6_available) {
-                break;
-            }
-        }
-
+    public static void runTest(NetworkInterface ni,
+                               String[] multicasts,
+                               String[] nonMulticasts) throws Exception {
         int failures = 0;
 
-        String multicasts[] = {
-                "224.80.80.80",
-                "ff01::1",
-                "ff02::1234",
-                "ff05::a",
-                "ff0e::1234:a" };
-
-        String non_multicasts[] = {
-                "129.1.1.1",
-                "::1",
-                "::129.1.1.1",
-                "fe80::a00:20ff:fee5:bc02" };
-
         MulticastSocket s = new MulticastSocket();
 
         /* test valid multicast addresses */
-
-        for (int i=0; i<multicasts.length; i++) {
+        for (int i = 0; i < multicasts.length; i++) {
             InetAddress ia = InetAddress.getByName(multicasts[i]);
-            if (ia instanceof Inet6Address && !ipv6_available) {
-                continue;
-            }
 
-            System.out.println("Test: " + ia);
-
+            System.out.println("Test: " + ia + " " + " ni: " + ni);
             try {
 
                 System.out.print("    joinGroup(InetAddress) ");
@@ -100,8 +56,8 @@
                 System.out.println("    Passed.");
 
                 System.out.print("    joinGroup(InetAddress,NetworkInterface) ");
-                s.joinGroup(new InetSocketAddress(ia,0), ni);
-                s.leaveGroup(new InetSocketAddress(ia,0), ni);
+                s.joinGroup(new InetSocketAddress(ia, 0), ni);
+                s.leaveGroup(new InetSocketAddress(ia, 0), ni);
                 System.out.println("    Passed.");
             } catch (IOException e) {
                 failures++;
@@ -111,13 +67,8 @@
         }
 
         /* test non-multicast addresses */
-
-        for (int i=0; i<non_multicasts.length; i++) {
-            InetAddress ia = InetAddress.getByName(non_multicasts[i]);
-            if (ia instanceof Inet6Address && !ipv6_available) {
-                continue;
-            }
-
+        for (int i = 0; i < nonMulticasts.length; i++) {
+            InetAddress ia = InetAddress.getByName(nonMulticasts[i]);
             boolean failed = false;
 
             System.out.println("Test: " + ia + " ");
@@ -130,20 +81,59 @@
             } catch (IOException e) {
                 System.out.println("    Passed: " + e.getMessage());
             }
-
             if (failed) {
                 s.leaveGroup(ia);
                 failures++;
             }
         }
-
-        /* done */
-
         s.close();
-
         if (failures > 0) {
             throw new Exception(failures + " test(s) failed - see log file.");
         }
     }
 
+
+    public static void main(String args[]) throws Exception {
+
+        String[] multicastIPv4 = {
+                "224.80.80.80",
+        };
+        String[] multicastIPv6 = {
+                "ff01::1",
+                "ff02::1234",
+                "ff05::a",
+                "ff0e::1234:a"};
+
+        String[] nonMulticastIPv4 = {
+                "129.1.1.1"
+        };
+
+        String[] nonMulticastIPv6 = {
+                "::1",
+                "::129.1.1.1",
+                "fe80::a00:20ff:fee5:bc02"};
+
+        /*
+         * Examine the network interfaces and determine :-
+         *
+         * 1. If host has IPv6 support
+         * 2. Get reference to a non-loopback interface
+         */
+        NetworkConfiguration nc = NetworkConfiguration.probe();
+        var ipv6List = nc.ip6MulticastInterfaces(false)
+                .collect(Collectors.toList());
+
+        var ipv4List = nc.ip4MulticastInterfaces(false)
+                .collect(Collectors.toList());
+
+        if (ipv6List.retainAll(ipv4List)) {
+            runTest(ipv6List.get(0), multicastIPv4, nonMulticastIPv4);
+            runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
+        } else {
+            if (!ipv4List.isEmpty())
+                runTest(ipv4List.get(0), multicastIPv4, nonMulticastIPv4);
+            if (!ipv6List.isEmpty())
+                runTest(ipv6List.get(0), multicastIPv6, nonMulticastIPv6);
+        }
+    }
 }
--- a/test/jdk/java/net/MulticastSocket/Reuse.java	Thu Aug 22 10:41:07 2019 -0700
+++ b/test/jdk/java/net/MulticastSocket/Reuse.java	Thu Aug 22 18:54:56 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,11 @@
 import java.net.MulticastSocket;
 import java.net.BindException;
 
+/*
+ * @test
+ * @summary Check if MulticastSocket sets SO_REUSEADDR
+ */
+
 public class Reuse {
     public static void main(String[] args) throws Exception {
         MulticastSocket s1, s2;
--- a/test/jdk/java/net/URLClassLoader/GetURLsTest.java	Thu Aug 22 10:41:07 2019 -0700
+++ b/test/jdk/java/net/URLClassLoader/GetURLsTest.java	Thu Aug 22 18:54:56 2019 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,11 +25,16 @@
 import java.io.*;
 
 /*
- * Regression test for URLClassLoader getURLs() and addURL() methods.
+ * @test
+ * @summary Regression test for URLClassLoader getURLs() and addURL() methods.
  * See RFE 4102580: Need URLClassLoader.getURLs() method
  */
-class GetURLsTest {
+public class GetURLsTest {
+    static final String TEST_DIR = System.getProperty("test.src", ".");
+
     public static void main(String[] args) throws Exception {
+        File testJars = new File(TEST_DIR, "jars");
+
         MyURLClassLoader ucl =
             new MyURLClassLoader(new URL[] { new File(".").toURL() });
         p("initial urls = ", ucl.getURLs());
@@ -37,7 +42,7 @@
         if (u != null) {
             p("found resource = " + u);
         }
-        ucl.addURL(new File("jars", "class_path_test.jar").toURL());
+        ucl.addURL(new File(testJars, "class_path_test.jar").toURL());
         p("new urls = ", ucl.getURLs());
         Class c = ucl.loadClass("Foo");
         p("found class = " + c);