mirror of
https://github.com/apache/jclouds.git
synced 2025-02-10 03:56:27 +00:00
refactor BaseComputeServiceLiveTest to simplify the extension of this base test
This commit is contained in:
parent
a39eadce50
commit
4cf6efe39a
@ -35,8 +35,6 @@ import static java.util.concurrent.TimeUnit.SECONDS;
|
|||||||
import static java.util.logging.Logger.getAnonymousLogger;
|
import static java.util.logging.Logger.getAnonymousLogger;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.nameTask;
|
||||||
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript;
|
||||||
import static org.jclouds.compute.options.TemplateOptions.Builder.inboundPorts;
|
|
||||||
import static org.jclouds.compute.options.TemplateOptions.Builder.nodeNames;
|
|
||||||
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials;
|
import static org.jclouds.compute.options.TemplateOptions.Builder.overrideLoginCredentials;
|
||||||
import static org.jclouds.compute.options.TemplateOptions.Builder.runAsRoot;
|
import static org.jclouds.compute.options.TemplateOptions.Builder.runAsRoot;
|
||||||
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED;
|
||||||
@ -50,7 +48,6 @@ import static org.testng.Assert.assertFalse;
|
|||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
import static org.testng.Assert.fail;
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -82,7 +79,6 @@ import org.jclouds.compute.domain.NodeMetadata.Status;
|
|||||||
import org.jclouds.compute.domain.OperatingSystem;
|
import org.jclouds.compute.domain.OperatingSystem;
|
||||||
import org.jclouds.compute.domain.Template;
|
import org.jclouds.compute.domain.Template;
|
||||||
import org.jclouds.compute.domain.TemplateBuilder;
|
import org.jclouds.compute.domain.TemplateBuilder;
|
||||||
import org.jclouds.compute.options.TemplateOptions;
|
|
||||||
import org.jclouds.compute.util.OpenSocketFinder;
|
import org.jclouds.compute.util.OpenSocketFinder;
|
||||||
import org.jclouds.domain.Credentials;
|
import org.jclouds.domain.Credentials;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
@ -218,10 +214,10 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
template = buildTemplate(client.templateBuilder());
|
||||||
TemplateOptions options = client.templateOptions().blockOnPort(22, 120);
|
template.getOptions().blockOnPort(22, 120);
|
||||||
try {
|
try {
|
||||||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
|
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
|
||||||
NodeMetadata node = get(nodes, 0);
|
NodeMetadata node = get(nodes, 0);
|
||||||
LoginCredentials good = node.getCredentials();
|
LoginCredentials good = node.getCredentials();
|
||||||
assert good.identity != null : nodes;
|
assert good.identity != null : nodes;
|
||||||
@ -362,9 +358,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
|
|
||||||
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript")
|
@Test(enabled = true, dependsOnMethods = "testCreateTwoNodesWithRunScript")
|
||||||
public void testCreateTwoNodesWithOneSpecifiedName() throws Exception {
|
public void testCreateTwoNodesWithOneSpecifiedName() throws Exception {
|
||||||
|
template = buildTemplate(client.templateBuilder());
|
||||||
|
template.getOptions().nodeNames(ImmutableSet.of("first-node"));
|
||||||
Set<? extends NodeMetadata> nodes;
|
Set<? extends NodeMetadata> nodes;
|
||||||
try {
|
try {
|
||||||
nodes = newTreeSet(client.createNodesInGroup(group, 2, nodeNames(ImmutableSet.of("first-node"))));
|
nodes = newTreeSet(client.createNodesInGroup(group, 2, template));
|
||||||
} catch (RunNodesException e) {
|
} catch (RunNodesException e) {
|
||||||
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
|
nodes = newTreeSet(concat(e.getSuccessfulNodes(), e.getNodeErrors().keySet()));
|
||||||
throw e;
|
throw e;
|
||||||
@ -423,6 +421,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
|
|
||||||
if (existingLocationIsAssignable) {
|
if (existingLocationIsAssignable) {
|
||||||
getAnonymousLogger().info("creating another node based on existing nodes' location: " + existingLocation);
|
getAnonymousLogger().info("creating another node based on existing nodes' location: " + existingLocation);
|
||||||
|
template = buildTemplate(client.templateBuilder());
|
||||||
template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template)
|
template = addRunScriptToTemplate(client.templateBuilder().fromTemplate(template)
|
||||||
.locationId(existingLocation.getId()).build());
|
.locationId(existingLocation.getId()).build());
|
||||||
} else {
|
} else {
|
||||||
@ -456,11 +455,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
final int groupNum = i;
|
final int groupNum = i;
|
||||||
final String group = "twin" + groupNum;
|
final String group = "twin" + groupNum;
|
||||||
groups.add(group);
|
groups.add(group);
|
||||||
|
template = buildTemplate(client.templateBuilder());
|
||||||
|
template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300 + groupNum);
|
||||||
ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
|
ListenableFuture<NodeMetadata> future = userExecutor.submit(new Callable<NodeMetadata>() {
|
||||||
public NodeMetadata call() throws Exception {
|
public NodeMetadata call() throws Exception {
|
||||||
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, inboundPorts(22, 8080)
|
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template));
|
||||||
.blockOnPort(22, 300 + groupNum)));
|
|
||||||
getAnonymousLogger().info("Started node " + node.getId());
|
getAnonymousLogger().info("Started node " + node.getId());
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -713,8 +712,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
|
|
||||||
ImmutableSet<String> tags = ImmutableSet. of(group);
|
ImmutableSet<String> tags = ImmutableSet. of(group);
|
||||||
Stopwatch watch = Stopwatch.createStarted();
|
Stopwatch watch = Stopwatch.createStarted();
|
||||||
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1,
|
|
||||||
inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags)));
|
template = buildTemplate(client.templateBuilder());
|
||||||
|
template.getOptions().inboundPorts(22, 8080).blockOnPort(22, 300).userMetadata(userMetadata).tags(tags);
|
||||||
|
|
||||||
|
NodeMetadata node = getOnlyElement(client.createNodesInGroup(group, 1, template));
|
||||||
long createSeconds = watch.elapsed(TimeUnit.SECONDS);
|
long createSeconds = watch.elapsed(TimeUnit.SECONDS);
|
||||||
|
|
||||||
final String nodeId = node.getId();
|
final String nodeId = node.getId();
|
||||||
@ -812,10 +814,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
|
|||||||
|
|
||||||
}
|
}
|
||||||
// no inbound ports
|
// no inbound ports
|
||||||
TemplateOptions options = client.templateOptions().blockUntilRunning(false).inboundPorts();
|
template = buildTemplate(client.templateBuilder());
|
||||||
|
template.getOptions().blockUntilRunning(false).inboundPorts();
|
||||||
try {
|
try {
|
||||||
long time = currentTimeMillis();
|
long time = currentTimeMillis();
|
||||||
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
|
Set<? extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, template);
|
||||||
NodeMetadata node = getOnlyElement(nodes);
|
NodeMetadata node = getOnlyElement(nodes);
|
||||||
assert node.getStatus() != Status.RUNNING : node;
|
assert node.getStatus() != Status.RUNNING : node;
|
||||||
long duration = (currentTimeMillis() - time) / 1000;
|
long duration = (currentTimeMillis() - time) / 1000;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user