mirror of https://github.com/apache/jclouds.git
JCLOUDS-462: Fix AWSEC2TemplateBuilderLiveTest
This commit is contained in:
parent
9a8a604bac
commit
acd06b3024
|
@ -21,18 +21,17 @@ import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorServic
|
|||
import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.getInvokerOfRequestAtIndex;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.compute.ComputeServiceContext;
|
||||
import org.jclouds.compute.domain.Template;
|
||||
import org.jclouds.compute.internal.BaseTemplateBuilderLiveTest;
|
||||
import org.jclouds.ec2.features.AMIApi;
|
||||
import org.jclouds.ec2.features.AvailabilityZoneAndRegionApi;
|
||||
import org.jclouds.ec2.options.DescribeAvailabilityZonesOptions;
|
||||
import org.jclouds.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.ec2.options.DescribeRegionsOptions;
|
||||
import org.jclouds.ec2.features.AMIApi;
|
||||
import org.jclouds.ec2.features.AvailabilityZoneAndRegionApi;
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
|
@ -42,6 +41,7 @@ import com.google.common.base.Predicate;
|
|||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||
|
@ -66,9 +66,10 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive
|
|||
assertEquals(template.getImage(), defaultTemplate.getImage());
|
||||
|
||||
Collection<HttpCommand> filteredCommandsInvoked = Collections2.filter(commandsInvoked, new Predicate<HttpCommand>() {
|
||||
private final Collection<Method> ignored = ImmutableSet.of(
|
||||
AvailabilityZoneAndRegionApi.class.getMethod("describeRegions", DescribeRegionsOptions[].class),
|
||||
AvailabilityZoneAndRegionApi.class.getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class));
|
||||
private final Collection<Invokable<?, Object>> ignored = ImmutableSet.of(
|
||||
Invokable.from(AvailabilityZoneAndRegionApi.class.getMethod("describeRegions", DescribeRegionsOptions[].class)),
|
||||
Invokable.from(AvailabilityZoneAndRegionApi.class.getMethod("describeAvailabilityZonesInRegion",
|
||||
String.class, DescribeAvailabilityZonesOptions[].class)));
|
||||
@Override
|
||||
public boolean apply(HttpCommand input) {
|
||||
return !ignored.contains(getInvokerOfRequest(input));
|
||||
|
@ -76,8 +77,8 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive
|
|||
});
|
||||
|
||||
assert filteredCommandsInvoked.size() == 1 : commandsInvoked;
|
||||
assertEquals(getInvokerOfRequestAtIndex(filteredCommandsInvoked, 0), AMIApi.class
|
||||
.getMethod("describeImagesInRegion", String.class, DescribeImagesOptions[].class));
|
||||
assertInvokedCommand(getInvokerOfRequestAtIndex(filteredCommandsInvoked, 0), Invokable.from(AMIApi.class
|
||||
.getMethod("describeImagesInRegion", String.class, DescribeImagesOptions[].class)));
|
||||
assertDescribeImagesOptionsEquals((DescribeImagesOptions[])getArgsForRequestAtIndex(filteredCommandsInvoked, 0).get(1),
|
||||
defaultImageProviderId);
|
||||
|
||||
|
@ -91,4 +92,17 @@ public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLive
|
|||
assertEquals(actual.length, 1);
|
||||
assertEquals(actual[0].getImageIds(), ImmutableSet.of(expectedImageId));
|
||||
}
|
||||
|
||||
protected static void assertInvokedCommand(Invokable<?, ?> actual, Invokable<?, ?> expected) {
|
||||
// Invokables can be constructed by different meanings and be of different types. Since we
|
||||
// only want to verify the "wrapped" types, let's ignore the invokable type and compare the
|
||||
// types of the underlying methods
|
||||
assertEquals(actual.getDeclaringClass(), expected.getDeclaringClass());
|
||||
assertEquals(actual.getName(), expected.getName());
|
||||
assertEquals(actual.getParameters().size(), expected.getParameters().size());
|
||||
for (int i = 0; i < actual.getParameters().size(); i++) {
|
||||
assertEquals(actual.getParameters().get(i).getType(), expected.getParameters().get(i).getType());
|
||||
}
|
||||
assertEquals(actual.getReturnType(), expected.getReturnType());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import javax.net.ssl.HostnameVerifier;
|
|||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import org.jclouds.http.HttpCommand;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.IOExceptionRetryHandler;
|
||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||
|
@ -91,4 +92,11 @@ public class TrackingJavaUrlHttpCommandExecutorService extends JavaUrlHttpComman
|
|||
untrustedSSLContextProvider, proxyForURI);
|
||||
this.commandsInvoked = commandsInvoked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResponse invoke(HttpCommand command) {
|
||||
commandsInvoked.add(command);
|
||||
return super.invoke(command);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class AWSEC2ProviderMetadata extends BaseProviderMetadata {
|
|||
.console(URI.create("https://console.aws.amazon.com/ec2/home"))
|
||||
.defaultProperties(AWSEC2ProviderMetadata.defaultProperties())
|
||||
.linkedServices("aws-ec2", "aws-elb", "aws-cloudwatch", "aws-s3", "aws-simpledb")
|
||||
.iso3166Codes("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "SG", "AU-NSW", "JP-13");
|
||||
.iso3166Codes("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "DE-HE", "SG", "AU-NSW", "JP-13");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -92,7 +92,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
|
|||
template.getOptions().userMetadata(userMetadata);
|
||||
template.getOptions().tags(tags);
|
||||
template.getOptions().as(AWSEC2TemplateOptions.class).enableMonitoring();
|
||||
template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(0.3f);
|
||||
template.getOptions().as(AWSEC2TemplateOptions.class).spotPrice(0.05f);
|
||||
|
||||
String startedId = null;
|
||||
try {
|
||||
|
|
|
@ -52,6 +52,7 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.inject.Module;
|
||||
|
||||
@Test(groups = "live", testName = "AWSEC2TemplateBuilderLiveTest")
|
||||
|
@ -157,7 +158,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
|||
Template defaultTemplate = view.getComputeService().templateBuilder().osFamily(AMZN_LINUX)
|
||||
.imageMatches(EC2ImagePredicates.rootDeviceType(RootDeviceType.INSTANCE_STORE)).build();
|
||||
assert defaultTemplate.getImage().getProviderId().startsWith("ami-") : defaultTemplate;
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2014.09.1");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getVersion(), "pv-2014.09.2");
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(defaultTemplate.getImage().getOperatingSystem().getFamily(), AMZN_LINUX);
|
||||
assertEquals(defaultTemplate.getImage().getUserMetadata().get("rootDeviceType"), "instance-store");
|
||||
|
@ -170,13 +171,13 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
|||
public void testFastestTemplateBuilder() throws IOException {
|
||||
Template fastestTemplate = view.getComputeService().templateBuilder().fastest().osFamily(AMZN_LINUX).build();
|
||||
assert fastestTemplate.getImage().getProviderId().startsWith("ami-") : fastestTemplate;
|
||||
assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.C3_8XLARGE);
|
||||
assertEquals(fastestTemplate.getHardware().getProviderId(), InstanceType.C4_8XLARGE);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getVersion(), "vpc-nat-pv-2014.09.1");
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().is64Bit(), true);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getFamily(), AMZN_LINUX);
|
||||
assertEquals(fastestTemplate.getImage().getUserMetadata().get("rootDeviceType"), "ebs");
|
||||
assertEquals(fastestTemplate.getLocation().getId(), "us-east-1");
|
||||
assertEquals(getCores(fastestTemplate.getHardware()), 32.0d);
|
||||
assertEquals(getCores(fastestTemplate.getHardware()), 36.0d);
|
||||
assertEquals(fastestTemplate.getImage().getOperatingSystem().getArch(), "paravirtual");
|
||||
}
|
||||
|
||||
|
@ -307,11 +308,11 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
|||
private static void assertOnlyOneRegionQueriedForAvailabilityZone(List<HttpCommand> commandsInvoked)
|
||||
throws NoSuchMethodException {
|
||||
assert commandsInvoked.size() == 2 : commandsInvoked;
|
||||
assertEquals(getInvokerOfRequestAtIndex(commandsInvoked, 0),
|
||||
AvailabilityZoneAndRegionApi.class.getMethod("describeRegions", DescribeRegionsOptions[].class));
|
||||
assertEquals(getInvokerOfRequestAtIndex(commandsInvoked, 1),
|
||||
assertInvokedCommand(getInvokerOfRequestAtIndex(commandsInvoked, 0), Invokable.from(
|
||||
AvailabilityZoneAndRegionApi.class.getMethod("describeRegions", DescribeRegionsOptions[].class)));
|
||||
assertInvokedCommand(getInvokerOfRequestAtIndex(commandsInvoked, 1), Invokable.from(
|
||||
AvailabilityZoneAndRegionApi.class.getMethod("describeAvailabilityZonesInRegion", String.class,
|
||||
DescribeAvailabilityZonesOptions[].class));
|
||||
DescribeAvailabilityZonesOptions[].class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -333,7 +334,7 @@ public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
|||
|
||||
@Override
|
||||
protected Set<String> getIso3166Codes() {
|
||||
return ImmutableSet.of("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "SG", "AU-NSW", "JP-13");
|
||||
return ImmutableSet.of("US-VA", "US-CA", "US-OR", "BR-SP", "IE", "DE-HE", "SG", "AU-NSW", "JP-13");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.jclouds.aws.ec2.features;
|
||||
|
||||
import static com.google.common.collect.Iterables.getOnlyElement;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
import static com.google.common.collect.Sets.newTreeSet;
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.jclouds.util.Predicates2.retry;
|
||||
|
@ -25,7 +24,6 @@ import static org.testng.Assert.assertEquals;
|
|||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
|
||||
|
@ -62,8 +60,7 @@ import com.google.inject.Module;
|
|||
*/
|
||||
@Test(groups = "live", singleThreaded = true, testName = "PlacementGroupApiLiveTest")
|
||||
public class PlacementGroupApiLiveTest extends BaseComputeServiceContextLiveTest {
|
||||
ArrayList<String> supportedRegions = newArrayList(Region.US_EAST_1, Region.US_WEST_2, Region.EU_WEST_1,
|
||||
Region.US_WEST_2, Region.AP_NORTHEAST_1, Region.AP_SOUTHEAST_1, Region.AP_SOUTHEAST_2);
|
||||
private final Set<String> supportedRegions = Region.DEFAULT_REGIONS;
|
||||
|
||||
public PlacementGroupApiLiveTest() {
|
||||
provider = "aws-ec2";
|
||||
|
@ -136,10 +133,10 @@ public class PlacementGroupApiLiveTest extends BaseComputeServiceContextLiveTest
|
|||
assertNotNull(allResults);
|
||||
if (allResults.size() >= 1) {
|
||||
PlacementGroup group = allResults.last();
|
||||
SortedSet<PlacementGroup> result = newTreeSet(client.getPlacementGroupApi().get()
|
||||
client.getPlacementGroupApi().get()
|
||||
.describePlacementGroupsInRegionWithFilter(region,
|
||||
ImmutableMultimap.<String, String>builder()
|
||||
.put("invalid-filter", group.getName()).build()));
|
||||
.put("invalid-filter", group.getName()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,9 +144,8 @@ public class SpotInstanceApiLiveTest extends BaseComputeServiceContextLiveTest
|
|||
assert in(
|
||||
ImmutableSet.of("c1.medium", "c1.xlarge", "cc1.4xlarge", "cg1.4xlarge", "cc2.8xlarge", "m1.large",
|
||||
"m1.small", "m1.medium", "m1.xlarge", "m2.2xlarge", "m2.4xlarge", "m2.xlarge", "m3.xlarge",
|
||||
"m3.2xlarge", "t1.micro", "cr1.8xlarge")).apply(
|
||||
spot.getInstanceType()) : spot;
|
||||
|
||||
"m3.2xlarge", "t1.micro", "cr1.8xlarge", "c4.large", "c4.xlarge", "c4.2xlarge", "c4.4xlarge",
|
||||
"c4.8xlarge")).apply(spot.getInstanceType()) : spot;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue