Updated Branches: refs/heads/master 5f524ee6c -> 5f3b8d3fa
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5f3b8d3f/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java deleted file mode 100644 index d7f6663..0000000 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/PlacementGroupClientLiveTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.aws.ec2.services; - -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; -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; - -import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.AWSEC2ApiMetadata; -import org.jclouds.aws.ec2.AWSEC2Client; -import org.jclouds.aws.ec2.domain.PlacementGroup; -import org.jclouds.aws.ec2.domain.PlacementGroup.State; -import org.jclouds.aws.ec2.predicates.PlacementGroupAvailable; -import org.jclouds.aws.ec2.predicates.PlacementGroupDeleted; -import org.jclouds.compute.RunNodesException; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Template; -import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.compute.predicates.NodePredicates; -import org.jclouds.ec2.compute.domain.EC2HardwareBuilder; -import org.jclouds.ec2.domain.InstanceType; -import org.jclouds.scriptbuilder.domain.Statements; -import org.jclouds.scriptbuilder.statements.java.InstallJDK; -import org.jclouds.scriptbuilder.statements.login.AdminAccess; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.base.Throwables; -import com.google.inject.Module; - -/** - * Tests behavior of {@code PlacementGroupClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true, testName = "PlacementGroupClientLiveTest") -public class PlacementGroupClientLiveTest extends BaseComputeServiceContextLiveTest { - ArrayList<String> supportedRegions = newArrayList(Region.US_EAST_1, Region.US_WEST_2, Region.EU_WEST_1); - - public PlacementGroupClientLiveTest() { - provider = "aws-ec2"; - } - - private AWSEC2Client client; - private Predicate<PlacementGroup> availableTester; - private Predicate<PlacementGroup> deletedTester; - private PlacementGroup group; - - @Override - @BeforeClass(groups = { "integration", "live" }) - public void setupContext() { - super.setupContext(); - client = view.unwrap(AWSEC2ApiMetadata.CONTEXT_TOKEN).getApi(); - availableTester = retry(new PlacementGroupAvailable(client), 60, 1, SECONDS); - deletedTester = retry(new PlacementGroupDeleted(client), 60, 1, SECONDS); - } - - @Test - void testDescribe() { - for (String region : supportedRegions) { - SortedSet<PlacementGroup> allResults = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region)); - assertNotNull(allResults); - if (allResults.size() >= 1) { - PlacementGroup group = allResults.last(); - SortedSet<PlacementGroup> result = newTreeSet(client.getPlacementGroupServices() - .describePlacementGroupsInRegion(region, group.getName())); - assertNotNull(result); - PlacementGroup compare = result.last(); - assertEquals(compare, group); - } - } - - for (String region : client.getAvailabilityZoneAndRegionServices().describeRegions().keySet()) { - if (!supportedRegions.contains(region)) - try { - client.getPlacementGroupServices().describePlacementGroupsInRegion(region); - fail("should be unsupported for region: " + region); - } catch (UnsupportedOperationException e) { - } - } - } - - @Test - void testCreatePlacementGroup() { - String groupName = PREFIX + "1"; - for (String region : supportedRegions) { - - client.getPlacementGroupServices().deletePlacementGroupInRegion(region, groupName); - client.getPlacementGroupServices().createPlacementGroupInRegion(region, groupName); - - verifyPlacementGroup(region, groupName); - } - } - - private void verifyPlacementGroup(String region, String groupName) { - assert availableTester.apply(new PlacementGroup(region, groupName, "cluster", State.PENDING)) : group; - Set<PlacementGroup> oneResult = client.getPlacementGroupServices().describePlacementGroupsInRegion(region, - groupName); - assertNotNull(oneResult); - assertEquals(oneResult.size(), 1); - group = oneResult.iterator().next(); - assertEquals(group.getName(), groupName); - assertEquals(group.getStrategy(), "cluster"); - assert availableTester.apply(group) : group; - } - - public void testStartCCInstance() throws Exception { - - Template template = view.getComputeService().templateBuilder() - .fromHardware(EC2HardwareBuilder.cc2_8xlarge().build()).osFamily(OsFamily.AMZN_LINUX).build(); - assert template != null : "The returned template was null, but it should have a value."; - assertEquals(template.getHardware().getProviderId(), InstanceType.CC2_8XLARGE); - assertEquals(template.getImage().getUserMetadata().get("rootDeviceType"), "ebs"); - assertEquals(template.getImage().getUserMetadata().get("virtualizationType"), "hvm"); - assertEquals(template.getImage().getUserMetadata().get("hypervisor"), "xen"); - - template.getOptions().runScript(Statements.newStatementList(AdminAccess.standard(), InstallJDK.fromOpenJDK())); - - String group = PREFIX + "cccluster"; - view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); - // TODO make this not lookup an explicit region - client.getPlacementGroupServices().deletePlacementGroupInRegion(null, "jclouds#" + group + "#us-east-1"); - - try { - Set<? extends NodeMetadata> nodes = view.getComputeService().createNodesInGroup(group, 1, template); - NodeMetadata node = getOnlyElement(nodes); - - getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(null, - node.getProviderId()))); - - } catch (RunNodesException e) { - System.err.println(e.getNodeErrors().keySet()); - Throwables.propagate(e); - } finally { - view.getComputeService().destroyNodesMatching(NodePredicates.inGroup(group)); - } - } - - public static final String PREFIX = System.getProperty("user.name") + "ec2"; - - @Override - @AfterClass(groups = { "integration", "live" }) - protected void tearDownContext() { - if (group != null) { - client.getPlacementGroupServices().deletePlacementGroupInRegion(group.getRegion(), group.getName()); - assert deletedTester.apply(group) : group; - } - super.tearDownContext(); - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5f3b8d3f/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java deleted file mode 100644 index ec7751a..0000000 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceAsyncClientTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.aws.ec2.services; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; -import java.util.Date; - -import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.aws.ec2.options.DescribeSpotPriceHistoryOptions; -import org.jclouds.aws.ec2.xml.DescribeSpotPriceHistoryResponseHandler; -import org.jclouds.http.functions.ParseSax; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.Lists; -import com.google.common.reflect.Invokable; -/** - * Tests behavior of {@code SpotInstanceAsyncClient} - * - * @author Adrian Cole - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "SpotInstanceAsyncClientTest") -public class SpotInstanceAsyncClientTest extends BaseAWSEC2AsyncClientTest<SpotInstanceAsyncClient> { - - public void testCancelSpotInstanceRequests() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(SpotInstanceAsyncClient.class, "cancelSpotInstanceRequestsInRegion", String.class, - String[].class); - GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "id")); - - assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, "Action=CancelSpotInstanceRequests&SpotInstanceRequestId.1=id", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testDescribeSpotPriceHistory() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(SpotInstanceAsyncClient.class, "describeSpotPriceHistoryInRegion", String.class, - DescribeSpotPriceHistoryOptions[].class); - GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList((String) null)); - - assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals(request, "Action=DescribeSpotPriceHistory", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, DescribeSpotPriceHistoryResponseHandler.class); - assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); - - checkFilters(request); - } - - Date from = new Date(12345678910l); - Date to = new Date(1234567891011l); - - public void testDescribeSpotPriceHistoryArgs() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(SpotInstanceAsyncClient.class, "describeSpotPriceHistoryInRegion", String.class, - DescribeSpotPriceHistoryOptions[].class); - GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, DescribeSpotPriceHistoryOptions.Builder.from(from) - .to(to).productDescription("description").instanceType("m1.small"))); - - assertRequestLineEquals(request, "POST https://ec2.us-east-1.amazonaws.com/ HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Host: ec2.us-east-1.amazonaws.com\n"); - assertPayloadEquals( - request, - "Action=DescribeSpotPriceHistory&StartTime=1970-05-23T21%3A21%3A18.910Z&EndTime=2009-02-13T23%3A31%3A31.011Z&ProductDescription=description&InstanceType.1=m1.small", - "application/x-www-form-urlencoded", false); - - assertResponseParserClassEquals(method, request, ParseSax.class); - assertSaxResponseParserClassEquals(method, DescribeSpotPriceHistoryResponseHandler.class); - assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); - - checkFilters(request); - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5f3b8d3f/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java ---------------------------------------------------------------------- diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java deleted file mode 100644 index 3def6f6..0000000 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/services/SpotInstanceClientLiveTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.aws.ec2.services; - -import static com.google.common.base.Predicates.in; -import static com.google.common.collect.Iterables.getOnlyElement; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.aws.ec2.options.DescribeSpotPriceHistoryOptions.Builder.from; -import static org.jclouds.aws.ec2.options.RequestSpotInstancesOptions.Builder.launchGroup; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.Date; -import java.util.Set; -import java.util.SortedSet; -import java.util.concurrent.TimeUnit; - -import org.jclouds.aws.domain.Region; -import org.jclouds.aws.ec2.AWSEC2ApiMetadata; -import org.jclouds.aws.ec2.AWSEC2Client; -import org.jclouds.aws.ec2.domain.AWSRunningInstance; -import org.jclouds.aws.ec2.domain.LaunchSpecification; -import org.jclouds.aws.ec2.domain.Spot; -import org.jclouds.aws.ec2.domain.SpotInstanceRequest; -import org.jclouds.aws.ec2.predicates.SpotInstanceRequestActive; -import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.ec2.domain.InstanceType; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSortedSet; - -/** - * Tests behavior of {@code SpotInstanceClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true) -public class SpotInstanceClientLiveTest extends BaseComputeServiceContextLiveTest { - public SpotInstanceClientLiveTest() { - provider = "aws-ec2"; - } - - private static final int SPOT_DELAY_SECONDS = 600; - private AWSEC2Client client; - private Predicate<SpotInstanceRequest> activeTester; - private Set<SpotInstanceRequest> requests; - private AWSRunningInstance instance; - private long start; - - @Override - @BeforeClass(groups = { "integration", "live" }) - public void setupContext() { - super.setupContext(); - client = view.unwrap(AWSEC2ApiMetadata.CONTEXT_TOKEN).getApi(); - activeTester = retry(new SpotInstanceRequestActive(client), SPOT_DELAY_SECONDS, 1, 1, SECONDS); - } - - @Test - void testDescribeSpotRequestsInRegion() { - for (String region : Region.DEFAULT_REGIONS) { - SortedSet<SpotInstanceRequest> allResults = ImmutableSortedSet.copyOf(client.getSpotInstanceServices() - .describeSpotInstanceRequestsInRegion(region)); - assertNotNull(allResults); - if (allResults.size() >= 1) { - SpotInstanceRequest request = allResults.last(); - SortedSet<SpotInstanceRequest> result = ImmutableSortedSet.copyOf(client.getSpotInstanceServices() - .describeSpotInstanceRequestsInRegion(region, request.getId())); - assertNotNull(result); - SpotInstanceRequest compare = result.last(); - assertEquals(compare, request); - } - } - - } - - @Test - void testDescribeSpotPriceHistoryInRegion() { - for (String region : Region.DEFAULT_REGIONS) { - Set<Spot> spots = client.getSpotInstanceServices().describeSpotPriceHistoryInRegion(region, from(new Date())); - assertNotNull(spots); - assert spots.size() > 0; - for (Spot spot : spots) { - assert spot.getSpotPrice() > 0 : spots; - assertEquals(spot.getRegion(), region); - assert in( - ImmutableSet.of("Linux/UNIX", "Linux/UNIX (Amazon VPC)", "SUSE Linux", "SUSE Linux (Amazon VPC)", - "Windows", "Windows (Amazon VPC)")).apply(spot.getProductDescription()) : spot; - 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")).apply( - spot.getInstanceType()) : spot; - - } - } - - } - - @Test(enabled = true) - void testCreateSpotInstance() { - String launchGroup = PREFIX + "1"; - for (String region : Region.DEFAULT_REGIONS) - for (SpotInstanceRequest request : client.getSpotInstanceServices().describeSpotInstanceRequestsInRegion( - region)) - if (launchGroup.equals(request.getLaunchGroup())) - client.getSpotInstanceServices().cancelSpotInstanceRequestsInRegion(region, request.getId()); - - start = System.currentTimeMillis(); - - requests = client.getSpotInstanceServices().requestSpotInstancesInRegion( - "sa-east-1", - 0.09f, - 1, - LaunchSpecification.builder().imageId("ami-3e3be423").instanceType(InstanceType.M1_SMALL).build(), - launchGroup(launchGroup).availabilityZoneGroup(launchGroup).validFrom( - new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(2))).validUntil( - new Date(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(SPOT_DELAY_SECONDS)))); - assertNotNull(requests); - - for (SpotInstanceRequest request : requests) - verifySpotInstance(request); - } - - private void verifySpotInstance(SpotInstanceRequest request) { - SpotInstanceRequest spot = refresh(request); - assertNotNull(spot); - assertEquals(spot, request); - assert activeTester.apply(request) : refresh(request); - System.out.println(System.currentTimeMillis() - start); - spot = refresh(request); - assert spot.getInstanceId() != null : spot; - instance = getOnlyElement(getOnlyElement(client.getInstanceServices().describeInstancesInRegion(spot.getRegion(), - spot.getInstanceId()))); - assertEquals(instance.getSpotInstanceRequestId(), spot.getId()); - } - - public SpotInstanceRequest refresh(SpotInstanceRequest request) { - return getOnlyElement(client.getSpotInstanceServices().describeSpotInstanceRequestsInRegion(request.getRegion(), - request.getId())); - } - - public static final String PREFIX = System.getProperty("user.name") + "ec2"; - - @Override - @AfterClass(groups = { "integration", "live" }) - protected void tearDownContext() { - if (requests != null) { - for (SpotInstanceRequest request : requests) - client.getSpotInstanceServices().cancelSpotInstanceRequestsInRegion(request.getRegion(), request.getId()); - // assert deletedTester.apply(request) : request; - } - if (instance != null) { - client.getInstanceServices().terminateInstancesInRegion(instance.getRegion(), instance.getId()); - } - super.tearDownContext(); - } -}
