mirror of
https://github.com/apache/jclouds.git
synced 2025-02-16 06:56:45 +00:00
reorganized test so that execution is predicatble when run in surefire
This commit is contained in:
parent
f1334fb999
commit
1680931776
@ -19,9 +19,7 @@
|
||||
package org.jclouds.cloudloadbalancers.features;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -38,7 +36,6 @@ import org.jclouds.predicates.RetryablePredicate;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
@ -30,8 +30,6 @@ import org.jclouds.cloudloadbalancers.domain.LoadBalancerAttributes;
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
|
||||
import org.jclouds.cloudloadbalancers.domain.NodeRequest;
|
||||
import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
@ -45,14 +43,15 @@ import com.google.common.collect.Sets;
|
||||
@Test(groups = "live", singleThreaded = true, testName = "LoadBalancerClientLiveTest")
|
||||
public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
|
||||
private Set<LoadBalancer> lbs = Sets.newLinkedHashSet();
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
protected void setup() {
|
||||
assertEquals(client.getConfiguredRegions(), Arrays.asList(regions));
|
||||
Logger.getAnonymousLogger().info("running against regions "+client.getConfiguredRegions());
|
||||
|
||||
@Override
|
||||
public void setupClient() {
|
||||
super.setupClient();
|
||||
assertEquals(client.getConfiguredRegions(), Arrays.asList(regions));
|
||||
Logger.getAnonymousLogger().info("running against regions " + client.getConfiguredRegions());
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
@Override
|
||||
protected void tearDown() {
|
||||
for (LoadBalancer lb : lbs) {
|
||||
client.getLoadBalancerClient(lb.getRegion()).removeLoadBalancer(lb.getId());
|
||||
@ -61,6 +60,37 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testCreateLoadBalancer() throws Exception {
|
||||
for (String region : client.getConfiguredRegions()) {
|
||||
Logger.getAnonymousLogger().info("starting lb in region " + region);
|
||||
LoadBalancer lb = client.getLoadBalancerClient(region).createLoadBalancer(
|
||||
LoadBalancerRequest.builder().name(prefix + "-" + region).protocol("HTTP").port(80).virtualIPType(
|
||||
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
|
||||
checkLBInRegion(region, lb, prefix + "-" + region);
|
||||
assertEquals(lb.getStatus(), LoadBalancer.Status.BUILD);
|
||||
lbs.add(lb);
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
|
||||
LoadBalancer newLb = client.getLoadBalancerClient(region).getLoadBalancer(lb.getId());
|
||||
checkLBInRegion(region, newLb, prefix + "-" + region);
|
||||
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateLoadBalancer")
|
||||
public void testUpdateLoadBalancer() throws Exception {
|
||||
for (LoadBalancer lb : lbs) {
|
||||
client.getLoadBalancerClient(lb.getRegion()).updateLoadBalancerAttributes(lb.getId(),
|
||||
LoadBalancerAttributes.Builder.name("foo" + "-" + lb.getRegion()));
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
|
||||
LoadBalancer newLb = client.getLoadBalancerClient(lb.getRegion()).getLoadBalancer(lb.getId());
|
||||
checkLBInRegion(newLb.getRegion(), newLb, "foo" + "-" + lb.getRegion());
|
||||
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testUpdateLoadBalancer")
|
||||
public void testListLoadBalancers() throws Exception {
|
||||
for (String region : client.getConfiguredRegions()) {
|
||||
Set<LoadBalancer> response = client.getLoadBalancerClient(region).listLoadBalancers();
|
||||
@ -95,42 +125,12 @@ public class LoadBalancerClientLiveTest extends BaseCloudLoadBalancersClientLive
|
||||
// node info not available during list;
|
||||
assert getDetails.getNodes().size() > 0 : lb;
|
||||
} catch (AssertionError e) {
|
||||
throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(),getDetails, lb));
|
||||
throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(), getDetails, lb));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testCreateLoadBalancer() throws Exception {
|
||||
for (String region : client.getConfiguredRegions()) {
|
||||
Logger.getAnonymousLogger().info("starting lb in region " + region);
|
||||
LoadBalancer lb = client.getLoadBalancerClient(region).createLoadBalancer(
|
||||
LoadBalancerRequest.builder().name(prefix + "-" + region).protocol("HTTP").port(80).virtualIPType(
|
||||
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
|
||||
checkLBInRegion(region, lb, prefix + "-" + region);
|
||||
assertEquals(lb.getStatus(), LoadBalancer.Status.BUILD);
|
||||
lbs.add(lb);
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
|
||||
LoadBalancer newLb = client.getLoadBalancerClient(region).getLoadBalancer(lb.getId());
|
||||
checkLBInRegion(region, newLb, prefix + "-" + region);
|
||||
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testCreateLoadBalancer")
|
||||
public void testUpdateLoadBalancer() throws Exception {
|
||||
for (LoadBalancer lb : lbs) {
|
||||
client.getLoadBalancerClient(lb.getRegion()).updateLoadBalancerAttributes(lb.getId(),
|
||||
LoadBalancerAttributes.Builder.name("foo" + "-" + lb.getRegion()));
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
|
||||
LoadBalancer newLb = client.getLoadBalancerClient(lb.getRegion()).getLoadBalancer(lb.getId());
|
||||
checkLBInRegion(newLb.getRegion(), newLb, "foo" + "-" + lb.getRegion());
|
||||
assertEquals(newLb.getStatus(), LoadBalancer.Status.ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkLBInRegion(String region, LoadBalancer lb, String name) {
|
||||
assertEquals(lb.getRegion(), region);
|
||||
assertEquals(lb.getName(), name);
|
||||
|
@ -26,19 +26,18 @@ import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancer;
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status;
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancerRequest;
|
||||
import org.jclouds.cloudloadbalancers.domain.Node;
|
||||
import org.jclouds.cloudloadbalancers.domain.NodeAttributes;
|
||||
import org.jclouds.cloudloadbalancers.domain.NodeRequest;
|
||||
import org.jclouds.cloudloadbalancers.domain.LoadBalancer.Status;
|
||||
import org.jclouds.cloudloadbalancers.domain.VirtualIP.Type;
|
||||
import org.testng.annotations.AfterGroups;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
@ -49,49 +48,73 @@ import org.testng.annotations.Test;
|
||||
@Test(groups = "live", singleThreaded = true, testName = "NodeClientLiveTest")
|
||||
public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
|
||||
private Map<LoadBalancer, Set<Node>> nodes = new HashMap<LoadBalancer, Set<Node>>();
|
||||
|
||||
@BeforeGroups(groups = "live")
|
||||
protected void setup() {
|
||||
assertTrue(client.getConfiguredRegions().size() > 0, "Need to have some regions!");
|
||||
Logger.getAnonymousLogger().info("running against regions "+client.getConfiguredRegions());
|
||||
for (String region : client.getConfiguredRegions()) {
|
||||
Logger.getAnonymousLogger().info("starting lb in region " + region);
|
||||
LoadBalancer lb = client.getLoadBalancerClient(region).createLoadBalancer(
|
||||
LoadBalancerRequest.builder().name(prefix + "-" + region).protocol("HTTP").port(80).virtualIPType(
|
||||
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
|
||||
nodes.put(lb, new HashSet<Node>());
|
||||
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
}
|
||||
}
|
||||
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
|
||||
LoadBalancer lb = entry.getKey();
|
||||
LoadBalancerClient lbClient = client.getLoadBalancerClient(lb.getRegion());
|
||||
|
||||
if(lbClient.getLoadBalancer(lb.getId()).getStatus() != Status.DELETED) {
|
||||
lbClient.removeLoadBalancer(lb.getId());
|
||||
}
|
||||
assert loadBalancerDeleted.apply(lb) : lb;
|
||||
@Test(groups = "live")
|
||||
public void testCreateLoadBalancers() {
|
||||
assertTrue(client.getConfiguredRegions().size() > 0, "Need to have some regions!");
|
||||
Logger.getAnonymousLogger().info("running against regions " + client.getConfiguredRegions());
|
||||
for (String region : client.getConfiguredRegions()) {
|
||||
Logger.getAnonymousLogger().info("starting lb in region " + region);
|
||||
LoadBalancer lb = client.getLoadBalancerClient(region).createLoadBalancer(
|
||||
LoadBalancerRequest.builder().name(prefix + "-" + region).protocol("HTTP").port(80).virtualIPType(
|
||||
Type.PUBLIC).node(NodeRequest.builder().address("192.168.1.1").port(8080).build()).build());
|
||||
nodes.put(lb, new HashSet<Node>());
|
||||
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testCreateLoadBalancers")
|
||||
public void testAddNodes() throws Exception {
|
||||
for (LoadBalancer lb : nodes.keySet()) {
|
||||
String region = lb.getRegion();
|
||||
Logger.getAnonymousLogger().info("starting node on loadbalancer " + lb.getId() + " in region " + region);
|
||||
Set<Node> newNodes = client.getNodeClient(region).createNodesInLoadBalancer(
|
||||
Collections.<NodeRequest> singleton(NodeRequest.builder().address("192.168.1.2").port(8080).build()),
|
||||
lb.getId());
|
||||
|
||||
for (Node n : newNodes) {
|
||||
assertEquals(n.getStatus(), Node.Status.ONLINE);
|
||||
nodes.get(lb).add(n);
|
||||
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), lb.getId()).getStatus(),
|
||||
Node.Status.ONLINE);
|
||||
}
|
||||
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testAddNodes")
|
||||
public void testModifyNode() throws Exception {
|
||||
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
|
||||
for (Node n : entry.getValue()) {
|
||||
String region = entry.getKey().getRegion();
|
||||
client.getNodeClient(region).updateAttributesForNodeInLoadBalancer(NodeAttributes.Builder.weight(23),
|
||||
n.getId(), entry.getKey().getId());
|
||||
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId())
|
||||
.getStatus(), Node.Status.ONLINE);
|
||||
|
||||
Node newNode = client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId());
|
||||
assertEquals(newNode.getStatus(), Node.Status.ONLINE);
|
||||
assertEquals(newNode.getWeight(), (Integer) 23);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testModifyNode")
|
||||
public void testListNodes() throws Exception {
|
||||
for (LoadBalancer lb : nodes.keySet()) {
|
||||
for (LoadBalancer lb : nodes.keySet()) {
|
||||
Set<Node> response = client.getNodeClient(lb.getRegion()).listNodes(lb.getId());
|
||||
assert null != response;
|
||||
assertTrue(response.size() >= 0);
|
||||
for (Node n : response) {
|
||||
assert n.getId() != -1 : n;
|
||||
assert n.getCondition() != null : n;
|
||||
assert n.getId() != -1 : n;
|
||||
assert n.getCondition() != null : n;
|
||||
assert n.getAddress() != null : n;
|
||||
assert n.getPort() != -1 : n;
|
||||
assert n.getStatus() != null : n;
|
||||
assert !Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(
|
||||
lb.getTypedAlgorithm()) || n.getWeight() != null : n;
|
||||
assert !Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(lb.getTypedAlgorithm())
|
||||
|| n.getWeight() != null : n;
|
||||
|
||||
Node getDetails = client.getNodeClient(lb.getRegion()).getNodeInLoadBalancer(n.getId(), lb.getId());
|
||||
System.out.println(n.toString());
|
||||
@ -101,48 +124,28 @@ public class NodeClientLiveTest extends BaseCloudLoadBalancersClientLiveTest {
|
||||
assertEquals(getDetails.getAddress(), n.getAddress());
|
||||
assertEquals(getDetails.getPort(), n.getPort());
|
||||
assertEquals(getDetails.getStatus(), n.getStatus());
|
||||
if(Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(
|
||||
lb.getTypedAlgorithm())) {
|
||||
if (Arrays.asList(LoadBalancer.WEIGHTED_ALGORITHMS).contains(lb.getTypedAlgorithm())) {
|
||||
assertEquals(getDetails.getWeight(), n.getWeight());
|
||||
}
|
||||
} catch (AssertionError e) {
|
||||
throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(),getDetails, n));
|
||||
throw new AssertionError(String.format("%s\n%s - %s", e.getMessage(), getDetails, n));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddNodes() throws Exception {
|
||||
for (LoadBalancer lb : nodes.keySet()) {
|
||||
String region = lb.getRegion();
|
||||
Logger.getAnonymousLogger().info("starting node on loadbalancer "+lb.getId()+" in region "+region);
|
||||
Set<Node> newNodes = client.getNodeClient(region).createNodesInLoadBalancer(Collections.<NodeRequest>singleton(
|
||||
NodeRequest.builder().address("192.168.1.2").port(8080).build()), lb.getId());
|
||||
|
||||
for (Node n : newNodes) {
|
||||
assertEquals(n.getStatus(), Node.Status.ONLINE);
|
||||
nodes.get(lb).add(n);
|
||||
assertEquals(client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), lb.getId()).getStatus(), Node.Status.ONLINE);
|
||||
}
|
||||
|
||||
assert loadBalancerActive.apply(lb) : lb;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
@AfterGroups(groups = "live")
|
||||
protected void tearDown() {
|
||||
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
|
||||
LoadBalancer lb = entry.getKey();
|
||||
LoadBalancerClient lbClient = client.getLoadBalancerClient(lb.getRegion());
|
||||
|
||||
@Test(dependsOnMethods = "testAddNodes")
|
||||
public void testModifyNode() throws Exception {
|
||||
for (Entry<LoadBalancer, Set<Node>> entry : nodes.entrySet()) {
|
||||
for (Node n : entry.getValue()) {
|
||||
String region = entry.getKey().getRegion();
|
||||
client.getNodeClient(region).updateAttributesForNodeInLoadBalancer(NodeAttributes.Builder.weight(23),
|
||||
n.getId(), entry.getKey().getId());
|
||||
assertEquals(client.getNodeClient(region)
|
||||
.getNodeInLoadBalancer(n.getId(), entry.getKey().getId()).getStatus(), Node.Status.ONLINE);
|
||||
|
||||
Node newNode = client.getNodeClient(region).getNodeInLoadBalancer(n.getId(), entry.getKey().getId());
|
||||
assertEquals(newNode.getStatus(), Node.Status.ONLINE);
|
||||
assertEquals(newNode.getWeight(), (Integer)23);
|
||||
}
|
||||
if (lbClient.getLoadBalancer(lb.getId()).getStatus() != Status.DELETED) {
|
||||
lbClient.removeLoadBalancer(lb.getId());
|
||||
}
|
||||
assert loadBalancerDeleted.apply(lb) : lb;
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user