Issue 979:invalid endpoint returned when region name is the same as the provider

This commit is contained in:
Adrian Cole 2012-06-15 22:54:17 -04:00
parent 0ab86744cf
commit 593a09045b
2 changed files with 13 additions and 1 deletions

View File

@ -56,10 +56,15 @@ public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
@Override
public URI apply(@Nullable Object from) {
if (from == null || from.equals(defaultProvider))
if (from == null)
return defaultUri.get();
checkArgument(from instanceof String, "region is a String argument");
Map<String, Supplier<URI>> regionToEndpoint = regionToEndpointSupplier.get();
if (from.equals(defaultProvider)){
if (regionToEndpoint.containsKey(from))
return regionToEndpoint.get(from).get();
return defaultUri.get();
}
checkArgument(regionToEndpoint.containsKey(from),
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
return regionToEndpoint.get(from).get();

View File

@ -38,6 +38,13 @@ import com.google.common.collect.ImmutableMap;
@Test(groups = "unit", testName = "RegionToEndpointOrProviderIfNullTest")
public class RegionToEndpointOrProviderIfNullTest {
@Test
public void testWhenRegionNameIsSameAsProviderName() throws SecurityException, NoSuchMethodException {
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI
.create("http://leader")), Suppliers.<Map<String, Supplier<URI>>>ofInstance(ImmutableMap.of("leader", Suppliers.ofInstance(URI.create("http://leaderregion")))));
assertEquals(fn.apply("leader"), URI.create("http://leaderregion"));
}
@Test
public void testWhenFindsRegion() throws SecurityException, NoSuchMethodException {
RegionToEndpointOrProviderIfNull fn = new RegionToEndpointOrProviderIfNull("leader", Suppliers.ofInstance(URI