revived jetty test

This commit is contained in:
Adrian Cole 2013-01-01 17:17:13 -08:00
parent 79334201bf
commit e42cb787f6
4 changed files with 27 additions and 20 deletions

View File

@ -20,6 +20,7 @@ package org.jclouds.compute;
import static org.jclouds.scriptbuilder.domain.Statements.exec; import static org.jclouds.scriptbuilder.domain.Statements.exec;
import static org.jclouds.scriptbuilder.domain.Statements.extractTargzAndFlattenIntoDirectory; import static org.jclouds.scriptbuilder.domain.Statements.extractTargzAndFlattenIntoDirectory;
import static org.jclouds.scriptbuilder.domain.Statements.literal;
import java.net.URI; import java.net.URI;
@ -35,7 +36,7 @@ import org.jclouds.scriptbuilder.statements.login.AdminAccess;
public class JettyStatements { public class JettyStatements {
public static final URI JETTY_URL = URI.create(System.getProperty("test.jetty-url",// public static final URI JETTY_URL = URI.create(System.getProperty("test.jetty-url",//
"http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz")); "http://download.eclipse.org/jetty/8.1.8.v20121106/dist/jetty-distribution-8.1.8.v20121106.tar.gz"));
public static final String JETTY_HOME = "/usr/local/jetty"; public static final String JETTY_HOME = "/usr/local/jetty";
@ -56,19 +57,20 @@ public class JettyStatements {
private static Statement authorizePortInIpTables() { private static Statement authorizePortInIpTables() {
return new StatementList( return new StatementList(
exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"), exec("iptables -I INPUT 1 -p tcp --dport " + port + " -j ACCEPT"),
exec("iptables-save")); exec("iptables-save"));
} }
public static Statement start() { public static Statement start() {
return new StatementList( return new StatementList(
exec("cd " + JETTY_HOME), literal("cd " + JETTY_HOME),
exec("./bin/jetty.sh start")); literal("nohup java -jar start.jar jetty.port=" + port + " > start.out 2> start.err < /dev/null &"),
literal("test $? && sleep 1")); // in case it is slow starting the proc
} }
public static Statement stop() { public static Statement stop() {
return new StatementList( return new StatementList(
exec("cd " + JETTY_HOME), literal("cd " + JETTY_HOME),
exec("./bin/jetty.sh stop")); literal("./bin/jetty.sh stop"));
} }
} }

View File

@ -319,8 +319,13 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
expect(clientNew.exec("java -fullversion\n")).andReturn(EXEC_GOOD); expect(clientNew.exec("java -fullversion\n")).andReturn(EXEC_GOOD);
clientNew.disconnect(); clientNew.disconnect();
String startJetty = new StringBuilder()
.append("cd /usr/local/jetty").append('\n')
.append("nohup java -jar start.jar jetty.port=8080 > start.out 2> start.err < /dev/null &").append('\n')
.append("test $? && sleep 1").append('\n').toString();
clientNew.connect(); clientNew.connect();
expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD); expect(clientNew.exec(startJetty)).andReturn(EXEC_GOOD);
clientNew.disconnect(); clientNew.disconnect();
clientNew.connect(); clientNew.connect();
@ -328,7 +333,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
clientNew.disconnect(); clientNew.disconnect();
clientNew.connect(); clientNew.connect();
expect(clientNew.exec("cd /usr/local/jetty\n./bin/jetty.sh start\n")).andReturn(EXEC_GOOD); expect(clientNew.exec(startJetty)).andReturn(EXEC_GOOD);
clientNew.disconnect(); clientNew.disconnect();
} catch (IOException e) { } catch (IOException e) {

View File

@ -225,7 +225,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
assert good.credential != null : nodes; assert good.credential != null : nodes;
for (Entry<? extends NodeMetadata, ExecResponse> response : client.runScriptOnNodesMatching( for (Entry<? extends NodeMetadata, ExecResponse> response : client.runScriptOnNodesMatching(
runningInGroup(group), Statements.exec("hostname"), runningInGroup(group), "hostname",
wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials(good)).entrySet()) { wrapInInitScript(false).runAsRoot(false).overrideLoginCredentials(good)).entrySet()) {
checkResponseEqualsHostname(response.getValue(), response.getKey()); checkResponseEqualsHostname(response.getValue(), response.getKey());
} }
@ -289,7 +289,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
@Test(enabled = false) @Test(enabled = false)
public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException { public void weCanCancelTasks(NodeMetadata node) throws InterruptedException, ExecutionException {
ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), Statements.exec("sleep 300"), ListenableFuture<ExecResponse> future = client.submitScriptOnNode(node.getId(), "sleep 300",
nameTask("sleeper").runAsRoot(false)); nameTask("sleeper").runAsRoot(false));
ExecResponse response = null; ExecResponse response = null;
try { try {
@ -297,11 +297,11 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
fail(node.getId() + ": " + response); fail(node.getId() + ": " + response);
} catch (TimeoutException e) { } catch (TimeoutException e) {
assert !future.isDone(); assert !future.isDone();
response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), response = client.runScriptOnNode(node.getId(), "/tmp/init-sleeper status",
wrapInInitScript(false).runAsRoot(false)); wrapInInitScript(false).runAsRoot(false));
assert !response.getOutput().trim().equals("") : node.getId() + ": " + response; assert !response.getOutput().trim().equals("") : node.getId() + ": " + response;
future.cancel(true); future.cancel(true);
response = client.runScriptOnNode(node.getId(), Statements.exec("/tmp/init-sleeper status"), response = client.runScriptOnNode(node.getId(), "/tmp/init-sleeper status",
wrapInInitScript(false).runAsRoot(false)); wrapInInitScript(false).runAsRoot(false));
assert response.getOutput().trim().equals("") : node.getId() + ": " + response; assert response.getOutput().trim().equals("") : node.getId() + ": " + response;
try { try {
@ -508,9 +508,9 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
checkOsMatchesTemplate(metadata); checkOsMatchesTemplate(metadata);
assert (metadata.getStatus() == Status.RUNNING) : metadata; assert (metadata.getStatus() == Status.RUNNING) : metadata;
// due to DHCP the addresses can actually change in-between runs. // due to DHCP the addresses can actually change in-between runs.
assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), String.format( assertEquals(metadata.getPrivateAddresses().size(), node.getPrivateAddresses().size(), format(
"[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size())); "[%s] didn't match: [%s]", metadata.getPrivateAddresses(), node.getPrivateAddresses().size()));
assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), String.format( assertEquals(metadata.getPublicAddresses().size(), node.getPublicAddresses().size(), format(
"[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size())); "[%s] didn't match: [%s]", metadata.getPublicAddresses(), node.getPublicAddresses().size()));
} }
assertNodeZero(metadataMap.values()); assertNodeZero(metadataMap.values());
@ -602,7 +602,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
@Override @Override
public String toString() { public String toString() {
return String.format("[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s]", return format("[backgroundProcessMilliseconds=%s, socketOpenMilliseconds=%s]",
backgroundProcessMilliseconds, socketOpenMilliseconds); backgroundProcessMilliseconds, socketOpenMilliseconds);
} }
} }
@ -618,7 +618,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
try { try {
socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS); socket = openSocketFinder.findOpenSocketOnNode(node, 8080, 60, TimeUnit.SECONDS);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {
throw new NoSuchElementException(String.format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError())); throw new NoSuchElementException(format("%s%n%s%s", e.getMessage(), exec.getOutput(), exec.getError()));
} }
stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
@ -692,12 +692,12 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
} }
protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) { protected void checkUserMetadataInNodeEquals(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
assert node.getUserMetadata().equals(userMetadata) : String.format("node userMetadata did not match %s %s", assert node.getUserMetadata().equals(userMetadata) : format("node userMetadata did not match %s %s",
userMetadata, node); userMetadata, node);
} }
protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet<String> tags) { protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet<String> tags) {
assert node.getTags().equals(tags) : String.format("node tags did not match %s %s", tags, node); assert node.getTags().equals(tags) : format("node tags did not match %s %s", tags, node);
} }
public void testListImages() throws Exception { public void testListImages() throws Exception {

View File

@ -222,7 +222,7 @@ END_OF_JCLOUDS_SCRIPT
iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT
iptables-save iptables-save
mkdir /tmp/$$ mkdir /tmp/$$
curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.eclipse.org/jetty/8.1.5.v20120716/dist/jetty-distribution-8.1.5.v20120716.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -) curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20 -X GET http://download.eclipse.org/jetty/8.1.8.v20121106/dist/jetty-distribution-8.1.8.v20121106.tar.gz |(mkdir -p /tmp/$$ &&cd /tmp/$$ &&tar -xpzf -)
mkdir -p /usr/local/jetty mkdir -p /usr/local/jetty
mv /tmp/$$/*/* /usr/local/jetty mv /tmp/$$/*/* /usr/local/jetty
rm -rf /tmp/$$ rm -rf /tmp/$$