Issue 29: better state testing

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2291 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-15 01:49:23 +00:00
parent 9a1abce72f
commit 2285f36bd3
1 changed files with 16 additions and 8 deletions

View File

@ -49,6 +49,8 @@ import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.HttpResponseException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
@ -67,7 +69,7 @@ import com.google.inject.Injector;
*
* @author Adrian Cole
*/
@Test(groups = "live", enabled = false, sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
@Test(groups = "live", enabled = true, sequential = true, testName = "ec2.ExpensiveEC2ClientLiveTest")
public class ExpensiveEC2ClientLiveTest {
private EC2Client client;
@ -78,6 +80,8 @@ public class ExpensiveEC2ClientLiveTest {
private String serverId;
private InetAddress address;
private RetryablePredicate<InetSocketAddress> socketTester;
@BeforeGroups(groups = { "live" })
public void setupClient() throws InterruptedException, ExecutionException, TimeoutException {
String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
@ -90,9 +94,12 @@ public class ExpensiveEC2ClientLiveTest {
new ExecutorServiceModule(new WithinThreadExecutorService()));
client = EC2ContextFactory.createContext(user, password, new Log4JLoggingModule()).getApi();
sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<InetSocketAddress>(socketOpen, 60, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger
}
@Test(enabled = false)
@Test(enabled = true)
void testCreateSecurityGroupIngressCidr() throws InterruptedException, ExecutionException,
TimeoutException {
securityGroupName = serverPrefix + "ingress";
@ -112,7 +119,7 @@ public class ExpensiveEC2ClientLiveTest {
.get(30, TimeUnit.SECONDS);
}
@Test(enabled = false)
@Test(enabled = true)
void testCreateKeyPair() throws InterruptedException, ExecutionException, TimeoutException {
String keyName = serverPrefix + "1";
try {
@ -129,7 +136,7 @@ public class ExpensiveEC2ClientLiveTest {
assertEquals(keyPair.getKeyName(), keyName);
}
@Test(enabled = false, dependsOnMethods = { "testCreateKeyPair",
@Test(enabled = true, dependsOnMethods = { "testCreateKeyPair",
"testCreateSecurityGroupIngressCidr" })
public void testCreateRunningInstance() throws Exception {
String imageId = "ami-1fd73376";
@ -158,7 +165,7 @@ public class ExpensiveEC2ClientLiveTest {
sshPing(server);
}
@Test(enabled = false, dependsOnMethods = "testCreateRunningInstance")
@Test(enabled = true, dependsOnMethods = "testCreateRunningInstance")
void testElasticIpAddress() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
address = client.allocateAddress().get(30, TimeUnit.SECONDS);
@ -192,7 +199,7 @@ public class ExpensiveEC2ClientLiveTest {
assert compare.getInstanceId() == null;
reservation = client.describeInstances(serverId).get(30, TimeUnit.SECONDS).last();
assert reservation.getRunningInstances().last().getIpAddress() == null;
// assert reservation.getRunningInstances().last().getIpAddress() == null; TODO
}
/**
@ -235,8 +242,9 @@ public class ExpensiveEC2ClientLiveTest {
.getInstanceId(), currentDetails.getInstanceState());
Thread.sleep(5 * 1000);
}
System.out.printf("%s awaiting daemons to start%n", currentDetails.getInstanceId());
Thread.sleep(10 * 1000);
System.out.printf("%s awaiting ssh service to start%n", currentDetails.getInstanceId());
assert socketTester.apply(new InetSocketAddress(currentDetails.getDnsName(), 22));
System.out.printf("%s ssh service started%n", currentDetails.getInstanceId());
return currentDetails;
}