mirror of https://github.com/apache/jclouds.git
Issue 763: added EC2TemplateBuilderLiveTest to assert httpCommands don't fetch all images
This commit is contained in:
parent
60af7f454f
commit
f140688077
|
@ -0,0 +1,79 @@
|
||||||
|
package org.jclouds.ec2.compute;
|
||||||
|
|
||||||
|
import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.getJavaArgsForRequestAtIndex;
|
||||||
|
import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.getJavaMethodForRequest;
|
||||||
|
import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.getJavaMethodForRequestAtIndex;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
||||||
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.ec2.options.DescribeAvailabilityZonesOptions;
|
||||||
|
import org.jclouds.ec2.options.DescribeImagesOptions;
|
||||||
|
import org.jclouds.ec2.options.DescribeRegionsOptions;
|
||||||
|
import org.jclouds.ec2.services.AMIAsyncClient;
|
||||||
|
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
|
||||||
|
import org.jclouds.http.HttpCommand;
|
||||||
|
import org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService;
|
||||||
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
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.inject.Module;
|
||||||
|
|
||||||
|
public abstract class EC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTemplateBuilderCanUseImageIdWithoutFetchingAllImages() throws Exception {
|
||||||
|
Template defaultTemplate = context.getComputeService().templateBuilder().build();
|
||||||
|
String defaultImageId = defaultTemplate.getImage().getId();
|
||||||
|
String defaultImageProviderId = defaultTemplate.getImage().getProviderId();
|
||||||
|
|
||||||
|
ComputeServiceContext context = null;
|
||||||
|
try {
|
||||||
|
// Track http commands
|
||||||
|
final List<HttpCommand> commandsInvoked = Lists.newArrayList();
|
||||||
|
context = new ComputeServiceContextFactory(setupRestProperties()).createContext(provider,
|
||||||
|
ImmutableSet.<Module> of(new Log4JLoggingModule(),
|
||||||
|
TrackingJavaUrlHttpCommandExecutorService.newTrackingModule(commandsInvoked)),
|
||||||
|
setupProperties());
|
||||||
|
|
||||||
|
Template template = context.getComputeService().templateBuilder().imageId(defaultImageId)
|
||||||
|
.build();
|
||||||
|
assertEquals(template.getImage(), defaultTemplate.getImage());
|
||||||
|
|
||||||
|
Collection<HttpCommand> filteredCommandsInvoked = Collections2.filter(commandsInvoked, new Predicate<HttpCommand>() {
|
||||||
|
private final Collection<Method> ignored = ImmutableSet.of(
|
||||||
|
AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeRegions", DescribeRegionsOptions[].class),
|
||||||
|
AvailabilityZoneAndRegionAsyncClient.class.getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class));
|
||||||
|
@Override
|
||||||
|
public boolean apply(HttpCommand input) {
|
||||||
|
return !ignored.contains(getJavaMethodForRequest(input));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert filteredCommandsInvoked.size() == 1 : commandsInvoked;
|
||||||
|
assertEquals(getJavaMethodForRequestAtIndex(filteredCommandsInvoked, 0), AMIAsyncClient.class
|
||||||
|
.getMethod("describeImagesInRegion", String.class, DescribeImagesOptions[].class));
|
||||||
|
assertDescribeImagesOptionsEquals((DescribeImagesOptions[])getJavaArgsForRequestAtIndex(filteredCommandsInvoked, 0).get(1),
|
||||||
|
defaultImageProviderId);
|
||||||
|
|
||||||
|
} finally {
|
||||||
|
if (context != null)
|
||||||
|
context.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertDescribeImagesOptionsEquals(DescribeImagesOptions[] actual, String expectedImageId) {
|
||||||
|
assertEquals(actual.length, 1);
|
||||||
|
assertEquals(actual[0].getImageIds(), ImmutableSet.of(expectedImageId));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.jclouds.http.internal;
|
package org.jclouds.http.internal;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
@ -17,8 +19,10 @@ import org.jclouds.http.HttpUtils;
|
||||||
import org.jclouds.http.IOExceptionRetryHandler;
|
import org.jclouds.http.IOExceptionRetryHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
import org.jclouds.http.handlers.DelegatingErrorHandler;
|
||||||
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
import org.jclouds.http.handlers.DelegatingRetryHandler;
|
||||||
|
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||||
|
|
||||||
import com.google.common.base.Supplier;
|
import com.google.common.base.Supplier;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.AbstractModule;
|
import com.google.inject.AbstractModule;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
@ -50,6 +54,19 @@ public class TrackingJavaUrlHttpCommandExecutorService extends JavaUrlHttpComman
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Method getJavaMethodForRequestAtIndex(final Collection<HttpCommand> commandsInvoked, int index) {
|
||||||
|
return getJavaMethodForRequest(Iterables.get(commandsInvoked, index));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Method getJavaMethodForRequest(HttpCommand commandInvoked) {
|
||||||
|
return GeneratedHttpRequest.class.cast(commandInvoked.getCurrentRequest()).getJavaMethod();
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public static List<Object> getJavaArgsForRequestAtIndex(final Collection<HttpCommand> commandsInvoked, int index) {
|
||||||
|
return GeneratedHttpRequest.class.cast(Iterables.get(commandsInvoked, index).getCurrentRequest()).getArgs();
|
||||||
|
}
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TrackingJavaUrlHttpCommandExecutorService(HttpUtils utils,
|
public TrackingJavaUrlHttpCommandExecutorService(HttpUtils utils,
|
||||||
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
@Named(Constants.PROPERTY_IO_WORKER_THREADS) ExecutorService ioWorkerExecutor,
|
||||||
|
|
|
@ -19,24 +19,23 @@
|
||||||
package org.jclouds.aws.ec2.compute;
|
package org.jclouds.aws.ec2.compute;
|
||||||
|
|
||||||
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
|
||||||
|
import static org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.getJavaMethodForRequestAtIndex;
|
||||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
import org.jclouds.aws.domain.Region;
|
import org.jclouds.aws.domain.Region;
|
||||||
import org.jclouds.aws.ec2.reference.AWSEC2Constants;
|
import org.jclouds.aws.ec2.reference.AWSEC2Constants;
|
||||||
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
|
||||||
import org.jclouds.compute.ComputeServiceContext;
|
import org.jclouds.compute.ComputeServiceContext;
|
||||||
import org.jclouds.compute.ComputeServiceContextFactory;
|
import org.jclouds.compute.ComputeServiceContextFactory;
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
|
import org.jclouds.ec2.compute.EC2TemplateBuilderLiveTest;
|
||||||
import org.jclouds.ec2.compute.predicates.EC2ImagePredicates;
|
import org.jclouds.ec2.compute.predicates.EC2ImagePredicates;
|
||||||
import org.jclouds.ec2.domain.InstanceType;
|
import org.jclouds.ec2.domain.InstanceType;
|
||||||
import org.jclouds.ec2.domain.RootDeviceType;
|
import org.jclouds.ec2.domain.RootDeviceType;
|
||||||
|
@ -45,26 +44,22 @@ import org.jclouds.ec2.options.DescribeRegionsOptions;
|
||||||
import org.jclouds.ec2.reference.EC2Constants;
|
import org.jclouds.ec2.reference.EC2Constants;
|
||||||
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
|
import org.jclouds.ec2.services.AvailabilityZoneAndRegionAsyncClient;
|
||||||
import org.jclouds.http.HttpCommand;
|
import org.jclouds.http.HttpCommand;
|
||||||
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
|
|
||||||
import org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService;
|
import org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
import com.google.inject.TypeLiteral;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live")
|
@Test(groups = "live")
|
||||||
public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
public class AWSEC2TemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
||||||
|
|
||||||
public AWSEC2TemplateBuilderLiveTest() {
|
public AWSEC2TemplateBuilderLiveTest() {
|
||||||
provider = "aws-ec2";
|
provider = "aws-ec2";
|
||||||
|
@ -357,10 +352,6 @@ public class AWSEC2TemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
||||||
.getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class));
|
.getMethod("describeAvailabilityZonesInRegion", String.class, DescribeAvailabilityZonesOptions[].class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Method getJavaMethodForRequestAtIndex(final List<HttpCommand> commandsInvoked, int index) {
|
|
||||||
return GeneratedHttpRequest.class.cast(commandsInvoked.get(index).getCurrentRequest()).getJavaMethod();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTemplateBuilderCanUseImageIdFromNonDefaultOwner() {
|
public void testTemplateBuilderCanUseImageIdFromNonDefaultOwner() {
|
||||||
// This is the id of a public image, not owned by one of the four default owners
|
// This is the id of a public image, not owned by one of the four default owners
|
||||||
|
|
|
@ -25,11 +25,11 @@ import java.io.IOException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.aws.util.AWSUtils;
|
import org.jclouds.aws.util.AWSUtils;
|
||||||
import org.jclouds.compute.BaseTemplateBuilderLiveTest;
|
|
||||||
import org.jclouds.compute.domain.OsFamily;
|
import org.jclouds.compute.domain.OsFamily;
|
||||||
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
import org.jclouds.compute.domain.OsFamilyVersion64Bit;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.domain.LocationScope;
|
import org.jclouds.domain.LocationScope;
|
||||||
|
import org.jclouds.ec2.compute.EC2TemplateBuilderLiveTest;
|
||||||
import org.jclouds.ec2.compute.util.EC2ComputeUtils;
|
import org.jclouds.ec2.compute.util.EC2ComputeUtils;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Test(groups = "live")
|
@Test(groups = "live")
|
||||||
public class EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest extends BaseTemplateBuilderLiveTest {
|
public class EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest extends EC2TemplateBuilderLiveTest {
|
||||||
|
|
||||||
public EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest() {
|
public EucalyptusPartnerCloudEucalyptusTemplateBuilderLiveTest() {
|
||||||
provider = "eucalyptus-partnercloud-ec2";
|
provider = "eucalyptus-partnercloud-ec2";
|
||||||
|
|
Loading…
Reference in New Issue