mirror of https://github.com/apache/jclouds.git
fixed bug in aws-simpledb tests
This commit is contained in:
parent
2759da648d
commit
d5e18405bf
|
@ -53,6 +53,8 @@ import com.google.inject.TypeLiteral;
|
|||
@Test(groups = "unit", testName = "SimpleDBAsyncClientTest")
|
||||
public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient> {
|
||||
|
||||
protected String provider = "simpledb";
|
||||
|
||||
@RequiresHttp
|
||||
@ConfiguresRestClient
|
||||
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
|
||||
|
@ -133,7 +135,7 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
|
|||
|
||||
@Override
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("simpledb", "identity", "credential", new Properties());
|
||||
return new RestContextFactory().createContextSpec(provider, "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import java.util.Map.Entry;
|
|||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
|
@ -50,6 +51,7 @@ import org.jclouds.rest.config.RestClientModule;
|
|||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.inject.ConfigurationException;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -75,16 +77,23 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
|||
@Provides
|
||||
@Singleton
|
||||
@Region
|
||||
@Nullable
|
||||
protected Map<String, URI> provideRegions(Injector injector) {
|
||||
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
|
||||
Map<String, URI> regions = newLinkedHashMap();
|
||||
for (String region : Splitter.on(',').split(regionString)) {
|
||||
regions.put(
|
||||
region,
|
||||
URI.create(injector.getInstance(Key.get(String.class,
|
||||
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
||||
try {
|
||||
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
|
||||
Map<String, URI> regions = newLinkedHashMap();
|
||||
for (String region : Splitter.on(',').split(regionString)) {
|
||||
regions.put(
|
||||
region,
|
||||
URI.create(injector.getInstance(Key.get(String.class,
|
||||
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
||||
}
|
||||
return regions;
|
||||
} catch (ConfigurationException e) {
|
||||
// this happens if regions property isn't set
|
||||
// services not run by AWS may not have regions, so this is ok.
|
||||
return null;
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -27,16 +27,17 @@ import java.net.URI;
|
|||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.location.Provider;
|
||||
import org.jclouds.location.Region;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* If a mapping of regions to endpoints exists, return a corresponding
|
||||
* If a mapping of regions to endpoints exists, return a uri corresponding to the name of the region
|
||||
* (passed argument). Otherwise, return the default location.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
|
@ -44,25 +45,25 @@ import com.google.inject.Inject;
|
|||
public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
|
||||
private final URI defaultUri;
|
||||
private final String defaultProvider;
|
||||
|
||||
@Inject(optional = true)
|
||||
@Region
|
||||
Map<String, URI> regionToEndpoint;
|
||||
private final Map<String, URI> regionToEndpoint;
|
||||
|
||||
@Inject
|
||||
public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Provider String defaultProvider) {
|
||||
public RegionToEndpointOrProviderIfNull(@Provider URI defaultUri, @Provider String defaultProvider,
|
||||
@Nullable @Region Map<String, URI> regionToEndpoint) {
|
||||
this.defaultUri = checkNotNull(defaultUri, "defaultUri");
|
||||
this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider");
|
||||
this.regionToEndpoint = regionToEndpoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI apply(@Nullable Object from) {
|
||||
checkState(from == null || from.equals(defaultProvider) || regionToEndpoint != null, "requested location " + from
|
||||
+ ", but only the default location " + defaultProvider + " is configured");
|
||||
checkArgument(from == null || from.equals(defaultProvider) || regionToEndpoint.containsKey(from),
|
||||
"requested location " + from + ", which is not in the configured locations: " + regionToEndpoint.keySet());
|
||||
checkArgument(
|
||||
from == null || from.equals(defaultProvider)
|
||||
|| (regionToEndpoint != null && regionToEndpoint.containsKey(from)),
|
||||
"requested location %s, which is not in the configured locations: %s", from, regionToEndpoint);
|
||||
|
||||
return from == null || from.equals(defaultProvider) ? defaultUri : regionToEndpoint.get(from);
|
||||
}
|
||||
|
||||
}
|
|
@ -39,7 +39,7 @@ simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder
|
|||
simpledb.propertiesbuilder=org.jclouds.simpledb.SimpleDBPropertiesBuilder
|
||||
|
||||
aws-simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder
|
||||
aws-simpledb..propertiesbuilder=org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder
|
||||
aws-simpledb.propertiesbuilder=org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder
|
||||
|
||||
elb.contextbuilder=org.jclouds.aws.elb.ELBContextBuilder
|
||||
elb.propertiesbuilder=org.jclouds.aws.elb.ELBPropertiesBuilder
|
||||
|
|
|
@ -23,10 +23,7 @@ import static org.jclouds.aws.simpledb.SimpleDBPropertiesBuilder.DEFAULT_REGIONS
|
|||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.rest.RestContextFactory;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.simpledb.SimpleDBAsyncClient;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -39,7 +36,9 @@ import org.testng.annotations.Test;
|
|||
@Test(groups = "unit", testName = "aws.SimpleDBAsyncClientTest")
|
||||
public class SimpleDBAsyncClientTest extends org.jclouds.simpledb.SimpleDBAsyncClientTest {
|
||||
|
||||
|
||||
public SimpleDBAsyncClientTest() {
|
||||
this.provider = "aws-simpledb";
|
||||
}
|
||||
|
||||
// TODO fix this test as it has the wrong arg count
|
||||
@Test(enabled = false)
|
||||
|
@ -50,9 +49,4 @@ public class SimpleDBAsyncClientTest extends org.jclouds.simpledb.SimpleDBAsyncC
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestContextSpec<?, ?> createContextSpec() {
|
||||
return new RestContextFactory().createContextSpec("aws-simpledb", "identity", "credential", new Properties());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue