|
25 | 25 | import java.net.InetAddress;
|
26 | 26 | import java.net.NetworkInterface;
|
27 | 27 | import java.util.Enumeration;
|
| 28 | +import java.util.LinkedList; |
28 | 29 | import java.util.List;
|
29 | 30 | import java.util.Locale;
|
30 | 31 | import org.apache.hadoop.conf.Configuration;
|
@@ -89,9 +90,7 @@ public void testInvalidRegionServerHostnameAbortsServer() throws Exception {
|
89 | 90 |
|
90 | 91 | @Test
|
91 | 92 | public void testRegionServerHostname() throws Exception {
|
92 |
| - Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces(); |
93 |
| - while (netInterfaceList.hasMoreElements()) { |
94 |
| - NetworkInterface ni = netInterfaceList.nextElement(); |
| 93 | + for (NetworkInterface ni : getValidNetworkInterfaces()) { |
95 | 94 | Enumeration<InetAddress> addrList = ni.getInetAddresses();
|
96 | 95 | // iterate through host addresses and use each as hostname
|
97 | 96 | while (addrList.hasMoreElements()) {
|
@@ -205,4 +204,25 @@ public void testRegionServerHostnameReportedToMaster() throws Exception {
|
205 | 204 | assertEquals(expectedRS, servers.size());
|
206 | 205 | }
|
207 | 206 | }
|
| 207 | + |
| 208 | + private boolean ignoreNetworkInterface(NetworkInterface networkInterface) throws Exception { |
| 209 | + return networkInterface == null |
| 210 | + || networkInterface.isLoopback() |
| 211 | + || networkInterface.isVirtual() |
| 212 | + || !networkInterface.isUp(); |
| 213 | + } |
| 214 | + |
| 215 | + |
| 216 | + private List<NetworkInterface> getValidNetworkInterfaces() throws Exception { |
| 217 | + List<NetworkInterface> validNetworkInterfaces = new LinkedList<>(); |
| 218 | + Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); |
| 219 | + while (interfaces.hasMoreElements()) { |
| 220 | + NetworkInterface networkInterface = interfaces.nextElement(); |
| 221 | + if (ignoreNetworkInterface(networkInterface)) { |
| 222 | + continue; |
| 223 | + } |
| 224 | + validNetworkInterfaces.add(networkInterface); |
| 225 | + } |
| 226 | + return validNetworkInterfaces; |
| 227 | + } |
208 | 228 | }
|
0 commit comments