Improving live tests

This commit is contained in:
Adam Lowe 2011-12-23 00:42:17 +00:00
parent 1cb55d6716
commit 0c2918abdc
15 changed files with 114 additions and 48 deletions

View File

@ -55,14 +55,14 @@ public interface ArchiveAsyncClient {
ListenableFuture<Set<Archive>> listArchives();
/**
* @see ArchiveClient#archiveDetails
* @see ArchiveClient#getArchiveDetails
*/
@POST
@Path("/archive/details/format/json")
@SelectJson("details")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ArchiveDetails> archiveDetails(@FormParam("username") String username);
ListenableFuture<ArchiveDetails> getArchiveDetails(@FormParam("username") String username);
/**
* @see ArchiveClient#createArchive
@ -84,7 +84,7 @@ public interface ArchiveAsyncClient {
*/
@POST
@Path("/archive/resize/format/json")
ListenableFuture<Void> resizeArchive(@FormParam("username") String username, @FormParam("size")int size);
ListenableFuture<Void> resizeArchive(@FormParam("username") String username, @FormParam("size") int size);
/**
* @see ArchiveClient#changeArchivePassword
*/

View File

@ -48,7 +48,7 @@ public interface ArchiveClient {
* @param username the username associated with the archive
* @return the archive information or null if not found
*/
ArchiveDetails archiveDetails(String username);
ArchiveDetails getArchiveDetails(String username);
/**
* Create a new backup volume.
@ -73,7 +73,7 @@ public interface ArchiveClient {
* Then delete the old volume.
*
* @param username the username associated with the archive
* @param size the new size required in GB
* @param size the new size required, see #getArchiveAllowedArguments for valid values
*/
void resizeArchive(String username, int size);

View File

@ -52,7 +52,7 @@ public interface EmailAsyncClient {
@SelectJson("response")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture<EmailOverview> emailOverview();
ListenableFuture<EmailOverview> getEmailOverview();
/**
* @see org.jclouds.glesys.features.EmailClient#listAccounts

View File

@ -44,7 +44,7 @@ public interface EmailClient {
*
* @return the relevant summary data
*/
EmailOverview emailOverview();
EmailOverview getEmailOverview();
/**
*

View File

@ -90,7 +90,7 @@ public interface ServerAsyncClient {
*/
@POST
@Path("/server/console/format/json")
@SelectJson("server")
@SelectJson("remote")
@Consumes(MediaType.APPLICATION_JSON)
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
ListenableFuture<ServerConsole> getServerConsole(@FormParam("serverid") String id);
@ -183,7 +183,7 @@ public interface ServerAsyncClient {
*/
@POST
@Path("/server/destroy/format/json")
ListenableFuture<Void> destroyServer(@FormParam("serverid") String id, @FormParam("keepip") int keepIp);
ListenableFuture<Void> destroyServer(@FormParam("serverid") String id, ServerDestroyOptions keepIp);
/**
* @see ServerClient#resetPassword

View File

@ -169,9 +169,9 @@ public interface ServerClient {
* Destroy a server
*
* @param id the id of the server
* @param keepIp if 1 the servers ip will be retained for use in your Glesys account
* @param keepIp if ServerDestroyOptions.keepIp(true) the servers ip will be retained for use in your GleSYS account
*/
void destroyServer(String id, int keepIp);
void destroyServer(String id, ServerDestroyOptions keepIp);
/**
* Reset the root password of a server

View File

@ -0,0 +1,35 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class ServerDestroyOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* Discard the server's ip on destroy
*/
public static ServerDestroyOptions keepIp() {
return new ServerDestroyOptions().keepIp(true);
}
/**
* Discard the server's ip on destroy
*/
public static ServerDestroyOptions discardIp() {
return new ServerDestroyOptions().keepIp(false);
}
}
/**
* Determines whether to keep the server's ip attached to your account when destroying a server
*
* @param keepIp if true, keep the ip address
*/
public ServerDestroyOptions keepIp(boolean keepIp) {
formParameters.put("keepip", Integer.toString(keepIp ? 1 : 0));
return this;
}
}

View File

@ -47,7 +47,7 @@ public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsy
}
public void testArchiveDetails() throws Exception {
testMethod("archiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName);
testMethod("getArchiveDetails", "details", "POST", true, ReturnNullOnNotFoundOr404.class, userName);
}
public void testCreateArchive() throws Exception {
@ -61,7 +61,7 @@ public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest<ArchiveAsy
public void testResizeArchive() throws Exception {
testMethod("resizeArchive", "resize", "POST", false, MapHttp4xxCodesToExceptions.class, userName,
newEntry("size", 5));
newEntry("size", "5 GB"));
}
public void testChangeArchivePassword() throws Exception {

View File

@ -39,7 +39,7 @@ import static org.testng.Assert.*;
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "ArchiveClientLiveTest")
@Test(groups = "live", testName = "ArchiveClientLiveTest", singleThreaded = true)
public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest {
@BeforeGroups(groups = {"live"})
@ -97,7 +97,7 @@ public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest {
@Test(dependsOnMethods = "testCreateArchive")
public void testArchiveDetails() throws Exception {
ArchiveDetails details = client.archiveDetails(archiveUser);
ArchiveDetails details = client.getArchiveDetails(archiveUser);
assertEquals(details.getUsername(), archiveUser);
assertNotNull(details.getFreeSize());
assertNotNull(details.getTotalSize());
@ -109,15 +109,14 @@ public class ArchiveClientLiveTest extends BaseGleSYSClientLiveTest {
// TODO assert something useful!
}
// TODO enable this once issue is resolved
@Test(enabled=false, dependsOnMethods = "testCreateArchive")
@Test(dependsOnMethods = "testCreateArchive")
public void testResizeArchive() throws Exception {
client.resizeArchive(archiveUser, 30);
client.resizeArchive(archiveUser, 20);
assertTrue(new RetryablePredicate<String>(
new Predicate<String>() {
public boolean apply(String value){
return client.archiveDetails(archiveUser) != null && value.equals(client.archiveDetails(archiveUser).getTotalSize());
return client.getArchiveDetails(archiveUser) != null && value.equals(client.getArchiveDetails(archiveUser).getTotalSize());
}
}, 30, 1, TimeUnit.SECONDS).apply("20 GB"));
}

View File

@ -94,7 +94,7 @@ public class BaseGleSYSClientLiveTest {
assertEquals(testServer.getHostname(), hostName);
assertFalse(testServer.getIps().isEmpty());
ServerStatusChecker runningServerCounter = new ServerStatusChecker(client, testServer.getId(), 300, 10, TimeUnit.SECONDS);
ServerStatusChecker runningServerCounter = new ServerStatusChecker(client, testServer.getId(), 180, 10, TimeUnit.SECONDS);
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
return runningServerCounter;

View File

@ -35,7 +35,7 @@ import static org.testng.Assert.assertTrue;
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "DomainClientLiveTest")
@Test(groups = "live", testName = "DomainClientLiveTest", singleThreaded = true)
public class DomainClientLiveTest extends BaseGleSYSClientLiveTest {
public final String testDomain = "glesystest.jclouds.org";

View File

@ -44,7 +44,7 @@ public class EmailAsyncClientTest extends BaseGleSYSAsyncClientTest<EmailAsyncCl
}
public void testOverview() throws Exception {
testMethod("emailOverview", "overview", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
testMethod("getEmailOverview", "overview", "POST", true, ReturnEmptySetOnNotFoundOr404.class);
}
public void testCreateAccount() throws Exception {

View File

@ -20,13 +20,14 @@ package org.jclouds.glesys.features;
import com.google.common.base.Predicate;
import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.options.EmailCreateOptions;
import org.jclouds.glesys.options.EmailEditOptions;
import org.jclouds.glesys.options.ServerDestroyOptions;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -37,7 +38,7 @@ import static org.testng.Assert.*;
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "EmailClientLiveTest")
@Test(groups = "live", testName = "EmailClientLiveTest", singleThreaded = true)
public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
@BeforeGroups(groups = {"live"})
@ -47,15 +48,16 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
try {
client.delete("test@" + testDomain);
client.delete("test2@" + testDomain);
context.getApi().getDomainClient().deleteDomain(testDomain);
} catch(Exception e) {
}
serverId = createServer("test-email-jclouds").getServerId();
createDomain(testDomain);
domainCounter = new RetryablePredicate<Integer>(
emailAccountCounter = new RetryablePredicate<Integer>(
new Predicate<Integer>() {
public boolean apply(Integer value) {
return client.listAccounts(testDomain).size() == value;
@ -68,26 +70,36 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
@AfterGroups(groups = {"live"})
public void tearDown() {
client.delete("test@" + testDomain);
assertTrue(emailAccountCounter.apply(0));
context.getApi().getDomainClient().deleteDomain(testDomain);
context.getApi().getServerClient().destroyServer(serverId, 0);
context.getApi().getServerClient().destroyServer(serverId, ServerDestroyOptions.Builder.discardIp());
super.tearDown();
}
private EmailClient client;
private String serverId;
private final String testDomain = "email-test.jclouds.org";
private RetryablePredicate<Integer> domainCounter;
private RetryablePredicate<Integer> emailAccountCounter;
@Test
public void createEmail() {
int before = client.listAccounts(testDomain).size();
client.createAccount("test@" + testDomain, "password");
assertTrue(domainCounter.apply(before + 1));
client.createAccount("test@" + testDomain, "password", EmailCreateOptions.Builder.antiVirus(true));
assertTrue(emailAccountCounter.apply(1));
}
@Test(dependsOnMethods = "createEmail")
public void createAlias() {
client.createAlias("test2@" + testDomain, "test@" + testDomain);
EmailOverview overview = client.getEmailOverview();
assertTrue(overview.getSummary().getAliases() == 1);
client.delete("test2@" + testDomain);
overview = client.getEmailOverview();
assertTrue(overview.getSummary().getAliases() == 0);
}
@Test(dependsOnMethods = "createEmail")
public void testOverview() throws Exception {
EmailOverview overview = client.emailOverview();
EmailOverview overview = client.getEmailOverview();
assertNotNull(overview.getSummary());
assertTrue(overview.getSummary().getAccounts() >= 1);
assertTrue(overview.getSummary().getAliases() == 0);
@ -108,8 +120,16 @@ public class EmailClientLiveTest extends BaseGleSYSClientLiveTest {
@Test(dependsOnMethods = "createEmail")
public void testEditAccount() throws Exception {
client.editAccount("test@" + testDomain, EmailEditOptions.Builder.antiVirus(false));
Set<Email> accounts = client.listAccounts(testDomain);
for(Email account : accounts) {
if (account.getAccount().equals("test@" + testDomain)) {
assertTrue(account.getAntiVirus());
}
}
client.editAccount("test@" + testDomain, EmailEditOptions.Builder.antiVirus(false));
accounts = client.listAccounts(testDomain);
for(Email account : accounts) {
if (account.getAccount().equals("test@" + testDomain)) {
assertFalse(account.getAntiVirus());

View File

@ -120,6 +120,11 @@ public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest<ServerAsync
testMethod("rebootServer", "reboot", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly);
}
public void testDestroyServer() throws Exception {
testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.keepIp());
testMethod("destroyServer", "destroy", "POST", false, MapHttp4xxCodesToExceptions.class, serverIdOnly, ServerDestroyOptions.Builder.discardIp());
}
@Override
protected TypeLiteral<RestAnnotationProcessor<ServerAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<ServerAsyncClient>>() {

View File

@ -21,10 +21,12 @@ package org.jclouds.glesys.features;
import com.google.common.base.Predicate;
import org.jclouds.glesys.domain.*;
import org.jclouds.glesys.options.ServerCloneOptions;
import org.jclouds.glesys.options.ServerDestroyOptions;
import org.jclouds.glesys.options.ServerStatusOptions;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import java.util.Map;
@ -48,24 +50,29 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
public void setupClient() {
super.setupClient();
client = context.getApi().getServerClient();
runningServerCounter = createServer(testHostName1);
testServerId = runningServerCounter.getServerId();
serverStatusChecker = createServer(testHostName1);
testServerId = serverStatusChecker.getServerId();
}
@AfterGroups(groups = {"live"})
public void tearDown() {
client.destroyServer(testServerId, 0);
client.destroyServer(testServerId, ServerDestroyOptions.Builder.discardIp());
if (testServerId2 != null) {
client.destroyServer(testServerId2, 0);
client.destroyServer(testServerId2, ServerDestroyOptions.Builder.discardIp());
}
super.tearDown();
}
private ServerClient client;
private ServerStatusChecker runningServerCounter;
private ServerStatusChecker serverStatusChecker;
private String testServerId;
private String testServerId2;
@BeforeMethod
public void makeSureServerIsRunning() throws Exception {
serverStatusChecker.apply(ServerState.RUNNING);
}
@Test
public void testAllowedArguments() throws Exception {
Map<String,ServerAllowedArguments> templates = client.getServerAllowedArguments();
@ -137,7 +144,7 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
checkStatus(newStatus);
}
@Test(enabled=false) // TODO tricksy
@Test(enabled=false) // TODO work a better plan
public void testRebootServer() throws Exception {
long uptime = 0;
@ -148,23 +155,25 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assertTrue(uptime > 19);
client.rebootServer(testServerId);
Thread.sleep(1000);
uptime = client.getServerStatus(testServerId).getUptime();
assertTrue(uptime < 20);
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
assertTrue(serverStatusChecker.apply(ServerState.RUNNING));
}
@Test
@Test(enabled=false) // TODO
public void testStopAndStartServer() throws Exception {
client.stopServer(testServerId);
assertTrue(runningServerCounter.apply(ServerState.STOPPED));
assertTrue(serverStatusChecker.apply(ServerState.STOPPED));
client.startServer(testServerId);
assertTrue(runningServerCounter.apply(ServerState.RUNNING));
assertTrue(serverStatusChecker.apply(ServerState.RUNNING));
}
@ -184,8 +193,7 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
}
}
// TODO in progress
@Test(enabled=false)
@Test
public void testServerConsole() throws Exception {
ServerConsole console = client.getServerConsole(testServerId);
assertNotNull(console);
@ -194,7 +202,7 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
assertNotNull(console.getPassword());
}
// takes a few minutes
// takes a few minutes and requires an extra server (using 2 already)
@Test(enabled=false)
public void testCloneServer() throws Exception {
ServerCreated testServer2 = client.cloneServer(testServerId, testHostName2, ServerCloneOptions.Builder.cpucores(1));
@ -206,7 +214,6 @@ public class ServerClientLiveTest extends BaseGleSYSClientLiveTest {
testServerId2 = testServer2.getId();
RetryablePredicate<ServerState> cloneChecker = new ServerStatusChecker(client, testServerId2, 300, 10, TimeUnit.SECONDS);
assertTrue(cloneChecker.apply(ServerState.STOPPED));
client.startServer(testServer2.getId());