mirror of https://github.com/apache/jclouds.git
Improved live tests for Load Balancing.
This commit is contained in:
parent
290543d93e
commit
1bd75d7c59
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jclouds.googlecomputeengine.features;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.Fallbacks.EmptyPagedIterableOnNotFoundOr404;
|
||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
|
@ -48,7 +50,6 @@ import javax.ws.rs.PathParam;
|
|||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
|
||||
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_READONLY_SCOPE;
|
||||
import static org.jclouds.googlecomputeengine.GoogleComputeEngineConstants.COMPUTE_SCOPE;
|
||||
|
||||
|
@ -148,5 +149,5 @@ public interface ForwardingRuleApi {
|
|||
@MapBinder(BindToJsonPayload.class)
|
||||
@Nullable
|
||||
Operation setTarget(@PathParam("forwardingRule") String forwardingRule,
|
||||
@PayloadParam("target") String target);
|
||||
@PayloadParam("target") URI target);
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public interface TargetPoolApi {
|
|||
* Creates a TargetPool resource in the specified project and region using the data included in the request.
|
||||
*
|
||||
* @param targetPoolName the name of the targetPool.
|
||||
* @param the options of the TargetPool to create.
|
||||
* @param the options of the TargetPool to create.
|
||||
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
|
||||
* you, and look for the status field.
|
||||
*/
|
||||
|
@ -204,13 +204,17 @@ public interface TargetPoolApi {
|
|||
@MapBinder(TargetPoolChangeHealthChecksBinder.class)
|
||||
@Nullable
|
||||
Operation removeHealthCheck(@PathParam("targetPool") String targetPool, @PayloadParam("healthChecks") Set<URI> healthChecks);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Changes backup pool configurations.
|
||||
*
|
||||
* @param targetPool the name of the target pool.
|
||||
* @param target the URL of target pool for which you want to use as backup.
|
||||
* WARNING: failoverRatio and BackupPool must either both be set or not set. This method
|
||||
* is only for updating the backup pool on a Target Pool that already has a
|
||||
* failoverRatio.
|
||||
* @see <a href = "https://cloud.google.com/compute/docs/reference/latest/targetPools/setBackup"/>
|
||||
*
|
||||
* @return an Operation resource. To check on the status of an operation, poll the Operations resource returned to
|
||||
* you, and look for the status field.
|
||||
|
@ -222,7 +226,7 @@ public interface TargetPoolApi {
|
|||
@MapBinder(BindToJsonPayload.class)
|
||||
@Nullable
|
||||
Operation setBackup(@PathParam("targetPool") String targetPool, @PayloadParam("target") URI target);
|
||||
|
||||
|
||||
/**
|
||||
* Changes backup pool configurations.
|
||||
*
|
||||
|
|
|
@ -187,7 +187,8 @@ public class ForwardingRuleApiExpectTest extends BaseGoogleComputeEngineApiExpec
|
|||
ForwardingRuleApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE),
|
||||
TOKEN_RESPONSE, setTarget, setTargetResponse).getForwardingRuleApi("myproject", "us-central1");
|
||||
|
||||
String newTarget = "https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/targetPools/test-target-pool";
|
||||
URI newTarget = URI.create("https://www.googleapis.com/compute/v1/projects/"
|
||||
+ "myproject/regions/europe-west1/targetPools/test-target-pool");
|
||||
assertEquals(api.setTarget(ruleName, newTarget), new ParseRegionOperationTest().expected());
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
package org.jclouds.googlecomputeengine.features;
|
||||
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.googlecomputeengine.domain.Address;
|
||||
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
|
||||
import org.jclouds.googlecomputeengine.domain.TargetPool;
|
||||
import org.jclouds.googlecomputeengine.domain.ForwardingRule.IPProtocolOption;
|
||||
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
|
||||
import org.jclouds.googlecomputeengine.options.ForwardingRuleCreationOptions;
|
||||
import org.jclouds.googlecomputeengine.options.ListOptions;
|
||||
|
@ -29,13 +31,19 @@ import org.testng.annotations.Test;
|
|||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static com.google.common.base.Optional.fromNullable;
|
||||
|
||||
public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
private static final String FORWARDING_RULE_NAME = "forwarding-rule-api-live-test";
|
||||
private static final String TARGETPOOL_NAME = "forwarding-rule-api-live-test-targetpool";
|
||||
private static final String TARGETPOOL_NAME_NEW = "forwarding-rule-api-live-test-new-targetpool";
|
||||
private static final String DESCRIPTION = "Forwarding rule api live test forwarding rule.";
|
||||
private static final String ADDRESS_NAME = "forwarding-rule-api-address";
|
||||
private static final int TIME_WAIT = 30;
|
||||
private TargetPool targetPool;
|
||||
private TargetPool newTargetPool;
|
||||
private Address address;
|
||||
|
||||
/**
|
||||
* The API under test
|
||||
|
@ -49,21 +57,36 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
|||
return api.getTargetPoolApi(userProject.get(), DEFAULT_REGION_NAME);
|
||||
}
|
||||
|
||||
private AddressApi addressApi(){
|
||||
return api.getAddressApi(userProject.get());
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public void init() {
|
||||
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions();
|
||||
assertRegionOperationDoneSucessfully(targetPoolApi().create(TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
|
||||
targetPool = targetPoolApi().get(TARGETPOOL_NAME);
|
||||
|
||||
assertRegionOperationDoneSucessfully(targetPoolApi().create(TARGETPOOL_NAME_NEW, targetPoolCreationOptions), TIME_WAIT);
|
||||
newTargetPool = targetPoolApi().get(TARGETPOOL_NAME_NEW);
|
||||
|
||||
assertRegionOperationDoneSucessfully(addressApi().createInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT);
|
||||
address = addressApi().getInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void tearDown() {
|
||||
assertRegionOperationDoneSucessfully(targetPoolApi().delete(TARGETPOOL_NAME), TIME_WAIT);
|
||||
assertRegionOperationDoneSucessfully(targetPoolApi().delete(TARGETPOOL_NAME_NEW), TIME_WAIT);
|
||||
assertRegionOperationDoneSucessfully(addressApi().deleteInRegion(DEFAULT_REGION_NAME, ADDRESS_NAME), TIME_WAIT);
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
public void testInsertForwardingRule() {
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
|
||||
.description(DESCRIPTION)
|
||||
.ipAddress(address.getAddress())
|
||||
.ipProtocol(IPProtocolOption.TCP)
|
||||
.target(targetPool.getSelfLink());
|
||||
assertRegionOperationDoneSucessfully(api().create(FORWARDING_RULE_NAME, forwardingRuleCreationOptions), TIME_WAIT);
|
||||
}
|
||||
|
@ -73,9 +96,22 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
|||
ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
|
||||
assertNotNull(forwardingRule);
|
||||
assertEquals(forwardingRule.getName(), FORWARDING_RULE_NAME);
|
||||
assertEquals(forwardingRule.getDescription(), fromNullable(DESCRIPTION));
|
||||
assertEquals(forwardingRule.getIpAddress(), fromNullable(address.getAddress()));
|
||||
assertEquals(forwardingRule.getIpProtocol(), fromNullable(IPProtocolOption.TCP));
|
||||
assertEquals(forwardingRule.getTarget(), targetPool.getSelfLink());
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testGetForwardingRule")
|
||||
public void testSetTargetForwardingRule(){
|
||||
assertRegionOperationDoneSucessfully(api().setTarget(FORWARDING_RULE_NAME, newTargetPool.getSelfLink()), TIME_WAIT);
|
||||
ForwardingRule forwardingRule = api().get(FORWARDING_RULE_NAME);
|
||||
assertNotNull(forwardingRule);
|
||||
assertEquals(forwardingRule.getName(), FORWARDING_RULE_NAME);
|
||||
assertEquals(forwardingRule.getTarget(), newTargetPool.getSelfLink());
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertForwardingRule")
|
||||
public void testListForwardingRule() {
|
||||
|
||||
IterableWithMarker<ForwardingRule> forwardingRule = api().list(new ListOptions.Builder()
|
||||
|
@ -83,7 +119,7 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
|||
assertEquals(forwardingRule.toList().size(), 1);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testListForwardingRule")
|
||||
@Test(groups = "live", dependsOnMethods = {"testListForwardingRule", "testSetTargetForwardingRule"}, alwaysRun = true)
|
||||
public void testDeleteForwardingRule() {
|
||||
assertRegionOperationDoneSucessfully(api().delete(FORWARDING_RULE_NAME), TIME_WAIT);
|
||||
}
|
||||
|
|
|
@ -19,24 +19,38 @@ package org.jclouds.googlecomputeengine.features;
|
|||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
|
||||
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
|
||||
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
|
||||
import org.jclouds.googlecomputeengine.options.ListOptions;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static com.google.common.base.Optional.fromNullable;
|
||||
|
||||
public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
private static final String HTTP_HEALTH_CHECK_NAME = "http-health-check-api-live-test";
|
||||
private static final int TIME_WAIT = 60;
|
||||
|
||||
private static final int OFFSET = 2;
|
||||
|
||||
private HttpHealthCheckCreationOptions options;
|
||||
|
||||
private HttpHealthCheckApi api() {
|
||||
return api.getHttpHealthCheckApi(userProject.get());
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
public void testInsertHttpHealthCheck() {
|
||||
assertGlobalOperationDoneSucessfully(api().insert(HTTP_HEALTH_CHECK_NAME), TIME_WAIT);
|
||||
options = new HttpHealthCheckCreationOptions()
|
||||
.port(56)
|
||||
.checkIntervalSec(40)
|
||||
.timeoutSec(40)
|
||||
.healthyThreshold(30)
|
||||
.unhealthyThreshold(15)
|
||||
.description("A First Health Check!");
|
||||
assertGlobalOperationDoneSucessfully(api().insert(HTTP_HEALTH_CHECK_NAME, options), TIME_WAIT);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
|
||||
|
@ -44,6 +58,12 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
|
|||
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
|
||||
assertNotNull(httpHealthCheck);
|
||||
assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
|
||||
assertEquals(httpHealthCheck.getPort(), fromNullable(options.getPort()));
|
||||
assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(options.getCheckIntervalSec()));
|
||||
assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(options.getTimeoutSec()));
|
||||
assertEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
|
||||
assertEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
|
||||
assertEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertHttpHealthCheck")
|
||||
|
@ -53,7 +73,46 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe
|
|||
assertEquals(httpHealthCheck.toList().size(), 1);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testListHttpHealthCheck", "testGetHttpHealthCheck"})
|
||||
@Test(groups = "live", dependsOnMethods = "testGetHttpHealthCheck")
|
||||
public void testPatchHttpHealthCheck() {
|
||||
HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions()
|
||||
.port(options.getPort() + OFFSET)
|
||||
.checkIntervalSec(options.getCheckIntervalSec() + OFFSET)
|
||||
.timeoutSec(options.getTimeoutSec() + OFFSET);
|
||||
assertGlobalOperationDoneSucessfully(api().patch(HTTP_HEALTH_CHECK_NAME, newOptions), TIME_WAIT);
|
||||
|
||||
// Check changes happened and others unchanged.
|
||||
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
|
||||
assertNotNull(httpHealthCheck);
|
||||
assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
|
||||
assertEquals(httpHealthCheck.getPort(), fromNullable(newOptions.getPort()));
|
||||
assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(newOptions.getCheckIntervalSec()));
|
||||
assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(newOptions.getTimeoutSec()));
|
||||
assertEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
|
||||
assertEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
|
||||
assertEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testPatchHttpHealthCheck")
|
||||
public void testUpdateHttpHealthCheck() {
|
||||
HttpHealthCheckCreationOptions newOptions = new HttpHealthCheckCreationOptions()
|
||||
.checkIntervalSec(options.getCheckIntervalSec() - OFFSET)
|
||||
.timeoutSec(options.getTimeoutSec() - OFFSET);
|
||||
assertGlobalOperationDoneSucessfully(api().update(HTTP_HEALTH_CHECK_NAME, newOptions), TIME_WAIT);
|
||||
|
||||
// Check changes happened.
|
||||
HttpHealthCheck httpHealthCheck = api().get(HTTP_HEALTH_CHECK_NAME);
|
||||
assertNotNull(httpHealthCheck);
|
||||
assertEquals(httpHealthCheck.getName(), HTTP_HEALTH_CHECK_NAME);
|
||||
assertEquals(httpHealthCheck.getCheckIntervalSec(), fromNullable(newOptions.getCheckIntervalSec()));
|
||||
assertEquals(httpHealthCheck.getTimeoutSec(), fromNullable(newOptions.getTimeoutSec()));
|
||||
// Update overwrites unspecified parameters to their defaults.
|
||||
assertNotEquals(httpHealthCheck.getHealthyThreshold(), fromNullable(options.getHealthyThreshold()));
|
||||
assertNotEquals(httpHealthCheck.getUnhealthyThreshold(), fromNullable(options.getUnhealthyThreshold()));
|
||||
assertNotEquals(httpHealthCheck.getDescription(), fromNullable(options.getDescription()));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testListHttpHealthCheck", "testUpdateHttpHealthCheck"})
|
||||
public void testDeleteHttpHealthCheck() {
|
||||
assertGlobalOperationDoneSucessfully(api().delete(HTTP_HEALTH_CHECK_NAME), TIME_WAIT);
|
||||
}
|
||||
|
|
|
@ -16,56 +16,250 @@
|
|||
*/
|
||||
package org.jclouds.googlecomputeengine.features;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.collect.IterableWithMarker;
|
||||
import org.jclouds.googlecomputeengine.domain.HttpHealthCheck;
|
||||
import org.jclouds.googlecomputeengine.domain.Image;
|
||||
import org.jclouds.googlecomputeengine.domain.Instance;
|
||||
import org.jclouds.googlecomputeengine.domain.InstanceTemplate;
|
||||
import org.jclouds.googlecomputeengine.domain.TargetPool;
|
||||
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
|
||||
import org.jclouds.googlecomputeengine.options.DiskCreationOptions;
|
||||
import org.jclouds.googlecomputeengine.options.HttpHealthCheckCreationOptions;
|
||||
import org.jclouds.googlecomputeengine.options.ListOptions;
|
||||
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions;
|
||||
import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static com.google.common.base.Optional.fromNullable;
|
||||
|
||||
public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
||||
|
||||
private static final String TARGETPOOL_NAME = "targetpool-api-live-test";
|
||||
private static final String BACKUP_TARGETPOOL_NAME = "targetpool-api-live-test-backup";
|
||||
private static final String TARGETPOOL_NAME = "targetpool-api-live-test-primary";
|
||||
private static final String THIRD_TARGETPOOL_NAME = "targetpool-apo-live-test-third";
|
||||
private static final int TIME_WAIT = 30;
|
||||
private static final String DESCRIPTION = "A New TargetPool!";
|
||||
private static final String DESCRIPTION_BACKUP = "A backup target pool!";
|
||||
|
||||
private static final String INSTANCE_NETWORK_NAME = "target-pool-api-live-test-network";
|
||||
private static final String INSTANCE_NAME = "target-pool-api-live-test-instance";
|
||||
private static final String BOOT_DISK_NAME = INSTANCE_NAME + "-boot-disk";
|
||||
private static final String IPV4_RANGE = "10.0.0.0/8";
|
||||
private static final String HEALTHCHECK_NAME = "target-pool-test-health-check";
|
||||
|
||||
private static final int DEFAULT_DISK_SIZE_GB = 10;
|
||||
private static final int TIME_WAIT_LONG = 600;
|
||||
|
||||
private Set<URI> instances;
|
||||
private Set<URI> httpHealthChecks;
|
||||
|
||||
private TargetPoolApi api() {
|
||||
return api.getTargetPoolApi(userProject.get(), DEFAULT_REGION_NAME);
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
public void testCreateInstanceAndHealthCheck(){
|
||||
InstanceApi instanceApi = api.getInstanceApi(userProject.get());
|
||||
HttpHealthCheckApi httpHealthCheckApi = api.getHttpHealthCheckApi(userProject.get());
|
||||
|
||||
// Get an imageUri
|
||||
URI imageUri = api.getImageApi("centos-cloud")
|
||||
.list(new ListOptions.Builder().filter("name eq centos.*"))
|
||||
.concat()
|
||||
.filter(new Predicate<Image>() {
|
||||
@Override
|
||||
public boolean apply(Image input) {
|
||||
// filter out all deprecated images
|
||||
return !(input.getDeprecated().isPresent() && input.getDeprecated().get().getState().isPresent());
|
||||
}
|
||||
})
|
||||
.first().get().getSelfLink();
|
||||
|
||||
// Make and instanceTemplate
|
||||
InstanceTemplate instanceTemplate = InstanceTemplate.builder()
|
||||
.forMachineType(getDefaultMachineTypeUrl(userProject.get()))
|
||||
.addNetworkInterface(getNetworkUrl(userProject.get(), INSTANCE_NETWORK_NAME),
|
||||
Instance.NetworkInterface.AccessConfig.Type.ONE_TO_ONE_NAT)
|
||||
.addMetadata("mykey", "myvalue")
|
||||
.description("a description")
|
||||
.addDisk(InstanceTemplate.PersistentDisk.Mode.READ_WRITE, getDiskUrl(userProject.get(), BOOT_DISK_NAME),
|
||||
null, true, true)
|
||||
.image(imageUri);
|
||||
|
||||
|
||||
// Insert a network.
|
||||
assertGlobalOperationDoneSucessfully(api.getNetworkApi(userProject.get()).createInIPv4Range
|
||||
(INSTANCE_NETWORK_NAME, IPV4_RANGE), TIME_WAIT_LONG);
|
||||
|
||||
// Create a disk.
|
||||
DiskCreationOptions diskCreationOptions = new DiskCreationOptions().sourceImage(instanceTemplate.getImage());
|
||||
assertZoneOperationDoneSucessfully(api.getDiskApi(userProject.get())
|
||||
.createInZone(BOOT_DISK_NAME, DEFAULT_DISK_SIZE_GB, DEFAULT_ZONE_NAME, diskCreationOptions),
|
||||
TIME_WAIT_LONG);
|
||||
|
||||
// Create an instance.
|
||||
assertZoneOperationDoneSucessfully(instanceApi.createInZone(INSTANCE_NAME,
|
||||
DEFAULT_ZONE_NAME,
|
||||
instanceTemplate),
|
||||
TIME_WAIT_LONG);
|
||||
Instance instance = instanceApi.getInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME);
|
||||
instances = new HashSet<URI>();
|
||||
instances.add(instance.getSelfLink());
|
||||
|
||||
// Create a healthCheck
|
||||
HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions()
|
||||
.checkIntervalSec(30)
|
||||
.timeoutSec(20)
|
||||
.description("A test HealthCheck for adding to targetPools");
|
||||
assertGlobalOperationDoneSucessfully(httpHealthCheckApi.insert(HEALTHCHECK_NAME, options), TIME_WAIT);
|
||||
HttpHealthCheck healthCheck = httpHealthCheckApi.get(HEALTHCHECK_NAME);
|
||||
httpHealthChecks = new HashSet<URI>();
|
||||
httpHealthChecks.add(healthCheck.getSelfLink());
|
||||
}
|
||||
|
||||
@Test(groups = "live")
|
||||
public void testInsertTargetPool() {
|
||||
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions()
|
||||
.description(DESCRIPTION)
|
||||
.description(DESCRIPTION_BACKUP)
|
||||
.sessionAffinity(SessionAffinityValue.CLIENT_IP);
|
||||
assertRegionOperationDoneSucessfully(api().create(BACKUP_TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
|
||||
public void testInsertTargetPool2(){
|
||||
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool);
|
||||
// Make a Target Pool with a backup and failoverRatio specified.
|
||||
TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions()
|
||||
.description(DESCRIPTION)
|
||||
.sessionAffinity(SessionAffinityValue.CLIENT_IP)
|
||||
.backupPool(targetPool.getSelfLink())
|
||||
.failoverRatio((float) 0.5);
|
||||
assertRegionOperationDoneSucessfully(api().create(TARGETPOOL_NAME, targetPoolCreationOptions), TIME_WAIT);
|
||||
TargetPool targetPool2 = api().get(TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool2);
|
||||
assertEquals(targetPool2.getName(), TARGETPOOL_NAME);
|
||||
assertEquals(targetPool2.getDescription(), fromNullable(DESCRIPTION));
|
||||
assertEquals(targetPool2.getFailoverRatio(), (float) 0.5);
|
||||
assertEquals(targetPool2.getBackupPool(), fromNullable(targetPool.getSelfLink()));
|
||||
assertEquals(targetPool2.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
|
||||
public void testGetTargetPool() {
|
||||
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
|
||||
assertEquals(targetPool.getDescription(), fromNullable(DESCRIPTION_BACKUP));
|
||||
assertEquals(targetPool.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool", "testCreateInstanceAndHealthCheck"})
|
||||
public void testAddInstanceTargetPool() {
|
||||
assertRegionOperationDoneSucessfully(api().addInstance(BACKUP_TARGETPOOL_NAME, instances), TIME_WAIT);
|
||||
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
|
||||
assertEquals(targetPool.getInstances(), instances);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testAddInstanceTargetPool")
|
||||
public void testRemoveInstanceTargetPool() {
|
||||
assertRegionOperationDoneSucessfully(api().removeInstance(BACKUP_TARGETPOOL_NAME, instances), TIME_WAIT);
|
||||
|
||||
TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME);
|
||||
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), BACKUP_TARGETPOOL_NAME);
|
||||
assertNotEquals(targetPool.getInstances(), fromNullable(instances));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2", "testCreateInstanceAndHealthCheck"})
|
||||
public void testAddHealthCheckTargetPool() {
|
||||
assertRegionOperationDoneSucessfully(api().addHealthCheck(TARGETPOOL_NAME, httpHealthChecks), TIME_WAIT);
|
||||
TargetPool targetPool = api().get(TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), TARGETPOOL_NAME);
|
||||
assertEquals(targetPool.getDescription(), fromNullable(DESCRIPTION));
|
||||
assertEquals(targetPool.getSessionAffinity(), fromNullable(SessionAffinityValue.CLIENT_IP));
|
||||
assertEquals(targetPool.getHealthChecks(), httpHealthChecks);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testAddHealthCheckTargetPool")
|
||||
public void testRemoveHealthCheckTargetPool() {
|
||||
assertRegionOperationDoneSucessfully(api().removeHealthCheck(TARGETPOOL_NAME, httpHealthChecks), TIME_WAIT);
|
||||
|
||||
TargetPool targetPool = api().get(TARGETPOOL_NAME);
|
||||
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), TARGETPOOL_NAME);
|
||||
assertNotEquals(targetPool.getHealthChecks(), fromNullable(httpHealthChecks));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertTargetPool")
|
||||
public void testListTargetPool() {
|
||||
|
||||
IterableWithMarker<TargetPool> targetPool = api().list(new ListOptions.Builder()
|
||||
.filter("name eq " + TARGETPOOL_NAME));
|
||||
.filter("name eq " + BACKUP_TARGETPOOL_NAME));
|
||||
assertEquals(targetPool.toList().size(), 1);
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testListTargetPool", "testGetTargetPool"})
|
||||
@Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2"})
|
||||
public void testSetBackupTargetPool() {
|
||||
TargetPoolCreationOptions options = new TargetPoolCreationOptions().description("A targetPool for testing setBackup.");
|
||||
assertRegionOperationDoneSucessfully(api().create(THIRD_TARGETPOOL_NAME, options), TIME_WAIT);
|
||||
TargetPool targetPool = api().get(THIRD_TARGETPOOL_NAME);
|
||||
assertNotNull(targetPool);
|
||||
assertEquals(targetPool.getName(), THIRD_TARGETPOOL_NAME);
|
||||
assertEquals(targetPool.getBackupPool(), fromNullable(null));
|
||||
|
||||
URI selfLink = api().get(TARGETPOOL_NAME).getSelfLink();
|
||||
|
||||
Float failoverRatio = Float.valueOf((float) 0.5);
|
||||
assertRegionOperationDoneSucessfully(api().setBackup(THIRD_TARGETPOOL_NAME, failoverRatio, selfLink), TIME_WAIT);
|
||||
|
||||
TargetPool targetPoolUpdated = api().get(THIRD_TARGETPOOL_NAME);
|
||||
assertNotNull(targetPoolUpdated);
|
||||
assertEquals(targetPoolUpdated.getName(), THIRD_TARGETPOOL_NAME);
|
||||
assertEquals(targetPoolUpdated.getBackupPool(), fromNullable(selfLink));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = {"testListTargetPool",
|
||||
"testGetTargetPool",
|
||||
"testRemoveInstanceTargetPool",
|
||||
"testRemoveHealthCheckTargetPool",
|
||||
"testSetBackupTargetPool"}, alwaysRun = true)
|
||||
public void testDeleteTargetPool() {
|
||||
// Note: This ordering matters due one being the backup of the other ect.
|
||||
assertRegionOperationDoneSucessfully(api().delete(THIRD_TARGETPOOL_NAME), TIME_WAIT);
|
||||
assertRegionOperationDoneSucessfully(api().delete(TARGETPOOL_NAME), TIME_WAIT);
|
||||
assertRegionOperationDoneSucessfully(api().delete(BACKUP_TARGETPOOL_NAME), TIME_WAIT);
|
||||
}
|
||||
|
||||
@AfterClass(groups = { "integration", "live" })
|
||||
public void testCleanup(){
|
||||
InstanceApi instanceApi = api.getInstanceApi(userProject.get());
|
||||
HttpHealthCheckApi httpHealthCheckApi = api.getHttpHealthCheckApi(userProject.get());
|
||||
|
||||
try {
|
||||
waitZoneOperationDone(instanceApi.deleteInZone(DEFAULT_ZONE_NAME, INSTANCE_NAME), TIME_WAIT_LONG);
|
||||
|
||||
waitZoneOperationDone(api.getDiskApi(userProject.get()).deleteInZone(DEFAULT_ZONE_NAME, BOOT_DISK_NAME),
|
||||
TIME_WAIT);
|
||||
waitGlobalOperationDone(api.getNetworkApi(userProject.get()).delete(INSTANCE_NETWORK_NAME), TIME_WAIT_LONG);
|
||||
|
||||
waitGlobalOperationDone(httpHealthCheckApi.delete(HEALTHCHECK_NAME), TIME_WAIT);
|
||||
} catch (Exception e) {
|
||||
// we don't really care about any exception here, so just delete away.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue