Fix network interface test issues . (#2774)

pull/2811/head
o‘Laoxu 2 years ago committed by GitHub
parent 11d6cf90bf
commit 3ba918ce09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -19,6 +19,7 @@ package com.alibaba.cloud.nacos.registry;
import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.net.Inet4Address; import java.net.Inet4Address;
import java.net.Inet6Address;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.util.Enumeration; import java.util.Enumeration;
@ -119,6 +120,7 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
while (inetAddress.hasMoreElements()) { while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement(); InetAddress currentAddress = inetAddress.nextElement();
if (currentAddress instanceof Inet4Address if (currentAddress instanceof Inet4Address
|| currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress()) { && !currentAddress.isLoopbackAddress()) {
return currentAddress.getHostAddress(); return currentAddress.getHostAddress();
} }
@ -152,6 +154,7 @@ public class NacosAutoServiceRegistrationIpNetworkInterfaceTests {
while (inetAddress.hasMoreElements()) { while (inetAddress.hasMoreElements()) {
InetAddress currentAddress = inetAddress.nextElement(); InetAddress currentAddress = inetAddress.nextElement();
if (currentAddress instanceof Inet4Address if (currentAddress instanceof Inet4Address
|| currentAddress instanceof Inet6Address
&& !currentAddress.isLoopbackAddress()) { && !currentAddress.isLoopbackAddress()) {
hasValidNetworkInterface = true; hasValidNetworkInterface = true;
netWorkInterfaceName = networkInterface.getName(); netWorkInterfaceName = networkInterface.getName();

Loading…
Cancel
Save