< prev index next >

jdk/test/java/nio/channels/DatagramChannel/MulticastSendReceiveTests.java

Print this page
rev 17203 : 8180644: move jdk.testlibrary.NetworkConfiguration to the top level test library
Reviewed-by: duke


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4527345 7026376 6633549
  26  * @summary Unit test for DatagramChannel's multicast support
  27  * @build MulticastSendReceiveTests NetworkConfiguration

  28  * @run main MulticastSendReceiveTests
  29  * @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests
  30  * @key randomness
  31  */
  32 
  33 import java.nio.ByteBuffer;
  34 import java.nio.channels.*;
  35 import java.net.*;
  36 import static java.net.StandardProtocolFamily.*;
  37 import java.util.*;
  38 import java.io.IOException;



  39 
  40 public class MulticastSendReceiveTests {
  41 
  42     static final Random rand = new Random();
  43 
  44     static final ProtocolFamily UNSPEC = new ProtocolFamily() {
  45         public String name() {
  46             return "UNSPEC";
  47         }
  48     };
  49 
  50     /**
  51      * Send datagram from given local address to given multicast
  52      * group.
  53      */
  54     static int sendDatagram(InetAddress local,
  55                             NetworkInterface nif,
  56                             InetAddress group,
  57                             int port)
  58         throws IOException


 221                 key = dc.join(group, nif, source);
 222 
 223                 id = sendDatagram(source, nif, group, port);
 224                 receiveDatagram(dc, source, id);
 225             } catch (UnsupportedOperationException x) {
 226                 String os = System.getProperty("os.name");
 227                 // Include-mode filtering supported on these platforms so UOE should never be thrown
 228                 if (os.equals("SunOS") || os.equals("Linux"))
 229                     throw x;
 230                 System.out.println("Include-mode filtering not supported!");
 231             }
 232         }
 233     }
 234 
 235     public static void main(String[] args) throws IOException {
 236         NetworkConfiguration config = NetworkConfiguration.probe();
 237 
 238         // multicast groups used for the test
 239         InetAddress ip4Group = InetAddress.getByName("225.4.5.6");
 240         InetAddress ip6Group = InetAddress.getByName("ff02::a");
 241 
 242         for (NetworkInterface nif: config.ip4Interfaces()) {
 243             InetAddress source = config.ip4Addresses(nif).iterator().next();
 244             test(INET,   nif, ip4Group, source);
 245             test(UNSPEC, nif, ip4Group, source);
 246         }
 247 
 248         for (NetworkInterface nif: config.ip6Interfaces()) {

 249             InetAddress source = config.ip6Addresses(nif).iterator().next();
 250             test(INET6,  nif, ip6Group, source);
 251             test(UNSPEC, nif, ip6Group, source);
 252         }
 253     }
 254 }


   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /* @test
  25  * @bug 4527345 7026376 6633549
  26  * @summary Unit test for DatagramChannel's multicast support
  27  * @library /test/lib
  28  * @build MulticastSendReceiveTests
  29  * @run main MulticastSendReceiveTests
  30  * @run main/othervm -Djava.net.preferIPv4Stack=true MulticastSendReceiveTests
  31  * @key randomness
  32  */
  33 
  34 import java.nio.ByteBuffer;
  35 import java.nio.channels.*;
  36 import java.net.*;
  37 import static java.net.StandardProtocolFamily.*;
  38 import java.util.*;
  39 import java.io.IOException;
  40 import java.util.stream.Collectors;
  41 
  42 import jdk.test.lib.NetworkConfiguration;
  43 
  44 public class MulticastSendReceiveTests {
  45 
  46     static final Random rand = new Random();
  47 
  48     static final ProtocolFamily UNSPEC = new ProtocolFamily() {
  49         public String name() {
  50             return "UNSPEC";
  51         }
  52     };
  53 
  54     /**
  55      * Send datagram from given local address to given multicast
  56      * group.
  57      */
  58     static int sendDatagram(InetAddress local,
  59                             NetworkInterface nif,
  60                             InetAddress group,
  61                             int port)
  62         throws IOException


 225                 key = dc.join(group, nif, source);
 226 
 227                 id = sendDatagram(source, nif, group, port);
 228                 receiveDatagram(dc, source, id);
 229             } catch (UnsupportedOperationException x) {
 230                 String os = System.getProperty("os.name");
 231                 // Include-mode filtering supported on these platforms so UOE should never be thrown
 232                 if (os.equals("SunOS") || os.equals("Linux"))
 233                     throw x;
 234                 System.out.println("Include-mode filtering not supported!");
 235             }
 236         }
 237     }
 238 
 239     public static void main(String[] args) throws IOException {
 240         NetworkConfiguration config = NetworkConfiguration.probe();
 241 
 242         // multicast groups used for the test
 243         InetAddress ip4Group = InetAddress.getByName("225.4.5.6");
 244         InetAddress ip6Group = InetAddress.getByName("ff02::a");
 245         for (NetworkInterface nif: config.ip4MulticastInterfaces()
 246                                          .collect(Collectors.toList())) {
 247             InetAddress source = config.ip4Addresses(nif).iterator().next();
 248             test(INET,   nif, ip4Group, source);
 249             test(UNSPEC, nif, ip4Group, source);
 250         }
 251 
 252         for (NetworkInterface nif: config.ip6MulticastInterfaces()
 253                                          .collect(Collectors.toList())) {
 254             InetAddress source = config.ip6Addresses(nif).iterator().next();
 255             test(INET6,  nif, ip6Group, source);
 256             test(UNSPEC, nif, ip6Group, source);
 257         }
 258     }
 259 }
< prev index next >