From 0c2918abdc55a0c9061885cecf65ed671c9f4544 Mon Sep 17 00:00:00 2001 From: Adam Lowe Date: Fri, 23 Dec 2011 00:42:17 +0000 Subject: [PATCH] Improving live tests --- .../glesys/features/ArchiveAsyncClient.java | 6 +-- .../glesys/features/ArchiveClient.java | 4 +- .../glesys/features/EmailAsyncClient.java | 2 +- .../jclouds/glesys/features/EmailClient.java | 2 +- .../glesys/features/ServerAsyncClient.java | 4 +- .../jclouds/glesys/features/ServerClient.java | 4 +- .../glesys/options/ServerDestroyOptions.java | 35 ++++++++++++++++ .../features/ArchiveAsyncClientTest.java | 4 +- .../features/ArchiveClientLiveTest.java | 11 +++-- .../features/BaseGleSYSClientLiveTest.java | 2 +- .../glesys/features/DomainClientLiveTest.java | 2 +- .../glesys/features/EmailAsyncClientTest.java | 2 +- .../glesys/features/EmailClientLiveTest.java | 42 ++++++++++++++----- .../features/ServerAsyncClientTest.java | 5 +++ .../glesys/features/ServerClientLiveTest.java | 37 +++++++++------- 15 files changed, 114 insertions(+), 48 deletions(-) create mode 100644 sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerDestroyOptions.java diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java index 257672179f..4098ebeade 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveAsyncClient.java @@ -55,14 +55,14 @@ public interface ArchiveAsyncClient { ListenableFuture> listArchives(); /** - * @see ArchiveClient#archiveDetails + * @see ArchiveClient#getArchiveDetails */ @POST @Path("/archive/details/format/json") @SelectJson("details") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnNullOnNotFoundOr404.class) - ListenableFuture archiveDetails(@FormParam("username") String username); + ListenableFuture getArchiveDetails(@FormParam("username") String username); /** * @see ArchiveClient#createArchive @@ -84,7 +84,7 @@ public interface ArchiveAsyncClient { */ @POST @Path("/archive/resize/format/json") - ListenableFuture resizeArchive(@FormParam("username") String username, @FormParam("size")int size); + ListenableFuture resizeArchive(@FormParam("username") String username, @FormParam("size") int size); /** * @see ArchiveClient#changeArchivePassword */ diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java index 039fb52a91..5180763cde 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ArchiveClient.java @@ -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); diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java index 267f5ad08d..afb20a89e9 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailAsyncClient.java @@ -52,7 +52,7 @@ public interface EmailAsyncClient { @SelectJson("response") @Consumes(MediaType.APPLICATION_JSON) @ExceptionParser(ReturnEmptySetOnNotFoundOr404.class) - ListenableFuture emailOverview(); + ListenableFuture getEmailOverview(); /** * @see org.jclouds.glesys.features.EmailClient#listAccounts diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java index 2fc29e6b29..a0081fe4d2 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/EmailClient.java @@ -44,7 +44,7 @@ public interface EmailClient { * * @return the relevant summary data */ - EmailOverview emailOverview(); + EmailOverview getEmailOverview(); /** * diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java index df12c4c4d0..da0ae14357 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerAsyncClient.java @@ -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 getServerConsole(@FormParam("serverid") String id); @@ -183,7 +183,7 @@ public interface ServerAsyncClient { */ @POST @Path("/server/destroy/format/json") - ListenableFuture destroyServer(@FormParam("serverid") String id, @FormParam("keepip") int keepIp); + ListenableFuture destroyServer(@FormParam("serverid") String id, ServerDestroyOptions keepIp); /** * @see ServerClient#resetPassword diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java index 554af8d627..7c01159485 100644 --- a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/features/ServerClient.java @@ -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 diff --git a/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerDestroyOptions.java b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerDestroyOptions.java new file mode 100644 index 0000000000..b018472fe6 --- /dev/null +++ b/sandbox-providers/glesys/src/main/java/org/jclouds/glesys/options/ServerDestroyOptions.java @@ -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; + } +} \ No newline at end of file diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java index 6c6c7bd991..1b9f93da17 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ArchiveAsyncClientTest.java @@ -47,7 +47,7 @@ public class ArchiveAsyncClientTest extends BaseGleSYSAsyncClientTest( new Predicate() { 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")); } diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientLiveTest.java index 6973b908d6..4e607f4fc9 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/BaseGleSYSClientLiveTest.java @@ -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; diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java index 58d3dff335..57c939c55d 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/DomainClientLiveTest.java @@ -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"; diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java index 6ba5679b76..c2af44c68f 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/EmailAsyncClientTest.java @@ -44,7 +44,7 @@ public class EmailAsyncClientTest extends BaseGleSYSAsyncClientTest( + emailAccountCounter = new RetryablePredicate( new Predicate() { 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 domainCounter; + private RetryablePredicate 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 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()); diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java index 8a659e62a7..4a81ea9a00 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerAsyncClientTest.java @@ -120,6 +120,11 @@ public class ServerAsyncClientTest extends BaseGleSYSAsyncClientTest> createTypeLiteral() { return new TypeLiteral>() { diff --git a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java index bd570ff728..ee0230ebdf 100644 --- a/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java +++ b/sandbox-providers/glesys/src/test/java/org/jclouds/glesys/features/ServerClientLiveTest.java @@ -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 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 cloneChecker = new ServerStatusChecker(client, testServerId2, 300, 10, TimeUnit.SECONDS); - assertTrue(cloneChecker.apply(ServerState.STOPPED)); client.startServer(testServer2.getId());