diff --git a/eureka-client-archaius2/src/test/java/com/netflix/appinfo/Ec2EurekaArchaius2InstanceConfigTest.java b/eureka-client-archaius2/src/test/java/com/netflix/appinfo/Ec2EurekaArchaius2InstanceConfigTest.java index 7c6b0d371..e4946d4c1 100644 --- a/eureka-client-archaius2/src/test/java/com/netflix/appinfo/Ec2EurekaArchaius2InstanceConfigTest.java +++ b/eureka-client-archaius2/src/test/java/com/netflix/appinfo/Ec2EurekaArchaius2InstanceConfigTest.java @@ -7,6 +7,7 @@ import java.util.Collections; +import static com.netflix.appinfo.AmazonInfo.MetaDataKey.ipv6; import static com.netflix.appinfo.AmazonInfo.MetaDataKey.localIpv4; import static com.netflix.appinfo.AmazonInfo.MetaDataKey.publicHostname; import static org.hamcrest.CoreMatchers.is; @@ -37,6 +38,10 @@ public void testResolveDefaultAddress() { info.getMetadata().remove(localIpv4.getName()); config = createConfig(info); + assertThat(config.resolveDefaultAddress(false), is(info.get(ipv6))); + + info.getMetadata().remove(ipv6.getName()); + config = createConfig(info); assertThat(config.resolveDefaultAddress(false), is(dummyDefault)); } @@ -47,7 +52,8 @@ private Ec2EurekaArchaius2InstanceConfig createConfig(AmazonInfo info) { public String[] getDefaultAddressResolutionOrder() { return new String[] { publicHostname.name(), - localIpv4.name() + localIpv4.name(), + ipv6.name() }; } diff --git a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java index 5c69d3c9d..67eb6e672 100644 --- a/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java +++ b/eureka-client/src/main/java/com/netflix/appinfo/AmazonInfo.java @@ -63,6 +63,7 @@ public enum MetaDataKey { availabilityZone("availability-zone", "placement/"), publicHostname("public-hostname"), publicIpv4("public-ipv4"), + ipv6("ipv6"), spotTerminationTime("termination-time", "spot/"), spotInstanceAction("instance-action", "spot/"), mac("mac"), // mac is declared above vpcId so will be found before vpcId (where it is needed) diff --git a/eureka-client/src/test/java/com/netflix/appinfo/CloudInstanceConfigTest.java b/eureka-client/src/test/java/com/netflix/appinfo/CloudInstanceConfigTest.java index e7fc18813..299d96e83 100644 --- a/eureka-client/src/test/java/com/netflix/appinfo/CloudInstanceConfigTest.java +++ b/eureka-client/src/test/java/com/netflix/appinfo/CloudInstanceConfigTest.java @@ -4,6 +4,7 @@ import org.junit.Before; import org.junit.Test; +import static com.netflix.appinfo.AmazonInfo.MetaDataKey.ipv6; import static com.netflix.appinfo.AmazonInfo.MetaDataKey.localIpv4; import static com.netflix.appinfo.AmazonInfo.MetaDataKey.publicHostname; import static org.hamcrest.CoreMatchers.is; @@ -37,6 +38,10 @@ public void testResolveDefaultAddress() { info.getMetadata().remove(localIpv4.getName()); config = createConfig(info); + assertThat(config.resolveDefaultAddress(false), is(info.get(ipv6))); + + info.getMetadata().remove(ipv6.getName()); + config = createConfig(info); assertThat(config.resolveDefaultAddress(false), is(dummyDefault)); } @@ -57,7 +62,8 @@ private CloudInstanceConfig createConfig(AmazonInfo info) { public String[] getDefaultAddressResolutionOrder() { return new String[] { publicHostname.name(), - localIpv4.name() + localIpv4.name(), + ipv6.name() }; } diff --git a/eureka-test-utils/src/main/java/com/netflix/discovery/util/InstanceInfoGenerator.java b/eureka-test-utils/src/main/java/com/netflix/discovery/util/InstanceInfoGenerator.java index 72ee2c5c7..5af4f01ea 100644 --- a/eureka-test-utils/src/main/java/com/netflix/discovery/util/InstanceInfoGenerator.java +++ b/eureka-test-utils/src/main/java/com/netflix/discovery/util/InstanceInfoGenerator.java @@ -174,6 +174,7 @@ private InstanceInfo generateInstanceInfo(int appIndex, int appInstanceId, boole String privateHostname = "ip-10.0" + appIndex + "." + appInstanceId + ".compute.internal"; String publicIp = "20.0." + appIndex + '.' + appInstanceId; String privateIp = "192.168." + appIndex + '.' + appInstanceId; + String ipv6 = "::FFFF:" + publicIp; String instanceId = String.format("i-%04d%04d", appIndex, appInstanceId); if (taggedId) { @@ -190,6 +191,7 @@ private InstanceInfo generateInstanceInfo(int appIndex, int appInstanceId, boole .addMetadata(MetaDataKey.localIpv4, privateIp) .addMetadata(MetaDataKey.publicHostname, hostName) .addMetadata(MetaDataKey.publicIpv4, publicIp) + .addMetadata(MetaDataKey.ipv6, ipv6) .build(); String unsecureURL = "http://" + hostName + ":8080";