Make sure the test also work on ipv6 interfaces
This commit is contained in:
parent
21eada0a6a
commit
5f28d01507
@ -18,10 +18,12 @@ package org.jboss.netty.channel.socket.nio;
|
|||||||
import org.jboss.netty.util.internal.DetectionUtil;
|
import org.jboss.netty.util.internal.DetectionUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Inet4Address;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.StandardProtocolFamily;
|
import java.net.StandardProtocolFamily;
|
||||||
import java.nio.channels.DatagramChannel;
|
import java.nio.channels.DatagramChannel;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
@ -29,13 +31,36 @@ import org.junit.Test;
|
|||||||
|
|
||||||
public class DefaultNioDatagramChannelConfigTest {
|
public class DefaultNioDatagramChannelConfigTest {
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMulticastOptions() throws IOException {
|
public void testMulticastOptions() throws IOException {
|
||||||
if (DetectionUtil.javaVersion() < 7) {
|
if (DetectionUtil.javaVersion() < 7) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(StandardProtocolFamily.INET));
|
|
||||||
NetworkInterface inf = NetworkInterface.getNetworkInterfaces().nextElement();
|
StandardProtocolFamily family = null;
|
||||||
|
NetworkInterface inf = null;
|
||||||
|
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
||||||
|
while (interfaces.hasMoreElements()) {
|
||||||
|
inf = interfaces.nextElement();
|
||||||
|
Enumeration<InetAddress> addresses = inf.getInetAddresses();
|
||||||
|
while(addresses.hasMoreElements()) {
|
||||||
|
InetAddress addr = addresses.nextElement();
|
||||||
|
if (addr instanceof Inet4Address) {
|
||||||
|
family = StandardProtocolFamily.INET;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
family = StandardProtocolFamily.INET6;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (inf == null) {
|
||||||
|
// No usable interface found so just skip the test
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DefaultNioDatagramChannelConfig config = new DefaultNioDatagramChannelConfig(DatagramChannel.open(family));
|
||||||
|
|
||||||
config.setNetworkInterface(inf);
|
config.setNetworkInterface(inf);
|
||||||
Assert.assertEquals(inf, config.getNetworkInterface());
|
Assert.assertEquals(inf, config.getNetworkInterface());
|
||||||
|
|
||||||
@ -48,6 +73,5 @@ public class DefaultNioDatagramChannelConfigTest {
|
|||||||
|
|
||||||
config.setLoopbackModeDisabled(false);
|
config.setLoopbackModeDisabled(false);
|
||||||
Assert.assertEquals(false, config.isLoopbackModeDisabled());
|
Assert.assertEquals(false, config.isLoopbackModeDisabled());
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user