From 950e56e3277ff51197163212378796e1c41e87bd Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Thu, 21 May 2009 16:08:31 +0000 Subject: [PATCH] Issue 26 git-svn-id: http://jclouds.googlecode.com/svn/trunk@822 3d8758e0-26b5-11de-8745-db77d3ebf521 --- aws/s3/core/pom.xml | 104 ------------------ aws/s3/pom.xml | 104 ++++++++++++++++++ aws/s3/samples/googleappengine/pom.xml | 73 ++++++++---- .../googleappengine/JCloudsServlet.java | 76 +++++++------ .../config/GuiceServletConfig.java | 80 +++++++------- ...Test.java => GoogleAppEngineLiveTest.java} | 83 +++++++------- ...ppEngineTest.java => GoogleDevServer.java} | 57 +++++----- extensions/gae/pom.xml | 6 +- 8 files changed, 304 insertions(+), 279 deletions(-) rename aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/{GoogleAppEngineTest.java => GoogleAppEngineLiveTest.java} (52%) rename aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/{BaseGoogleAppEngineTest.java => GoogleDevServer.java} (56%) diff --git a/aws/s3/core/pom.xml b/aws/s3/core/pom.xml index d49b07937d..302a380ba5 100644 --- a/aws/s3/core/pom.xml +++ b/aws/s3/core/pom.xml @@ -72,108 +72,4 @@ test - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.4.3 - - - integration - integration-test - - test - - - - - **/*LiveTest.java - - - **/*IntegrationTest.java - - - - jclouds.s3.httpstream.url - ${jclouds.s3.httpstream.url} - - - jclouds.s3.httpstream.md5 - ${jclouds.s3.httpstream.md5} - - - - - - - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.4.3 - - - integration - integration-test - - test - - - - - none - - - **/*IntegrationTest.java - **/*LiveTest.java - - - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - - - jclouds.s3.httpstream.url - ${jclouds.s3.httpstream.url} - - - jclouds.s3.httpstream.md5 - ${jclouds.s3.httpstream.md5} - - - - - - - - - - diff --git a/aws/s3/pom.xml b/aws/s3/pom.xml index 327463ad92..f413a1cd73 100644 --- a/aws/s3/pom.xml +++ b/aws/s3/pom.xml @@ -43,4 +43,108 @@ extensions samples + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4.3 + + + integration + integration-test + + test + + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + jclouds.s3.httpstream.url + ${jclouds.s3.httpstream.url} + + + jclouds.s3.httpstream.md5 + ${jclouds.s3.httpstream.md5} + + + + + + + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.4.3 + + + integration + integration-test + + test + + + + + none + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + jclouds.aws.accesskeyid + ${jclouds.aws.accesskeyid} + + + jclouds.aws.secretaccesskey + ${jclouds.aws.secretaccesskey} + + + jclouds.s3.httpstream.url + ${jclouds.s3.httpstream.url} + + + jclouds.s3.httpstream.md5 + ${jclouds.s3.httpstream.md5} + + + + + + + + + + diff --git a/aws/s3/samples/googleappengine/pom.xml b/aws/s3/samples/googleappengine/pom.xml index 3bb3f48d2b..99bac2367e 100644 --- a/aws/s3/samples/googleappengine/pom.xml +++ b/aws/s3/samples/googleappengine/pom.xml @@ -41,11 +41,9 @@ - /Users/adriancole/Desktop/appengine-java-sdk-1.2.0 + /Users/adriancole/Desktop/appengine-java-sdk-1.2.1 localhost 8088 - - @@ -95,7 +93,7 @@ com.google.appengine appengine-tools-api - 1.2.0 + 1.2.1 system ${appengine.home}/lib/appengine-tools-api.jar @@ -103,12 +101,10 @@ ${project.artifactId} - src/it/java org.apache.maven.plugins maven-surefire-plugin - 2.4.3 integration @@ -117,16 +113,7 @@ test - target/test-classes - - jclouds.aws.accesskeyid - ${jclouds.aws.accesskeyid} - - - jclouds.aws.secretaccesskey - ${jclouds.aws.secretaccesskey} - appengine.home ${appengine.home} @@ -157,12 +144,58 @@ - - - target/classes - - + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + + jclouds.aws.accesskeyid + ${jclouds.aws.accesskeyid} + + + jclouds.aws.secretaccesskey + ${jclouds.aws.secretaccesskey} + + + appengine.home + ${appengine.home} + + + devappserver.address + ${devappserver.address} + + + devappserver.port + ${devappserver.port} + + + warfile + ${project.build.directory}/${project.artifactId} + + + + + + + + + + diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java index aac9157983..5aadeaf1ec 100644 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/JCloudsServlet.java @@ -23,28 +23,26 @@ */ package org.jclouds.samples.googleappengine; -import java.io.IOException; -import java.io.Writer; -import java.util.List; -import java.util.concurrent.TimeUnit; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.jclouds.aws.s3.S3Context; +import org.jclouds.aws.s3.S3ResponseException; +import org.jclouds.aws.s3.domain.S3Bucket; +import org.jclouds.logging.Logger; import javax.annotation.Resource; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - -import org.jclouds.aws.s3.S3Context; -import org.jclouds.aws.s3.S3ResponseException; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.logging.Logger; - -import com.google.inject.Inject; -import com.google.inject.Singleton; +import java.io.IOException; +import java.io.Writer; +import java.util.List; +import java.util.concurrent.TimeUnit; /** * Shows an example of how to use @{link S3Connection} injected with Guice. - * + * * @author Adrian Cole */ @Singleton @@ -59,32 +57,32 @@ public class JCloudsServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest httpServletRequest, - HttpServletResponse httpServletResponse) throws ServletException, - IOException { - httpServletResponse.setContentType("text/plain"); - Writer writer = httpServletResponse.getWriter(); - try { - List myBuckets = context.getConnection() - .listOwnedBuckets().get(10, TimeUnit.SECONDS); - writer.write("List:\n"); - for (S3Bucket.Metadata bucket : myBuckets) { - writer.write(String.format(" %1$s", bucket)); - try { - writer.write(String.format(": %1$s entries%n", context - .createInputStreamMap(bucket.getName()).size())); - } catch (S3ResponseException e) { - String message = String.format( - ": unable to list entries due to: %1$s%n", e - .getError().getCode()); - writer.write(message); - logger.warn(e, "message"); - } + HttpServletResponse httpServletResponse) throws ServletException, + IOException { + httpServletResponse.setContentType("text/plain"); + Writer writer = httpServletResponse.getWriter(); + try { + List myBuckets = context.getConnection() + .listOwnedBuckets().get(10, TimeUnit.SECONDS); + writer.write("List:\n"); + for (S3Bucket.Metadata bucket : myBuckets) { + writer.write(String.format(" %1$s", bucket)); + try { + writer.write(String.format(": %1$s entries%n", context + .createInputStreamMap(bucket.getName()).size())); + } catch (S3ResponseException e) { + String message = String.format( + ": unable to list entries due to: %1$s%n", e + .getError().getCode()); + writer.write(message); + logger.warn(e, "message"); + } - } - } catch (Exception e) { - throw new ServletException(e); - } - writer.flush(); - writer.close(); + } + } catch (Exception e) { + throw new ServletException(e); + } + writer.flush(); + writer.close(); } } \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java index e5e0900c89..ca5ad9dd49 100644 --- a/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java +++ b/aws/s3/samples/googleappengine/src/main/java/org/jclouds/samples/googleappengine/config/GuiceServletConfig.java @@ -23,12 +23,10 @@ */ package org.jclouds.samples.googleappengine.config; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; - -import javax.servlet.ServletContextEvent; - +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.servlet.GuiceServletContextListener; +import com.google.inject.servlet.ServletModule; import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.S3Context; import org.jclouds.aws.s3.S3ContextFactory; @@ -36,17 +34,15 @@ import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.gae.config.URLFetchServiceClientModule; import org.jclouds.samples.googleappengine.JCloudsServlet; - -import com.google.inject.Inject; -import com.google.inject.Injector; -import com.google.inject.servlet.GuiceServletContextListener; -import com.google.inject.servlet.ServletModule; +import javax.servlet.ServletContextEvent; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; /** * Setup Logging and create Injector for use in testing S3. - * + * * @author Adrian Cole - * */ public class GuiceServletConfig extends GuiceServletContextListener { @Inject @@ -56,45 +52,45 @@ public class GuiceServletConfig extends GuiceServletContextListener { @Override public void contextInitialized(ServletContextEvent servletContextEvent) { - Properties props = loadJCloudsProperties(servletContextEvent); - this.accessKeyId = props - .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - this.secretAccessKey = props - .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - super.contextInitialized(servletContextEvent); + Properties props = loadJCloudsProperties(servletContextEvent); + this.accessKeyId = props + .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); + this.secretAccessKey = props + .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + super.contextInitialized(servletContextEvent); } private Properties loadJCloudsProperties( - ServletContextEvent servletContextEvent) { - InputStream input = servletContextEvent.getServletContext() - .getResourceAsStream("/WEB-INF/jclouds.properties"); - Properties props = new Properties(); - try { - props.load(input); - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - IOUtils.closeQuietly(input); - } - return props; + ServletContextEvent servletContextEvent) { + InputStream input = servletContextEvent.getServletContext() + .getResourceAsStream("/WEB-INF/jclouds.properties"); + Properties props = new Properties(); + try { + props.load(input); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + IOUtils.closeQuietly(input); + } + return props; } @Override protected Injector getInjector() { - return S3ContextFactory.createInjector(accessKeyId, secretAccessKey, - false, new URLFetchServiceClientModule(), - new ServletModule() { - @Override - protected void configureServlets() { - serve("*.s3").with(JCloudsServlet.class); - requestInjection(this); - } - }); + return S3ContextFactory.createInjector(accessKeyId, secretAccessKey, + false, new URLFetchServiceClientModule(), + new ServletModule() { + @Override + protected void configureServlets() { + serve("*.s3").with(JCloudsServlet.class); + requestInjection(this); + } + }); } @Override public void contextDestroyed(ServletContextEvent servletContextEvent) { - context.close(); - super.contextDestroyed(servletContextEvent); + context.close(); + super.contextDestroyed(servletContextEvent); } } \ No newline at end of file diff --git a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java similarity index 52% rename from aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java rename to aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java index 51240ae7f3..4b876b84c7 100644 --- a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineTest.java +++ b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleAppEngineLiveTest.java @@ -24,12 +24,6 @@ package org.jclouds.samples.googleappengine.functest; import static com.google.common.base.Preconditions.checkNotNull; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Properties; - import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.reference.S3Constants; import org.testng.annotations.BeforeTest; @@ -37,65 +31,74 @@ import org.testng.annotations.Optional; import org.testng.annotations.Parameters; import org.testng.annotations.Test; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; + /** * Starts up the Google App Engine for Java Development environment and deploys * an application which tests S3. - * + * * @author Adrian Cole - * */ -@Test(groups = "integration", enabled = true, sequential = true, testName = "functionalTests") -public class GoogleAppEngineTest extends BaseGoogleAppEngineTest { +@Test(groups = "live", sequential = true, testName = "functionalTests") +public class GoogleAppEngineLiveTest { + GoogleDevServer server; private static final String sysAWSAccessKeyId = System - .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); + .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); private static final String sysAWSSecretAccessKey = System - .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + private URL url; @BeforeTest - @Parameters( { "warfile", "devappserver.address", "devappserver.port", - S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) + @Parameters({"warfile", "devappserver.address", "devappserver.port", + S3Constants.PROPERTY_AWS_ACCESSKEYID, + S3Constants.PROPERTY_AWS_SECRETACCESSKEY}) public void startDevAppServer(final String warfile, final String address, - final String port, @Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey) throws Exception { - AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId - : sysAWSAccessKeyId; - AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey - : sysAWSSecretAccessKey; + final String port, @Optional String AWSAccessKeyId, + @Optional String AWSSecretAccessKey) throws Exception { + url = new URL(String.format("http://%1$s:%2$s", address, port)); - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId"); - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey"); + AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId + : sysAWSAccessKeyId; + AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey + : sysAWSSecretAccessKey; - Properties props = new Properties(); - props.put(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); - props.put(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); - writePropertiesAndStartServer(address, port, warfile, props); + checkNotNull(AWSAccessKeyId, "AWSAccessKeyId"); + checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey"); + + Properties props = new Properties(); + props.put(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); + props.put(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); + server = new GoogleDevServer(); + server.writePropertiesAndStartServer(address, port, warfile, props); } @Test public void shouldPass() throws InterruptedException, IOException { - InputStream i = url.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("Hello World!") >= 0 : string; + InputStream i = url.openStream(); + String string = IOUtils.toString(i); + assert string.indexOf("Hello World!") >= 0 : string; } @Test(invocationCount = 5, enabled = true) public void testGuiceJCloudsSerial() throws InterruptedException, - IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); - InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("List") >= 0 : string; + IOException { + URL gurl = new URL(url, "/guice/listbuckets.s3"); + InputStream i = gurl.openStream(); + String string = IOUtils.toString(i); + assert string.indexOf("List") >= 0 : string; } @Test(invocationCount = 50, enabled = true, threadPoolSize = 10) public void testGuiceJCloudsParallel() throws InterruptedException, - IOException { - URL gurl = new URL(url, "/guice/listbuckets.s3"); - InputStream i = gurl.openStream(); - String string = IOUtils.toString(i); - assert string.indexOf("List") >= 0 : string; + IOException { + URL gurl = new URL(url, "/guice/listbuckets.s3"); + InputStream i = gurl.openStream(); + String string = IOUtils.toString(i); + assert string.indexOf("List") >= 0 : string; } } diff --git a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java similarity index 56% rename from aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java rename to aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java index d96d535231..c4069f1dfb 100644 --- a/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/BaseGoogleAppEngineTest.java +++ b/aws/s3/samples/googleappengine/src/test/java/org/jclouds/samples/googleappengine/functest/GoogleDevServer.java @@ -23,53 +23,48 @@ */ package org.jclouds.samples.googleappengine.functest; -import java.io.FileNotFoundException; +import com.google.appengine.tools.KickStart; + import java.io.FileOutputStream; import java.io.IOException; -import java.net.URL; +import java.io.File; import java.util.Properties; -import org.testng.annotations.AfterTest; - -import com.google.appengine.tools.KickStart; - /** * Basic functionality to start a local google app engine instance. - * + * * @author Adrian Cole - * */ -public abstract class BaseGoogleAppEngineTest { +public class GoogleDevServer { Thread server; - URL url; - protected void writePropertiesAndStartServer(final String address, - final String port, final String warfile, Properties props) - throws IOException, FileNotFoundException, InterruptedException { - url = new URL(String.format("http://%1$s:%2$s", address, port)); + public void writePropertiesAndStartServer(final String address, + final String port, final String warfile, Properties props) + throws IOException, InterruptedException { + String filename = String.format( + "%1$s/WEB-INF/jclouds.properties", warfile); + System.err.println("file: " + filename); + props.store(new FileOutputStream(filename), "test"); + assert new File(filename).exists(); + this.server = new Thread(new Runnable() { + public void run() { + KickStart + .main(new String[]{ + "com.google.appengine.tools.development.DevAppServerMain", + "--disable_update_check", "-a", address, "-p", + port, warfile}); - props.store(new FileOutputStream(String.format( - "%1$s/WEB-INF/jclouds.properties", warfile)), "test"); - this.server = new Thread(new Runnable() { - public void run() { - KickStart - .main(new String[] { - "com.google.appengine.tools.development.DevAppServerMain", - "--disable_update_check", "-a", address, "-p", - port, warfile }); + } - } - - }); - server.start(); - Thread.sleep(7 * 1000); + }); + server.start(); + Thread.sleep(10 * 1000); } @SuppressWarnings("deprecation") - @AfterTest - public void stopDevAppServer() throws Exception { - server.stop(); + public void stop() throws Exception { + server.stop(); } } \ No newline at end of file diff --git a/extensions/gae/pom.xml b/extensions/gae/pom.xml index 474372d2ce..5d2ccf8347 100644 --- a/extensions/gae/pom.xml +++ b/extensions/gae/pom.xml @@ -50,18 +50,18 @@ com.google.appengine appengine-api - 1.2.0 + 1.2.1 com.google.appengine appengine-api-stubs - 1.2.0 + 1.2.1 test com.google.appengine appengine-local-runtime - 1.2.0 + 1.2.1 test