Workaround to have multicast tests work on osx, linux and windows

This commit is contained in:
Norman Maurer 2012-04-10 21:00:44 +02:00
parent f17e56b33b
commit 4436f60e2f

View File

@ -28,6 +28,7 @@ import io.netty.channel.socket.DatagramChannelFactory;
import io.netty.testsuite.util.TestUtils;
import io.netty.util.internal.ExecutorUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.NetworkInterface;
import java.util.concurrent.CountDownLatch;
@ -72,7 +73,13 @@ public abstract class AbstractDatagramMulticastTest {
int port = TestUtils.getFreePort();
NetworkInterface iface = NetworkInterface.getNetworkInterfaces().nextElement();
NetworkInterface iface = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
// check if the NetworkInterface is null, this is the case on my ubuntu dev machine but not on osx and windows.
// if so fail back the the first interface
if (iface == null) {
iface = NetworkInterface.getByIndex(0);
}
sb.setOption("networkInterface", iface);
sb.setOption("reuseAddress", true);