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")
|
@Test(groups = "unit", testName = "SimpleDBAsyncClientTest")
|
||||||
public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient> {
|
public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient> {
|
||||||
|
|
||||||
|
protected String provider = "simpledb";
|
||||||
|
|
||||||
@RequiresHttp
|
@RequiresHttp
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
|
private static final class TestSimpleDBRestClientModule extends SimpleDBRestClientModule {
|
||||||
|
@ -133,7 +135,7 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RestContextSpec<?, ?> createContextSpec() {
|
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.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
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.Predicate;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
import com.google.inject.ConfigurationException;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Key;
|
import com.google.inject.Key;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
@ -75,7 +77,9 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
||||||
@Provides
|
@Provides
|
||||||
@Singleton
|
@Singleton
|
||||||
@Region
|
@Region
|
||||||
|
@Nullable
|
||||||
protected Map<String, URI> provideRegions(Injector injector) {
|
protected Map<String, URI> provideRegions(Injector injector) {
|
||||||
|
try {
|
||||||
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
|
String regionString = injector.getInstance(Key.get(String.class, Names.named(PROPERTY_REGIONS)));
|
||||||
Map<String, URI> regions = newLinkedHashMap();
|
Map<String, URI> regions = newLinkedHashMap();
|
||||||
for (String region : Splitter.on(',').split(regionString)) {
|
for (String region : Splitter.on(',').split(regionString)) {
|
||||||
|
@ -85,6 +89,11 @@ public class AWSRestClientModule<S, A> extends RestClientModule<S, A> {
|
||||||
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
Names.named(Constants.PROPERTY_ENDPOINT + "." + region)))));
|
||||||
}
|
}
|
||||||
return regions;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -27,16 +27,17 @@ import java.net.URI;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
import org.jclouds.location.Provider;
|
import org.jclouds.location.Provider;
|
||||||
import org.jclouds.location.Region;
|
import org.jclouds.location.Region;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
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
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
|
@ -44,25 +45,25 @@ import com.google.inject.Inject;
|
||||||
public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
|
public class RegionToEndpointOrProviderIfNull implements Function<Object, URI> {
|
||||||
private final URI defaultUri;
|
private final URI defaultUri;
|
||||||
private final String defaultProvider;
|
private final String defaultProvider;
|
||||||
|
private final Map<String, URI> regionToEndpoint;
|
||||||
@Inject(optional = true)
|
|
||||||
@Region
|
|
||||||
Map<String, URI> regionToEndpoint;
|
|
||||||
|
|
||||||
@Inject
|
@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.defaultUri = checkNotNull(defaultUri, "defaultUri");
|
||||||
this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider");
|
this.defaultProvider = checkNotNull(defaultProvider, "defaultProvider");
|
||||||
|
this.regionToEndpoint = regionToEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI apply(@Nullable Object from) {
|
public URI apply(@Nullable Object from) {
|
||||||
checkState(from == null || from.equals(defaultProvider) || regionToEndpoint != null, "requested location " + from
|
checkState(from == null || from.equals(defaultProvider) || regionToEndpoint != null, "requested location " + from
|
||||||
+ ", but only the default location " + defaultProvider + " is configured");
|
+ ", but only the default location " + defaultProvider + " is configured");
|
||||||
checkArgument(from == null || from.equals(defaultProvider) || regionToEndpoint.containsKey(from),
|
checkArgument(
|
||||||
"requested location " + from + ", which is not in the configured locations: " + regionToEndpoint.keySet());
|
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);
|
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
|
simpledb.propertiesbuilder=org.jclouds.simpledb.SimpleDBPropertiesBuilder
|
||||||
|
|
||||||
aws-simpledb.contextbuilder=org.jclouds.simpledb.SimpleDBContextBuilder
|
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.contextbuilder=org.jclouds.aws.elb.ELBContextBuilder
|
||||||
elb.propertiesbuilder=org.jclouds.aws.elb.ELBPropertiesBuilder
|
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.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
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.jclouds.simpledb.SimpleDBAsyncClient;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -39,7 +36,9 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "unit", testName = "aws.SimpleDBAsyncClientTest")
|
@Test(groups = "unit", testName = "aws.SimpleDBAsyncClientTest")
|
||||||
public class SimpleDBAsyncClientTest extends org.jclouds.simpledb.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
|
// TODO fix this test as it has the wrong arg count
|
||||||
@Test(enabled = false)
|
@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