Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from Randgalt/master
Update
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
curator-x-discovery/src/main/java/com/netflix/curator/x/discovery/LocalIpFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.netflix.curator.x.discovery; | ||
|
||
import java.net.InetAddress; | ||
import java.net.NetworkInterface; | ||
import java.net.SocketException; | ||
|
||
public interface LocalIpFilter | ||
{ | ||
public boolean use(NetworkInterface networkInterface, InetAddress address) throws SocketException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
curator-x-discovery/src/test/java/com/netflix/curator/x/discovery/TestLocalIpFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.netflix.curator.x.discovery; | ||
|
||
import com.google.common.collect.Lists; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
import java.net.InetAddress; | ||
import java.net.NetworkInterface; | ||
import java.net.SocketException; | ||
import java.util.List; | ||
|
||
public class TestLocalIpFilter | ||
{ | ||
@Test | ||
public void testFilterEverything() throws SocketException | ||
{ | ||
LocalIpFilter localIpFilter = ServiceInstanceBuilder.getLocalIpFilter(); | ||
try | ||
{ | ||
ServiceInstanceBuilder.setLocalIpFilter | ||
( | ||
new LocalIpFilter() | ||
{ | ||
@Override | ||
public boolean use(NetworkInterface networkInterface, InetAddress address) throws SocketException | ||
{ | ||
return false; | ||
} | ||
} | ||
); | ||
|
||
List<InetAddress> allLocalIPs = Lists.newArrayList(ServiceInstanceBuilder.getAllLocalIPs()); | ||
Assert.assertEquals(allLocalIPs.size(), 0); | ||
} | ||
finally | ||
{ | ||
ServiceInstanceBuilder.setLocalIpFilter(localIpFilter); | ||
} | ||
|
||
List<InetAddress> allLocalIPs = Lists.newArrayList(ServiceInstanceBuilder.getAllLocalIPs()); | ||
Assert.assertTrue(allLocalIPs.size() > 0); | ||
} | ||
} |