8238376: test/jdk/java/nio/channels/DatagramChannel/Loopback.java failing on multi-homed systems

Alan Bateman Alan.Bateman at oracle.com
Sun Feb 9 16:14:32 UTC 2020


test/jdk/java/nio/channels/DatagramChannel/Loopback.java is a test we 
added recently to check the behavior of the IP_MULTICAST_LOOP socket 
option. This tests is failing on test systems that are connected to 
several networks because the test doesn't set the interface for outgoing 
multicast datagrams. Amy Lu has checked the test passes with this change.

-Alan

--- a/test/jdk/java/nio/channels/DatagramChannel/Loopback.java
+++ b/test/jdk/java/nio/channels/DatagramChannel/Loopback.java
@@ -1,5 +1,5 @@
  /*
- * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2020, 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
@@ -45,7 +45,9 @@
  import java.nio.channels.Selector;
  import java.util.List;
  import java.util.stream.Collectors;
-import static java.net.StandardProtocolFamily.*;
+import static java.net.StandardProtocolFamily.INET;
+import static java.net.StandardProtocolFamily.INET6;
+import static java.net.StandardSocketOptions.IP_MULTICAST_IF;
  import static java.net.StandardSocketOptions.IP_MULTICAST_LOOP;

  import jdk.test.lib.NetworkConfiguration;
@@ -106,6 +108,9 @@
              System.out.format("join %s @ %s%n", 
group.getHostAddress(), ni.getName());
              dc.join(group, ni);

+            System.out.format("set outgoing multicast interface to 
%s%n", ni.getName());
+            dc.setOption(IP_MULTICAST_IF, ni);
+
              // -- IP_MULTICAST_LOOP enabled --

              assertTrue(dc.getOption(IP_MULTICAST_LOOP), 
"IP_MULTICAST_LOOP not enabled");


More information about the nio-dev mailing list