diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java index 84ea134b1d..3004c4c00c 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/internal/BaseS3Map.java @@ -24,9 +24,19 @@ package org.jclouds.aws.s3.internal; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.inject.Inject; -import com.google.inject.assistedinject.Assisted; -import com.google.inject.name.Named; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + import org.jclouds.aws.s3.S3Connection; import org.jclouds.aws.s3.S3Map; import org.jclouds.aws.s3.domain.S3Bucket; @@ -34,203 +44,213 @@ import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.util.Utils; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Inject; +import com.google.inject.assistedinject.Assisted; +import com.google.inject.name.Named; /** * Implements core Map functionality with an {@link S3Connection} *

- * All commands will wait a maximum of ${jclouds.s3.map.timeout} milliseconds to - * complete before throwing an exception. - * + * All commands will wait a maximum of ${jclouds.s3.map.timeout} milliseconds to complete before + * throwing an exception. + * * @author Adrian Cole * @param - * value of the map + * value of the map */ public abstract class BaseS3Map implements S3Map { - protected final S3Connection connection; - protected final String bucket; + protected final S3Connection connection; + protected final String bucket; - /** - * maximum duration of an S3 Request - */ - @Inject(optional = true) - @Named(S3Constants.PROPERTY_S3_MAP_TIMEOUT) - protected long requestTimeoutMilliseconds = 10000; + /** + * maximum duration of an S3 Request + */ + @Inject(optional = true) + @Named(S3Constants.PROPERTY_S3_MAP_TIMEOUT) + protected long requestTimeoutMilliseconds = 10000; - @Inject - public BaseS3Map(S3Connection connection, @Assisted String bucket) { - this.connection = checkNotNull(connection, "connection"); - this.bucket = checkNotNull(bucket, "bucketName"); - } + /** + * time to pause before retrying a transient failure + */ + @Inject(optional = true) + @Named(S3Constants.PROPERTY_S3_MAP_RETRY) + protected long requestRetryMilliseconds = 10; - /** - * {@inheritDoc} - *

- * This returns the number of keys in the {@link S3Bucket} - * - * @see S3Bucket#getContents() - */ - public int size() { - try { - S3Bucket bucket = refreshBucket(); - Set contents = bucket.getContents(); - return contents.size(); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting size of bucketName" - + bucket, e); - } - } + @Inject + public BaseS3Map(S3Connection connection, @Assisted String bucket) { + this.connection = checkNotNull(connection, "connection"); + this.bucket = checkNotNull(bucket, "bucketName"); + } - protected boolean containsMd5(byte[] md5) throws InterruptedException, - ExecutionException, TimeoutException { - for (S3Object.Metadata metadata : refreshBucket().getContents()) { - if (Arrays.equals(md5, metadata.getMd5())) - return true; - } - return false; - } + /** + * {@inheritDoc} + *

+ * This returns the number of keys in the {@link S3Bucket} + * + * @see S3Bucket#getContents() + */ + public int size() { + try { + S3Bucket bucket = refreshBucket(); + Set contents = bucket.getContents(); + return contents.size(); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException("Error getting size of bucketName" + bucket, e); + } + } - protected byte[] getMd5(Object value) throws IOException, - FileNotFoundException, InterruptedException, ExecutionException, + protected boolean containsMd5(byte[] md5) throws InterruptedException, ExecutionException, TimeoutException { - S3Object object = null; - if (value instanceof S3Object) { - object = (S3Object) value; - } else { - object = new S3Object("dummy", value); - } - if (object.getMetadata().getMd5() == null) - object.generateMd5(); - return object.getMetadata().getMd5(); - } + for (S3Object.Metadata metadata : refreshBucket().getContents()) { + if (Arrays.equals(md5, metadata.getMd5())) + return true; + } + return false; + } - /** - * attempts asynchronous gets on all objects. - * - * @see S3Connection#getObject(String, String) - */ - protected Set getAllObjects() { - Set objects = new HashSet(); - Set> futureObjects = new HashSet>(); - for (String key : keySet()) { - futureObjects.add(connection.getObject(bucket, key)); - } - for (Future futureObject : futureObjects) { - S3Object object = null; - try { - object = futureObject.get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error getting value from bucket %1$s", bucket), e); + protected byte[] getMd5(Object value) throws IOException, FileNotFoundException, + InterruptedException, ExecutionException, TimeoutException { + S3Object object = null; + if (value instanceof S3Object) { + object = (S3Object) value; + } else { + object = new S3Object("dummy", value); + } + if (object.getMetadata().getMd5() == null) + object.generateMd5(); + return object.getMetadata().getMd5(); + } + + /** + * attempts asynchronous gets on all objects. + * + * @see S3Connection#getObject(String, String) + */ + protected Set getAllObjects() { + Set objects = new HashSet(); + Set> futureObjects = new HashSet>(); + for (String key : keySet()) { + futureObjects.add(connection.getObject(bucket, key)); + } + for (Future futureObject : futureObjects) { + try { + ifNotFoundRetryOtherwiseAddToSet(futureObject, objects); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException(String.format("Error getting value from bucket %1$s", + bucket), e); + } + + } + return objects; + } + + @VisibleForTesting + void ifNotFoundRetryOtherwiseAddToSet(Future futureObject, Set objects) + throws InterruptedException, ExecutionException, TimeoutException { + for (int i = 0; i < 3; i++) { + S3Object object = futureObject.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); + if (object != S3Object.NOT_FOUND) { + objects.add(object); + break; + } else { + Thread.sleep(requestRetryMilliseconds); + } + } + } + + /** + * {@inheritDoc} + *

+ * Note that if value is an instance of InputStream, it will be read and closed following this + * method. To reuse data from InputStreams, pass {@link java.io.InputStream}s inside + * {@link S3Object}s + */ + public boolean containsValue(Object value) { + try { + byte[] md5 = getMd5(value); + return containsMd5(md5); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException(String.format( + "Error searching for ETAG of value: [%2$s] in bucketName:%1$s", bucket, value), e); + } + } + + public static class S3RuntimeException extends RuntimeException { + private static final long serialVersionUID = 1L; + + S3RuntimeException(String s) { + super(s); + } + + public S3RuntimeException(String s, Throwable throwable) { + super(s, throwable); + } + } + + public void clear() { + try { + List> deletes = new ArrayList>(); + for (String key : keySet()) { + deletes.add(connection.deleteObject(bucket, key)); + } + for (Future isdeleted : deletes) + if (!isdeleted.get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)) { + throw new S3RuntimeException("failed to delete entry"); } - if (object != S3Object.NOT_FOUND) - objects.add(object); - } - return objects; - } + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException("Error clearing bucketName" + bucket, e); + } + } - /** - * {@inheritDoc} - *

- * Note that if value is an instance of InputStream, it will be read and - * closed following this method. To reuse data from InputStreams, pass - * {@link java.io.InputStream}s inside {@link S3Object}s - */ - public boolean containsValue(Object value) { - try { - byte[] md5 = getMd5(value); - return containsMd5(md5); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error searching for ETAG of value: [%2$s] in bucketName:%1$s", - bucket, value), e); - } - } + protected S3Bucket refreshBucket() throws InterruptedException, ExecutionException, + TimeoutException { + S3Bucket currentBucket = connection.listBucket(bucket).get(requestTimeoutMilliseconds, + TimeUnit.MILLISECONDS); + if (currentBucket == S3Bucket.NOT_FOUND) + throw new S3RuntimeException("bucketName not found: " + bucket); + else + return currentBucket; + } - public static class S3RuntimeException extends RuntimeException { - private static final long serialVersionUID = 1L; + public Set keySet() { + try { + Set keys = new HashSet(); + for (S3Object.Metadata object : refreshBucket().getContents()) + keys.add(object.getKey()); + return keys; + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException("Error getting keys in bucketName: " + bucket, e); + } + } - S3RuntimeException(String s) { - super(s); - } + public boolean containsKey(Object key) { + try { + return connection.headObject(bucket, key.toString()).get(requestTimeoutMilliseconds, + TimeUnit.MILLISECONDS) != S3Object.Metadata.NOT_FOUND; + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException(String.format("Error searching for %1$s:%2$s", bucket, key), + e); + } + } - public S3RuntimeException(String s, Throwable throwable) { - super(s, throwable); - } - } + public boolean isEmpty() { + return keySet().size() == 0; + } - public void clear() { - try { - List> deletes = new ArrayList>(); - for (String key : keySet()) { - deletes.add(connection.deleteObject(bucket, key)); - } - for (Future isdeleted : deletes) - if (!isdeleted.get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS)) { - throw new S3RuntimeException("failed to delete entry"); - } - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error clearing bucketName" + bucket, e); - } - } - - protected S3Bucket refreshBucket() throws InterruptedException, - ExecutionException, TimeoutException { - S3Bucket currentBucket = connection.listBucket(bucket).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - if (currentBucket == S3Bucket.NOT_FOUND) - throw new S3RuntimeException("bucketName not found: " + bucket); - else - return currentBucket; - } - - public Set keySet() { - try { - Set keys = new HashSet(); - for (S3Object.Metadata object : refreshBucket().getContents()) - keys.add(object.getKey()); - return keys; - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting keys in bucketName: " - + bucket, e); - } - } - - public boolean containsKey(Object key) { - try { - return connection.headObject(bucket, key.toString()).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS) != S3Object.Metadata.NOT_FOUND; - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException(String.format( - "Error searching for %1$s:%2$s", bucket, key), e); - } - } - - public boolean isEmpty() { - return keySet().size() == 0; - } - - public S3Bucket getBucket() { - try { - return refreshBucket(); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3RuntimeException("Error getting bucketName" + bucket, e); - } - } + public S3Bucket getBucket() { + try { + return refreshBucket(); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3RuntimeException("Error getting bucketName" + bucket, e); + } + } } \ No newline at end of file diff --git a/aws/s3/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java b/aws/s3/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java index bdc188380e..7d3c6f37d8 100644 --- a/aws/s3/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java +++ b/aws/s3/core/src/main/java/org/jclouds/aws/s3/reference/S3Constants.java @@ -33,12 +33,15 @@ import org.jclouds.http.HttpConstants; */ public interface S3Constants extends HttpConstants, PoolConstants, S3Headers { - public static final String PROPERTY_AWS_SECRETACCESSKEY = "jclouds.aws.secretaccesskey"; - public static final String PROPERTY_AWS_ACCESSKEYID = "jclouds.aws.accesskeyid"; - /** - * longest time a single Map operation can take before throwing an - * exception. - */ - public static final String PROPERTY_S3_MAP_TIMEOUT = "jclouds.s3.map.timeout"; + public static final String PROPERTY_AWS_SECRETACCESSKEY = "jclouds.aws.secretaccesskey"; + public static final String PROPERTY_AWS_ACCESSKEYID = "jclouds.aws.accesskeyid"; + /** + * longest time a single Map operation can take before throwing an exception. + */ + public static final String PROPERTY_S3_MAP_TIMEOUT = "jclouds.s3.map.timeout"; + /** + * time to pause before retrying a transient failure + */ + public static final String PROPERTY_S3_MAP_RETRY = "jclouds.s3.map.retry"; } diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/PerformanceTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/PerformanceTest.java index fc19a4e7ac..6cad97f4b2 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/PerformanceTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/PerformanceTest.java @@ -23,31 +23,31 @@ */ package org.jclouds.aws; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ -@Test(groups = "performance", sequential = true, testName = "s3.PerformanceTest") +@Test(groups = "performance") public class PerformanceTest { - protected static int LOOP_COUNT = 1000; - protected ExecutorService exec; + protected static int LOOP_COUNT = 1000; + protected ExecutorService exec; - @BeforeMethod - public void setupExecutorService() { - exec = Executors.newCachedThreadPool(); - } + @BeforeTest + public void setupExecutorService() { + exec = Executors.newCachedThreadPool(); + } - @AfterMethod - public void teardownExecutorService() { - exec.shutdownNow(); - exec = null; - } + @AfterTest + public void teardownExecutorService() { + exec.shutdownNow(); + exec = null; + } } diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java index 204b78b6f8..a44932e101 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3ConnectionIntegrationTest.java @@ -24,71 +24,62 @@ package org.jclouds.aws.s3; import static com.google.common.base.Preconditions.checkNotNull; -import org.jclouds.aws.s3.domain.S3Bucket; -import org.jclouds.aws.s3.domain.S3Object; -import org.jclouds.aws.s3.util.S3Utils; import static org.testng.Assert.assertEquals; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; -import java.util.List; import java.util.concurrent.TimeUnit; +import org.jclouds.aws.s3.domain.S3Object; +import org.jclouds.aws.s3.util.S3Utils; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + /** * Tests connection by listing all the buckets and their size - * + * * @author Adrian Cole */ @Test(testName = "s3.S3ConnectionIntegrationTest") public class S3ConnectionIntegrationTest extends S3IntegrationTest { - @Test(groups = {"integration"}) - void testListBuckets() throws Exception { - List myBuckets = client.listOwnedBuckets().get(10, - TimeUnit.SECONDS); - for (S3Bucket.Metadata bucket : myBuckets) { - context.createInputStreamMap(bucket.getName()).size(); - } - } + @Test(groups = { "integration" }) + void testListBuckets() throws Exception { + client.listOwnedBuckets().get(10, TimeUnit.SECONDS); + } - private static final String sysHttpStreamUrl = System - .getProperty("jclouds.s3.httpstream.url"); - private static final String sysHttpStreamMd5 = System - .getProperty("jclouds.s3.httpstream.md5"); + private static final String sysHttpStreamUrl = System.getProperty("jclouds.s3.httpstream.url"); + private static final String sysHttpStreamMd5 = System.getProperty("jclouds.s3.httpstream.md5"); - @Test(groups = {"integration"}) - @Parameters({"jclouds.s3.httpstream.url", "jclouds.s3.httpstream.md5"}) - public void testCopyUrl(@Optional String httpStreamUrl, - @Optional String httpStreamMd5) throws Exception { - httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl - : sysHttpStreamUrl, "httpStreamUrl"); + @Test(groups = { "integration" }) + @Parameters( { "jclouds.s3.httpstream.url", "jclouds.s3.httpstream.md5" }) + public void testCopyUrl(@Optional String httpStreamUrl, @Optional String httpStreamMd5) + throws Exception { + httpStreamUrl = checkNotNull(httpStreamUrl != null ? httpStreamUrl : sysHttpStreamUrl, + "httpStreamUrl"); - httpStreamMd5 = checkNotNull(httpStreamMd5 != null ? httpStreamMd5 - : sysHttpStreamMd5, "httpStreamMd5"); + httpStreamMd5 = checkNotNull(httpStreamMd5 != null ? httpStreamMd5 : sysHttpStreamMd5, + "httpStreamMd5"); - String bucketName = bucketPrefix + "tcu"; - createBucketAndEnsureEmpty(bucketName); - String key = "hello"; + String bucketName = bucketPrefix + "tcu"; + createBucketAndEnsureEmpty(bucketName); + String key = "hello"; - URL url = new URL(httpStreamUrl); - byte[] md5 = S3Utils - .fromHexString(httpStreamMd5); + URL url = new URL(httpStreamUrl); + byte[] md5 = S3Utils.fromHexString(httpStreamMd5); - URLConnection connection = url.openConnection(); - int length = connection.getContentLength(); - InputStream input = connection.getInputStream(); + URLConnection connection = url.openConnection(); + int length = connection.getContentLength(); + InputStream input = connection.getInputStream(); - S3Object object = new S3Object(key, input); - object.setContentLength(length); - object.getMetadata().setMd5(md5); - object.getMetadata().setSize(length); + S3Object object = new S3Object(key, input); + object.setContentLength(length); + object.getMetadata().setMd5(md5); + object.getMetadata().setSize(length); - byte[] newMd5 = client.putObject(bucketName, object).get(30, - TimeUnit.SECONDS); - assertEquals(newMd5, md5); - } + byte[] newMd5 = client.putObject(bucketName, object).get(30, TimeUnit.SECONDS); + assertEquals(newMd5, md5); + } } \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java index bd73d772f8..5c28006fb8 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3IntegrationTest.java @@ -24,7 +24,27 @@ package org.jclouds.aws.s3; import static com.google.common.base.Preconditions.checkNotNull; -import com.google.inject.Module; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + import org.jclouds.aws.s3.config.StubS3ConnectionModule; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; @@ -32,215 +52,201 @@ import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.util.S3Utils; import org.jclouds.http.HttpConstants; import org.jclouds.http.config.JavaUrlHttpFutureCommandClientModule; -import static org.testng.Assert.assertEquals; import org.testng.ITestContext; -import org.testng.annotations.*; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; -import java.io.IOException; -import java.lang.reflect.Method; -import java.util.*; -import java.util.concurrent.*; -import java.util.logging.*; -import java.util.logging.Formatter; +import com.google.inject.Module; public class S3IntegrationTest { - protected static final String TEST_STRING = " "; + protected static final String TEST_STRING = " "; - protected byte[] goodMd5; - protected byte[] badMd5; - protected String bucketName; + protected byte[] goodMd5; + protected byte[] badMd5; + protected String bucketName; - protected void createBucketAndEnsureEmpty(String sourceBucket) - throws InterruptedException, ExecutionException, TimeoutException { - client.putBucketIfNotExists(sourceBucket).get(10, TimeUnit.SECONDS); - assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS) - .getContents().size(), 0); - } + protected void createBucketAndEnsureEmpty(String sourceBucket) throws InterruptedException, + ExecutionException, TimeoutException { + client.deleteBucketIfEmpty(sourceBucket).get(10, TimeUnit.SECONDS); + client.putBucketIfNotExists(sourceBucket).get(10, TimeUnit.SECONDS); + assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS).getContents().size(), + 0, "bucket " + sourceBucket + "wasn't empty"); + } - protected void addObjectToBucket(String sourceBucket, String key) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - S3Object sourceObject = new S3Object(key); - sourceObject.getMetadata().setContentType("text/xml"); - sourceObject.setData(TEST_STRING); - addObjectToBucket(sourceBucket, sourceObject); - } + protected void addObjectToBucket(String sourceBucket, String key) throws InterruptedException, + ExecutionException, TimeoutException, IOException { + S3Object sourceObject = new S3Object(key); + sourceObject.getMetadata().setContentType("text/xml"); + sourceObject.setData(TEST_STRING); + addObjectToBucket(sourceBucket, sourceObject); + } - protected void addObjectToBucket(String sourceBucket, S3Object object) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - client.putObject(sourceBucket, object).get(10, TimeUnit.SECONDS); - } + protected void addObjectToBucket(String sourceBucket, S3Object object) + throws InterruptedException, ExecutionException, TimeoutException, IOException { + client.putObject(sourceBucket, object).get(10, TimeUnit.SECONDS); + } - protected S3Object validateContent(String sourceBucket, String key) - throws InterruptedException, ExecutionException, TimeoutException, - IOException { - assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS) - .getContents().size(), 1); - S3Object newObject = client.getObject(sourceBucket, key).get(10, - TimeUnit.SECONDS); - assert newObject != S3Object.NOT_FOUND; - assertEquals(S3Utils.getContentAsStringAndClose(newObject), TEST_STRING); - return newObject; - } + protected S3Object validateContent(String sourceBucket, String key) throws InterruptedException, + ExecutionException, TimeoutException, IOException { + assertEquals(client.listBucket(sourceBucket).get(10, TimeUnit.SECONDS).getContents().size(), + 1); + S3Object newObject = client.getObject(sourceBucket, key).get(10, TimeUnit.SECONDS); + assert newObject != S3Object.NOT_FOUND; + assertEquals(S3Utils.getContentAsStringAndClose(newObject), TEST_STRING); + return newObject; + } - @BeforeClass(groups = {"integration", "live"}) - void enableDebug() { - if (debugEnabled()) { - Handler HANDLER = new ConsoleHandler() { - { - setLevel(Level.ALL); - setFormatter(new Formatter() { + @BeforeClass(groups = { "integration", "live" }) + void enableDebug() { + if (debugEnabled()) { + Handler HANDLER = new ConsoleHandler() { + { + setLevel(Level.ALL); + setFormatter(new Formatter() { - @Override - public String format(LogRecord record) { - return String.format( - "[%tT %-7s] [%-7s] [%s]: %s %s\n", - new Date(record.getMillis()), record - .getLevel(), Thread.currentThread() - .getName(), record.getLoggerName(), - record.getMessage(), - record.getThrown() == null ? "" : record - .getThrown()); - } - }); - } - }; - Logger guiceLogger = Logger.getLogger("org.jclouds"); - guiceLogger.addHandler(HANDLER); - guiceLogger.setLevel(Level.ALL); - } - } + @Override + public String format(LogRecord record) { + return String.format("[%tT %-7s] [%-7s] [%s]: %s %s\n", new Date(record + .getMillis()), record.getLevel(), Thread.currentThread().getName(), + record.getLoggerName(), record.getMessage(), + record.getThrown() == null ? "" : record.getThrown()); + } + }); + } + }; + Logger guiceLogger = Logger.getLogger("org.jclouds"); + guiceLogger.addHandler(HANDLER); + guiceLogger.setLevel(Level.ALL); + } + } - protected S3Connection client; - protected S3Context context = null; + protected S3Connection client; + protected S3Context context = null; - protected String bucketPrefix = (System.getProperty("user.name") + "." + this - .getClass().getSimpleName()).toLowerCase(); + protected String bucketPrefix = (System.getProperty("user.name") + "." + this.getClass() + .getSimpleName()).toLowerCase(); - private static final String sysAWSAccessKeyId = System + private static final String sysAWSAccessKeyId = System .getProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID); - private static final String sysAWSSecretAccessKey = System + private static final String sysAWSSecretAccessKey = System .getProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - @BeforeClass(inheritGroups = false, groups = {"integration", "live"}) - @Parameters({S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY}) - protected void setUpCredentials(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey, ITestContext testContext) throws Exception { - AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId - : sysAWSAccessKeyId; - AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey - : sysAWSSecretAccessKey; - if (AWSAccessKeyId != null) - testContext.setAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); - if (AWSSecretAccessKey != null) - testContext.setAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); - } + @BeforeClass(inheritGroups = false, groups = { "integration", "live" }) + @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) + protected void setUpCredentials(@Optional String AWSAccessKeyId, + @Optional String AWSSecretAccessKey, ITestContext testContext) throws Exception { + AWSAccessKeyId = AWSAccessKeyId != null ? AWSAccessKeyId : sysAWSAccessKeyId; + AWSSecretAccessKey = AWSSecretAccessKey != null ? AWSSecretAccessKey : sysAWSSecretAccessKey; + if (AWSAccessKeyId != null) + testContext.setAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID, AWSAccessKeyId); + if (AWSSecretAccessKey != null) + testContext.setAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, AWSSecretAccessKey); + } - @BeforeClass(dependsOnMethods = {"setUpCredentials"}, groups = {"integration", "live"}) - protected void setUpClient(ITestContext testContext) throws Exception { - if (testContext.getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID) != null) { - String AWSAccessKeyId = (String) testContext.getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID); - String AWSSecretAccessKey = (String) testContext.getAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); - createLiveS3Context(AWSAccessKeyId, AWSSecretAccessKey); - } else { - createStubS3Context(); - } - client = context.getConnection(); - assert client != null; - deleteEverything(); - goodMd5 = S3Utils.md5(TEST_STRING); - badMd5 = S3Utils.md5("alf"); - } + @BeforeClass(dependsOnMethods = { "setUpCredentials" }, groups = { "integration", "live" }) + protected void setUpClient(ITestContext testContext) throws Exception { + if (testContext.getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID) != null) { + String AWSAccessKeyId = (String) testContext + .getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID); + String AWSSecretAccessKey = (String) testContext + .getAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + createLiveS3Context(AWSAccessKeyId, AWSSecretAccessKey); + } else { + createStubS3Context(); + } + client = context.getConnection(); + assert client != null; + deleteEverything(); + goodMd5 = S3Utils.md5(TEST_STRING); + badMd5 = S3Utils.md5("alf"); + } - protected void createStubS3Context() { - Properties props = new Properties(); - props.setProperty(S3Constants.PROPERTY_HTTP_ADDRESS, "stub"); - context = S3ContextFactory.createS3Context(props, new StubS3ConnectionModule()); - } + protected void createStubS3Context() { + Properties props = new Properties(); + props.setProperty(S3Constants.PROPERTY_HTTP_ADDRESS, "stub"); + context = S3ContextFactory.createS3Context(props, new StubS3ConnectionModule()); + } - protected void createLiveS3Context(String AWSAccessKeyId, String AWSSecretAccessKey) { - context = S3ContextFactory.createS3Context(buildS3Properties( - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId"), - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")), - createHttpModule()); - } + protected void createLiveS3Context(String AWSAccessKeyId, String AWSSecretAccessKey) { + context = S3ContextFactory.createS3Context(buildS3Properties(checkNotNull(AWSAccessKeyId, + "AWSAccessKeyId"), checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")), + createHttpModule()); + } - @BeforeMethod(dependsOnMethods = "deleteBucket", groups = {"integration", "live"}) - public void setUpBucket(Method method) throws TimeoutException, ExecutionException, InterruptedException { - bucketName = (bucketPrefix + method.getName()).toLowerCase(); - createBucketAndEnsureEmpty(bucketName); - } + @BeforeMethod(dependsOnMethods = "deleteBucket", groups = { "integration", "live" }) + public void setUpBucket(Method method) throws TimeoutException, ExecutionException, + InterruptedException { + bucketName = (bucketPrefix + method.getName()).toLowerCase(); + createBucketAndEnsureEmpty(bucketName); + } - @BeforeMethod(groups = {"integration", "live"}) - @AfterMethod(groups = {"integration", "live"}) - public void deleteBucket() throws TimeoutException, ExecutionException, InterruptedException { - if (bucketName != null) - deleteBucket(bucketName); - } + @BeforeMethod(groups = { "integration", "live" }) + @AfterMethod(groups = { "integration", "live" }) + public void deleteBucket() throws TimeoutException, ExecutionException, InterruptedException { + if (bucketName != null) + deleteBucket(bucketName); + } - protected boolean debugEnabled() { - return false; - } + protected boolean debugEnabled() { + return false; + } - protected Properties buildS3Properties(String AWSAccessKeyId, - String AWSSecretAccessKey) { - Properties properties = new Properties( - S3ContextFactory.DEFAULT_PROPERTIES); - properties.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID, - checkNotNull(AWSAccessKeyId, "AWSAccessKeyId")); - properties.setProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, - checkNotNull(AWSSecretAccessKey, "AWSSecretAccessKey")); - properties.setProperty(HttpConstants.PROPERTY_HTTP_SECURE, "false"); - properties.setProperty(HttpConstants.PROPERTY_HTTP_PORT, "80"); - return properties; - } + protected Properties buildS3Properties(String AWSAccessKeyId, String AWSSecretAccessKey) { + Properties properties = new Properties(S3ContextFactory.DEFAULT_PROPERTIES); + properties.setProperty(S3Constants.PROPERTY_AWS_ACCESSKEYID, checkNotNull(AWSAccessKeyId, + "AWSAccessKeyId")); + properties.setProperty(S3Constants.PROPERTY_AWS_SECRETACCESSKEY, checkNotNull( + AWSSecretAccessKey, "AWSSecretAccessKey")); + properties.setProperty(HttpConstants.PROPERTY_HTTP_SECURE, "false"); + properties.setProperty(HttpConstants.PROPERTY_HTTP_PORT, "80"); + return properties; + } - protected Module createHttpModule() { - return new JavaUrlHttpFutureCommandClientModule(); - } - - protected void deleteEverything() throws Exception { - try { - List metadata = client.listOwnedBuckets().get( - 10, TimeUnit.SECONDS); - for (S3Bucket.Metadata metaDatum : metadata) { - if (metaDatum.getName().startsWith(bucketPrefix.toLowerCase())) { - deleteBucket(metaDatum.getName()); - } + protected Module createHttpModule() { + return new JavaUrlHttpFutureCommandClientModule(); + } + protected void deleteEverything() throws Exception { + try { + List metadata = client.listOwnedBuckets().get(10, TimeUnit.SECONDS); + for (S3Bucket.Metadata metaDatum : metadata) { + if (metaDatum.getName().startsWith(bucketPrefix.toLowerCase())) { + deleteBucket(metaDatum.getName()); } - } catch (CancellationException e) { - throw e; - } - } - private void deleteBucket(String name) throws InterruptedException, ExecutionException, TimeoutException { - if (client.bucketExists(name).get(10, TimeUnit.SECONDS)) { - List> results = new ArrayList>(); + } + } catch (CancellationException e) { + throw e; + } + } - S3Bucket bucket = client.listBucket(name) - .get(10, TimeUnit.SECONDS); - for (S3Object.Metadata objectMeta : bucket.getContents()) { - results.add(client.deleteObject(name, - objectMeta.getKey())); - } - Iterator> iterator = results.iterator(); - while (iterator.hasNext()) { - iterator.next().get(10, TimeUnit.SECONDS); - iterator.remove(); - } - client.deleteBucketIfEmpty(name).get(10, - TimeUnit.SECONDS); - } - } + private void deleteBucket(String name) throws InterruptedException, ExecutionException, + TimeoutException { + if (client.bucketExists(name).get(10, TimeUnit.SECONDS)) { + List> results = new ArrayList>(); - @AfterClass - protected void tearDownClient() throws Exception { - deleteEverything(); - context.close(); - context = null; - } + S3Bucket bucket = client.listBucket(name).get(10, TimeUnit.SECONDS); + for (S3Object.Metadata objectMeta : bucket.getContents()) { + results.add(client.deleteObject(name, objectMeta.getKey())); + } + Iterator> iterator = results.iterator(); + while (iterator.hasNext()) { + iterator.next().get(10, TimeUnit.SECONDS); + iterator.remove(); + } + client.deleteBucketIfEmpty(name).get(10, TimeUnit.SECONDS); + } + } + + @AfterClass + protected void tearDownClient() throws Exception { + deleteEverything(); + context.close(); + context = null; + } } \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java index 071c3cad28..9a58e3bb87 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/S3UtilsTest.java @@ -44,7 +44,7 @@ import java.util.concurrent.ExecutorCompletionService; * * @author Adrian Cole */ -@Test(groups = "performance", sequential = true, testName = "s3.PerformanceTest") +@Test(groups = "performance", sequential = true, testName = "s3.S3UtilsTest") public class S3UtilsTest extends PerformanceTest { @Test(dataProvider = "hmacsha1") diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java index 029a9b1cfb..8848ce7489 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3CommandFactoryTest.java @@ -23,131 +23,131 @@ */ package org.jclouds.aws.s3.commands; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; + +import org.jclouds.aws.s3.commands.config.S3CommandsModule; +import org.jclouds.aws.s3.commands.options.CopyObjectOptions; +import org.jclouds.aws.s3.commands.options.GetObjectOptions; +import org.jclouds.aws.s3.commands.options.ListBucketOptions; +import org.jclouds.aws.s3.commands.options.PutBucketOptions; +import org.jclouds.aws.s3.commands.options.PutObjectOptions; +import org.jclouds.aws.s3.domain.S3Object; +import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.name.Names; -import static org.easymock.EasyMock.expect; -import static org.easymock.classextension.EasyMock.createMock; -import static org.easymock.classextension.EasyMock.replay; -import org.jclouds.aws.s3.commands.config.S3CommandsModule; -import org.jclouds.aws.s3.commands.options.*; -import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; -import org.jclouds.aws.s3.domain.S3Object; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; /** * @author Adrian Cole */ -@Test(groups = {"unit"}, testName = "s3.S3CommandFactoryTest") +@Test(groups = { "unit" }, testName = "s3.S3CommandFactoryTest") public class S3CommandFactoryTest { - Injector injector = null; - S3CommandFactory commandFactory = null; - - @BeforeMethod - void setUpInjector() { - injector = Guice.createInjector(new S3CommandsModule() { - @Override - protected void configure() { - bindConstant().annotatedWith( - Names.named("jclouds.http.address")).to("localhost"); - super.configure(); - } - }); - commandFactory = injector.getInstance(S3CommandFactory.class); - } + Injector injector = null; + S3CommandFactory commandFactory = null; - @AfterMethod - void tearDownInjector() { - commandFactory = null; - injector = null; - } + @BeforeTest + void setUpInjector() { + injector = Guice.createInjector(new S3CommandsModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Names.named("jclouds.http.address")).to("localhost"); + super.configure(); + } + }); + commandFactory = injector.getInstance(S3CommandFactory.class); + } - @Test - void testCreateCopyObject() { - assert commandFactory.createCopyObject("sourcebucket", "sourceObject", - "destbucket", "destObject", CopyObjectOptions.NONE) != null; - } + @AfterTest + void tearDownInjector() { + commandFactory = null; + injector = null; + } - @Test - void testCreateCopyObjectOptions() { - assert commandFactory.createCopyObject("sourcebucket", "sourceObject", - "destbucket", "destObject", new CopyObjectOptions()) != null; - } + @Test + void testCreateCopyObject() { + assert commandFactory.createCopyObject("sourcebucket", "sourceObject", "destbucket", + "destObject", CopyObjectOptions.NONE) != null; + } - @Test - void testCreateDeleteBucket() { - assert commandFactory.createDeleteBucket("test") != null; - } + @Test + void testCreateCopyObjectOptions() { + assert commandFactory.createCopyObject("sourcebucket", "sourceObject", "destbucket", + "destObject", new CopyObjectOptions()) != null; + } - @Test - void testCreateDeleteObject() { - assert commandFactory.createDeleteObject("test", "blah") != null; - } + @Test + void testCreateDeleteBucket() { + assert commandFactory.createDeleteBucket("test") != null; + } - @Test - void testCreateHeadBucket() { - assert commandFactory.createHeadBucket("test") != null; - } + @Test + void testCreateDeleteObject() { + assert commandFactory.createDeleteObject("test", "blah") != null; + } - @Test - void testCreatePutBucket() { - assert commandFactory.createPutBucket("test", PutBucketOptions.NONE) != null; - } + @Test + void testCreateHeadBucket() { + assert commandFactory.createHeadBucket("test") != null; + } - @Test - void testCreatePutBucketOptions() { - assert commandFactory.createPutBucket("test", PutBucketOptions.Builder - .createIn(LocationConstraint.EU)) != null; - } + @Test + void testCreatePutBucket() { + assert commandFactory.createPutBucket("test", PutBucketOptions.NONE) != null; + } - @Test - void testCreatePutObject() { - S3Object.Metadata metadata = createMock(S3Object.Metadata.class); - S3Object object = new S3Object(metadata); - expect(metadata.getSize()).andReturn(4L).atLeastOnce(); - expect(metadata.getKey()).andReturn("rawr"); - expect(metadata.getContentType()).andReturn("text/xml").atLeastOnce(); - expect(metadata.getCacheControl()).andReturn("no-cache").atLeastOnce(); - expect(metadata.getContentDisposition()).andReturn("disposition") - .atLeastOnce(); - expect(metadata.getContentEncoding()).andReturn("encoding") - .atLeastOnce(); - expect(metadata.getMd5()).andReturn("encoding".getBytes()) - .atLeastOnce(); - Multimap userMdata = HashMultimap.create(); - expect(metadata.getUserMetadata()).andReturn(userMdata).atLeastOnce(); + @Test + void testCreatePutBucketOptions() { + assert commandFactory.createPutBucket("test", PutBucketOptions.Builder + .createIn(LocationConstraint.EU)) != null; + } - replay(metadata); - object.setData(""); + @Test + void testCreatePutObject() { + S3Object.Metadata metadata = createMock(S3Object.Metadata.class); + S3Object object = new S3Object(metadata); + expect(metadata.getSize()).andReturn(4L).atLeastOnce(); + expect(metadata.getKey()).andReturn("rawr"); + expect(metadata.getContentType()).andReturn("text/xml").atLeastOnce(); + expect(metadata.getCacheControl()).andReturn("no-cache").atLeastOnce(); + expect(metadata.getContentDisposition()).andReturn("disposition").atLeastOnce(); + expect(metadata.getContentEncoding()).andReturn("encoding").atLeastOnce(); + expect(metadata.getMd5()).andReturn("encoding".getBytes()).atLeastOnce(); + Multimap userMdata = HashMultimap.create(); + expect(metadata.getUserMetadata()).andReturn(userMdata).atLeastOnce(); - assert commandFactory.createPutObject("test", object, - PutObjectOptions.NONE) != null; - } + replay(metadata); + object.setData(""); - @Test - void testCreateGetObject() { - assert commandFactory.createGetObject("test", "blah", - GetObjectOptions.NONE) != null; - } + assert commandFactory.createPutObject("test", object, PutObjectOptions.NONE) != null; + } - @Test - void testCreateHeadMetadata() { - assert commandFactory.createHeadMetadata("test", "blah") != null; - } + @Test + void testCreateGetObject() { + assert commandFactory.createGetObject("test", "blah", GetObjectOptions.NONE) != null; + } - @Test - void testCreateListAllMyBuckets() { - assert commandFactory.createGetMetadataForOwnedBuckets() != null; - } + @Test + void testCreateHeadMetadata() { + assert commandFactory.createHeadMetadata("test", "blah") != null; + } - @Test - void testCreateListBucket() { - assert commandFactory.createListBucket("test", ListBucketOptions.NONE) != null; - } + @Test + void testCreateListAllMyBuckets() { + assert commandFactory.createGetMetadataForOwnedBuckets() != null; + } + + @Test + void testCreateListBucket() { + assert commandFactory.createListBucket("test", ListBucketOptions.NONE) != null; + } } \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java index e41efecdf5..7c0afee4e3 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java @@ -23,8 +23,16 @@ */ package org.jclouds.aws.s3.commands; -import com.google.inject.Guice; -import com.google.inject.Injector; +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; + import org.apache.commons.io.IOUtils; import org.jclouds.aws.PerformanceTest; import org.jclouds.aws.s3.domain.CanonicalUser; @@ -38,165 +46,149 @@ import org.jclouds.aws.s3.xml.config.S3ParserModule; import org.jclouds.http.HttpException; import org.jclouds.http.commands.callables.xml.ParseSax; import org.joda.time.DateTime; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import org.xml.sax.SAXException; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; +import com.google.inject.Guice; +import com.google.inject.Injector; /** * Tests parsing of S3 responses - * + * * @author Adrian Cole */ -@Test(groups = {"performance"}, testName = "s3.S3ParserTest") +@Test(groups = { "performance" }, testName = "s3.S3ParserTest") public class S3ParserTest extends PerformanceTest { - Injector injector = null; + Injector injector = null; - public static final String listAllMyBucketsResultOn200 = "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0adrianjbosstest2009-03-12T02:00:07.000Zadrianjbosstest22009-03-12T02:00:09.000Z"; + public static final String listAllMyBucketsResultOn200 = "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0adrianjbosstest2009-03-12T02:00:07.000Zadrianjbosstest22009-03-12T02:00:09.000Z"; - S3ParserFactory parserFactory = null; + S3ParserFactory parserFactory = null; - @BeforeMethod - protected void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - assert parserFactory != null; - } + @BeforeTest + protected void setUpInjector() { + injector = Guice.createInjector(new S3ParserModule()); + parserFactory = injector.getInstance(S3ParserFactory.class); + assert parserFactory != null; + } - @AfterMethod - protected void tearDownInjector() { - parserFactory = null; - injector = null; - } + @AfterTest + protected void tearDownInjector() { + parserFactory = null; + injector = null; + } - @Test - void testParseListAllMyBucketsSerialResponseTime() throws HttpException { - for (int i = 0; i < LOOP_COUNT; i++) - runParseListAllMyBuckets(); - } + @Test + void testParseListAllMyBucketsSerialResponseTime() throws HttpException { + for (int i = 0; i < LOOP_COUNT; i++) + runParseListAllMyBuckets(); + } - private List runParseListAllMyBuckets() - throws HttpException { - return parserFactory.createListBucketsParser().parse( - IOUtils.toInputStream(listAllMyBucketsResultOn200)); - } + private List runParseListAllMyBuckets() throws HttpException { + return parserFactory.createListBucketsParser().parse( + IOUtils.toInputStream(listAllMyBucketsResultOn200)); + } - @Test - void testParseListAllMyBucketsParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService> completer = new ExecutorCompletionService>( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable>() { - public List call() throws IOException, - SAXException, HttpException { - return runParseListAllMyBuckets(); - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get() != null; - } + @Test + void testParseListAllMyBucketsParallelResponseTime() throws InterruptedException, + ExecutionException { + CompletionService> completer = new ExecutorCompletionService>( + exec); + for (int i = 0; i < LOOP_COUNT; i++) + completer.submit(new Callable>() { + public List call() throws IOException, SAXException, HttpException { + return runParseListAllMyBuckets(); + } + }); + for (int i = 0; i < LOOP_COUNT; i++) + assert completer.take().get() != null; + } - @Test - public void testCanParseListAllMyBuckets() throws HttpException { - List s3Buckets = runParseListAllMyBuckets(); - S3Bucket.Metadata bucket1 = s3Buckets.get(0); - assert bucket1.getName().equals("adrianjbosstest"); - DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z"); - DateTime date1 = bucket1.getCreationDate(); - assert date1.equals(expectedDate1); - S3Bucket.Metadata bucket2 = s3Buckets.get(1); - assert bucket2.getName().equals("adrianjbosstest2"); - DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z"); - DateTime date2 = bucket2.getCreationDate(); - assert date2.equals(expectedDate2); - assert s3Buckets.size() == 2; - CanonicalUser owner = new CanonicalUser( - "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); - assert bucket1.getOwner().equals(owner); - assert bucket2.getOwner().equals(owner); - } + @Test + public void testCanParseListAllMyBuckets() throws HttpException { + List s3Buckets = runParseListAllMyBuckets(); + S3Bucket.Metadata bucket1 = s3Buckets.get(0); + assert bucket1.getName().equals("adrianjbosstest"); + DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z"); + DateTime date1 = bucket1.getCreationDate(); + assert date1.equals(expectedDate1); + S3Bucket.Metadata bucket2 = s3Buckets.get(1); + assert bucket2.getName().equals("adrianjbosstest2"); + DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z"); + DateTime date2 = bucket2.getCreationDate(); + assert date2.equals(expectedDate2); + assert s3Buckets.size() == 2; + CanonicalUser owner = new CanonicalUser( + "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); + assert bucket1.getOwner().equals(owner); + assert bucket2.getOwner().equals(owner); + } - public static final String listBucketResult = "adrianjbosstest1000false33662009-03-12T02:00:13.000Z"9d7bb64e8e18ee34eec06dd2cf37b766"136e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; + public static final String listBucketResult = "adrianjbosstest1000false33662009-03-12T02:00:13.000Z"9d7bb64e8e18ee34eec06dd2cf37b766"136e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; - public void testCanParseListBucketResult() throws HttpException, - UnsupportedEncodingException { - S3Bucket bucket = runParseListBucketResult(); - assert !bucket.isTruncated(); - assert bucket.getName().equals("adrianjbosstest"); - assert bucket.getContents().size() == 1; - S3Object.Metadata object = bucket.getContents().iterator().next(); - assert object.getKey().equals("3366"); - DateTime expected = new DateTime("2009-03-12T02:00:13.000Z"); - assert object.getLastModified().equals(expected) : String.format( - "expected %1$s, but got %1$s", expected, object - .getLastModified()); - assertEquals(S3Utils.toHexString(object.getMd5()), - "9d7bb64e8e18ee34eec06dd2cf37b766"); - assert object.getSize() == 136; - CanonicalUser owner = new CanonicalUser( - "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); - owner.setDisplayName("ferncam"); - assert object.getOwner().equals(owner); - assert object.getStorageClass().equals("STANDARD"); - } + public void testCanParseListBucketResult() throws HttpException, UnsupportedEncodingException { + S3Bucket bucket = runParseListBucketResult(); + assert !bucket.isTruncated(); + assert bucket.getName().equals("adrianjbosstest"); + assert bucket.getContents().size() == 1; + S3Object.Metadata object = bucket.getContents().iterator().next(); + assert object.getKey().equals("3366"); + DateTime expected = new DateTime("2009-03-12T02:00:13.000Z"); + assert object.getLastModified().equals(expected) : String.format( + "expected %1$s, but got %1$s", expected, object.getLastModified()); + assertEquals(S3Utils.toHexString(object.getMd5()), "9d7bb64e8e18ee34eec06dd2cf37b766"); + assert object.getSize() == 136; + CanonicalUser owner = new CanonicalUser( + "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0"); + owner.setDisplayName("ferncam"); + assert object.getOwner().equals(owner); + assert object.getStorageClass().equals("STANDARD"); + } - private S3Bucket runParseListBucketResult() throws HttpException { - ParseSax parser = parserFactory.createListBucketParser(); - ListBucketHandler handler = (ListBucketHandler) parser.getHandler(); - handler.setBucketName("adrianjbosstest"); - return parser.parse(IOUtils.toInputStream(listBucketResult)); - } + private S3Bucket runParseListBucketResult() throws HttpException { + ParseSax parser = parserFactory.createListBucketParser(); + ListBucketHandler handler = (ListBucketHandler) parser.getHandler(); + handler.setBucketName("adrianjbosstest"); + return parser.parse(IOUtils.toInputStream(listBucketResult)); + } - public static final String successfulCopyObject200 = "2009-03-19T13:23:27.000Z\"92836a3ea45a6984d1b4d23a747d46bb\""; + public static final String successfulCopyObject200 = "2009-03-19T13:23:27.000Z\"92836a3ea45a6984d1b4d23a747d46bb\""; - private S3Object.Metadata runParseCopyObjectResult() throws HttpException { - ParseSax parser = parserFactory - .createCopyObjectParser(); - CopyObjectHandler handler = (CopyObjectHandler) parser.getHandler(); - handler.setKey("adrianjbosstest"); - return parser.parse(IOUtils.toInputStream(successfulCopyObject200)); - } + private S3Object.Metadata runParseCopyObjectResult() throws HttpException { + ParseSax parser = parserFactory.createCopyObjectParser(); + CopyObjectHandler handler = (CopyObjectHandler) parser.getHandler(); + handler.setKey("adrianjbosstest"); + return parser.parse(IOUtils.toInputStream(successfulCopyObject200)); + } - public void testCanParseCopyObjectResult() throws HttpException, - UnsupportedEncodingException { - S3Object.Metadata metadata = runParseCopyObjectResult(); - DateTime expected = new DateTime("2009-03-19T13:23:27.000Z"); - assertEquals(metadata.getLastModified(), expected); - assertEquals(S3Utils.toHexString(metadata.getMd5()), - "92836a3ea45a6984d1b4d23a747d46bb"); - assertEquals(metadata.getKey(), "adrianjbosstest"); - } + public void testCanParseCopyObjectResult() throws HttpException, UnsupportedEncodingException { + S3Object.Metadata metadata = runParseCopyObjectResult(); + DateTime expected = new DateTime("2009-03-19T13:23:27.000Z"); + assertEquals(metadata.getLastModified(), expected); + assertEquals(S3Utils.toHexString(metadata.getMd5()), "92836a3ea45a6984d1b4d23a747d46bb"); + assertEquals(metadata.getKey(), "adrianjbosstest"); + } - @Test - void testParseListBucketResultSerialResponseTime() throws HttpException { - for (int i = 0; i < LOOP_COUNT; i++) - runParseListBucketResult(); - } + @Test + void testParseListBucketResultSerialResponseTime() throws HttpException { + for (int i = 0; i < LOOP_COUNT; i++) + runParseListBucketResult(); + } - @Test - void testParseListBucketResultParallelResponseTime() - throws InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public S3Bucket call() throws IOException, SAXException, - HttpException { - return runParseListBucketResult(); - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assert completer.take().get() != null; - } + @Test + void testParseListBucketResultParallelResponseTime() throws InterruptedException, + ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + for (int i = 0; i < LOOP_COUNT; i++) + completer.submit(new Callable() { + public S3Bucket call() throws IOException, SAXException, HttpException { + return runParseListBucketResult(); + } + }); + for (int i = 0; i < LOOP_COUNT; i++) + assert completer.take().get() != null; + } } diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java index 6277448f91..378786d3d2 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/commands/callables/ParseObjectFromHeadersAndHttpContentTest.java @@ -23,16 +23,19 @@ */ package org.jclouds.aws.s3.commands.callables; +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.replay; +import static org.testng.Assert.assertEquals; + import org.apache.commons.io.IOUtils; -import static org.easymock.classextension.EasyMock.*; import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object.Metadata; import org.jclouds.http.HttpException; import org.jclouds.http.HttpHeaders; import org.jclouds.http.HttpResponse; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** @@ -43,13 +46,13 @@ public class ParseObjectFromHeadersAndHttpContentTest { ParseObjectFromHeadersAndHttpContent callable; ParseMetadataFromHeaders metadataParser; - @BeforeMethod + @BeforeTest void setUp() { metadataParser = createMock(ParseMetadataFromHeaders.class); callable = new ParseObjectFromHeadersAndHttpContent(metadataParser); } - @AfterMethod + @AfterTest void tearDown() { callable = null; } diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/BaseS3MapTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/BaseS3MapTest.java new file mode 100644 index 0000000000..c1752f1148 --- /dev/null +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/internal/BaseS3MapTest.java @@ -0,0 +1,121 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3.internal; + +import static org.easymock.EasyMock.expect; +import static org.easymock.classextension.EasyMock.createMock; +import static org.easymock.classextension.EasyMock.createNiceMock; +import static org.easymock.classextension.EasyMock.replay; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.jclouds.aws.s3.S3Connection; +import org.jclouds.aws.s3.domain.S3Object; +import org.testng.annotations.Test; + +/** + * + * Tests retry logic. + * + * @author Adrian Cole + */ +@Test(groups = { "unit" }, testName = "s3.BaseS3MapTest") +public class BaseS3MapTest { + + class MockBaseS3Map extends BaseS3Map { + + public MockBaseS3Map() { + super(createNiceMock(S3Connection.class), "bucket"); + } + + public Set> entrySet() { + return null; + } + + public String get(Object key) { + return null; + } + + public String put(String key, String value) { + return null; + } + + public void putAll(Map t) { + + } + + public String remove(Object key) { + return null; + } + + public Collection values() { + return null; + } + + } + + public void testIfNotFoundRetryOtherwiseAddToSet() throws InterruptedException, + ExecutionException, TimeoutException { + BaseS3Map map = new MockBaseS3Map(); + Future futureObject = createMock(Future.class); + S3Object object = createNiceMock(S3Object.class); + expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andReturn( + S3Object.NOT_FOUND); + expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andReturn( + object); + replay(futureObject); + Set objects = new HashSet(); + long time = System.currentTimeMillis(); + map.ifNotFoundRetryOtherwiseAddToSet(futureObject, objects); + // should have retried once + assert System.currentTimeMillis() >= time + map.requestRetryMilliseconds; + assert objects.contains(object); + assert !objects.contains(S3Object.NOT_FOUND); + } + + public void testIfNotFoundRetryOtherwiseAddToSetButNeverGetsIt() throws InterruptedException, + ExecutionException, TimeoutException { + BaseS3Map map = new MockBaseS3Map(); + Future futureObject = createMock(Future.class); + S3Object object = createNiceMock(S3Object.class); + expect(futureObject.get(map.requestTimeoutMilliseconds, TimeUnit.MILLISECONDS)).andReturn( + S3Object.NOT_FOUND).atLeastOnce(); + replay(futureObject); + Set objects = new HashSet(); + long time = System.currentTimeMillis(); + map.ifNotFoundRetryOtherwiseAddToSet(futureObject, objects); + // should have retried thrice + assert System.currentTimeMillis() >= time + map.requestRetryMilliseconds * 3; + + assert !objects.contains(object); + assert !objects.contains(S3Object.NOT_FOUND); + } +} \ No newline at end of file diff --git a/aws/s3/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java b/aws/s3/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java index 0e2cdf37dc..9444f94cb7 100644 --- a/aws/s3/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java +++ b/aws/s3/core/src/test/java/org/jclouds/aws/s3/xml/S3ParserFactoryTest.java @@ -23,12 +23,13 @@ */ package org.jclouds.aws.s3.xml; +import org.jclouds.aws.s3.xml.config.S3ParserModule; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + import com.google.inject.Guice; import com.google.inject.Injector; -import org.jclouds.aws.s3.xml.config.S3ParserModule; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; /** * @author Adrian Cole @@ -36,39 +37,39 @@ import org.testng.annotations.Test; @Test(groups = "unit", testName = "s3.S3ParserFactoryTest") public class S3ParserFactoryTest { - Injector injector = null; - S3ParserFactory parserFactory = null; + Injector injector = null; + S3ParserFactory parserFactory = null; - @BeforeMethod - void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - } + @BeforeTest + void setUpInjector() { + injector = Guice.createInjector(new S3ParserModule()); + parserFactory = injector.getInstance(S3ParserFactory.class); + } - @AfterMethod - void tearDownInjector() { - parserFactory = null; - injector = null; - } + @AfterTest + void tearDownInjector() { + parserFactory = null; + injector = null; + } - @Test - void testCreateListBucketsParser() { - assert parserFactory.createListBucketsParser() != null; - } + @Test + void testCreateListBucketsParser() { + assert parserFactory.createListBucketsParser() != null; + } - @Test - void testCreateListBucketParser() { - assert parserFactory.createListBucketParser() != null; - } + @Test + void testCreateListBucketParser() { + assert parserFactory.createListBucketParser() != null; + } - @Test - void testCreateCopyObjectParser() { - assert parserFactory.createCopyObjectParser() != null; - } + @Test + void testCreateCopyObjectParser() { + assert parserFactory.createCopyObjectParser() != null; + } - @Test - void testCreateErrorParser() { - assert parserFactory.createErrorParser() != null; - } + @Test + void testCreateErrorParser() { + assert parserFactory.createErrorParser() != null; + } } \ No newline at end of file diff --git a/aws/s3/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java b/aws/s3/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java index 6e569ad0c7..6a92ab5d6c 100644 --- a/aws/s3/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java +++ b/aws/s3/extensions/jets3t/src/main/java/org/jclouds/aws/s3/jets3t/JCloudsS3Service.java @@ -40,277 +40,252 @@ import org.jets3t.service.acl.AccessControlList; import org.jets3t.service.model.S3Bucket; import org.jets3t.service.model.S3BucketLoggingStatus; import org.jets3t.service.model.S3Object; -import org.jets3t.service.model.S3Owner; import org.jets3t.service.security.AWSCredentials; import com.google.inject.Module; /** * A JetS3t S3Service implemented by JClouds - * + * * @author Adrian Cole * @author James Murty */ public class JCloudsS3Service extends S3Service { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final S3Context context; - private final S3Connection connection; + private final S3Context context; + private final S3Connection connection; - private final long requestTimeoutMilliseconds = 10000; + private final long requestTimeoutMilliseconds = 10000; - /** - * Initializes a JClouds context to S3. - * - * @param awsCredentials - credentials to access S3 - * @param modules - Module that configures a FutureHttpClient, if not specified, - * default is URLFetchServiceClientModule - * @throws S3ServiceException - */ - protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules) + /** + * Initializes a JClouds context to S3. + * + * @param awsCredentials + * - credentials to access S3 + * @param modules + * - Module that configures a FutureHttpClient, if not specified, default is + * URLFetchServiceClientModule + * @throws S3ServiceException + */ + protected JCloudsS3Service(AWSCredentials awsCredentials, Module... modules) throws S3ServiceException { - super(awsCredentials); - context = S3ContextFactory.createS3Context(awsCredentials - .getAccessKey(), awsCredentials.getSecretKey(), modules); - connection = context.getConnection(); - } + super(awsCredentials); + context = S3ContextFactory.createS3Context(awsCredentials.getAccessKey(), awsCredentials + .getSecretKey(), modules); + connection = context.getConnection(); + } - @Override - public int checkBucketStatus(final String bucketName) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + @Override + public int checkBucketStatus(final String bucketName) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } - /** - * {@inheritDoc} - */ - @SuppressWarnings("unchecked") - @Override - protected Map copyObjectImpl(String sourceBucketName, - String sourceObjectKey, String destinationBucketName, - String destinationObjectKey, AccessControlList acl, - Map destinationMetadata, Calendar ifModifiedSince, - Calendar ifUnmodifiedSince, String[] ifMatchTags, - String[] ifNoneMatchTags) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + /** + * {@inheritDoc} + */ + @SuppressWarnings("unchecked") + @Override + protected Map copyObjectImpl(String sourceBucketName, String sourceObjectKey, + String destinationBucketName, String destinationObjectKey, AccessControlList acl, + Map destinationMetadata, Calendar ifModifiedSince, Calendar ifUnmodifiedSince, + String[] ifMatchTags, String[] ifNoneMatchTags) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } - @Override - protected S3Bucket createBucketImpl(String bucketName, String location, - AccessControlList acl) throws S3ServiceException - { - if (location != null) - throw new UnsupportedOperationException("Bucket location is not yet supported"); - if (acl != null) - throw new UnsupportedOperationException("Bucket ACL is not yet supported"); - - try { - if (connection.putBucketIfNotExists(bucketName).get()) { - // Bucket created. - } - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException( - "error creating bucket: " + bucketName, e); - } - return new S3Bucket(bucketName); - } - - /** - * {@inheritDoc} - * - * @see S3Connection#deleteBucketIfEmpty(String) - */ - @Override - protected void deleteBucketImpl(String bucketName) + @Override + protected S3Bucket createBucketImpl(String bucketName, String location, AccessControlList acl) throws S3ServiceException { - try { - connection.deleteBucketIfEmpty(bucketName).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException( - "error deleting bucket: " + bucketName, e); - } - } + if (location != null) + throw new UnsupportedOperationException("Bucket location is not yet supported"); + if (acl != null) + throw new UnsupportedOperationException("Bucket ACL is not yet supported"); - /** - * {@inheritDoc} - * - * @see S3Connection#deleteObject(String, String) - */ - @Override - protected void deleteObjectImpl(String bucketName, String objectKey) + try { + if (connection.putBucketIfNotExists(bucketName).get()) { + // Bucket created. + } + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException("error creating bucket: " + bucketName, e); + } + return new S3Bucket(bucketName); + } + + /** + * {@inheritDoc} + * + * @see S3Connection#deleteBucketIfEmpty(String) + */ + @Override + protected void deleteBucketImpl(String bucketName) throws S3ServiceException { + try { + connection.deleteBucketIfEmpty(bucketName).get(requestTimeoutMilliseconds, + TimeUnit.MILLISECONDS); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException("error deleting bucket: " + bucketName, e); + } + } + + /** + * {@inheritDoc} + * + * @see S3Connection#deleteObject(String, String) + */ + @Override + protected void deleteObjectImpl(String bucketName, String objectKey) throws S3ServiceException { + try { + connection.deleteObject(bucketName, objectKey).get(requestTimeoutMilliseconds, + TimeUnit.MILLISECONDS); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException(String.format("error deleting object: %1$s:%2$s", bucketName, + objectKey), e); + } + } + + @Override + protected AccessControlList getBucketAclImpl(String bucketName) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } + + @Override + protected String getBucketLocationImpl(String bucketName) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } + + @Override + protected S3BucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) throws S3ServiceException { - try { - connection.deleteObject(bucketName, objectKey).get( - requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException(String.format( - "error deleting object: %1$s:%2$s", bucketName, objectKey), e); - } - } + // TODO Unimplemented + throw new UnsupportedOperationException(); + } - @Override - protected AccessControlList getBucketAclImpl(String bucketName) + @Override + protected AccessControlList getObjectAclImpl(String bucketName, String objectKey) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); + } - @Override - protected String getBucketLocationImpl(String bucketName) + @Override + protected S3Object getObjectDetailsImpl(String bucketName, String objectKey, + Calendar ifModifiedSince, Calendar ifUnmodifiedSince, String[] ifMatchTags, + String[] ifNoneMatchTags) throws S3ServiceException { + try { + if (ifModifiedSince != null) + throw new IllegalArgumentException("ifModifiedSince"); + if (ifUnmodifiedSince != null) + throw new IllegalArgumentException("ifUnmodifiedSince"); + if (ifMatchTags != null) + throw new IllegalArgumentException("ifMatchTags"); + if (ifNoneMatchTags != null) + throw new IllegalArgumentException("ifNoneMatchTags"); + + return Util.convertObjectHead(connection.headObject(bucketName, objectKey).get()); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException(String.format("error retrieving object head: %1$s:%2$s", + bucketName, objectKey), e); + } + } + + @Override + protected S3Object getObjectImpl(String bucketName, String objectKey, Calendar ifModifiedSince, + Calendar ifUnmodifiedSince, String[] ifMatchTags, String[] ifNoneMatchTags, + Long byteRangeStart, Long byteRangeEnd) throws S3ServiceException { + try { + GetObjectOptions options = Util.convertOptions(ifModifiedSince, ifUnmodifiedSince, + ifMatchTags, ifNoneMatchTags); + return Util.convertObject(connection.getObject(bucketName, objectKey, options).get()); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException(String.format("error retrieving object: %1$s:%2$s", + bucketName, objectKey), e); + } + } + + @Override + public boolean isBucketAccessible(String bucketName) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } + + @Override + protected boolean isRequesterPaysBucketImpl(String bucketName) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } + + @Override + protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException { + try { + List jcBucketList = connection + .listOwnedBuckets().get(requestTimeoutMilliseconds, TimeUnit.MILLISECONDS); + return Util.convertBuckets(jcBucketList); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(e); + throw new S3ServiceException("error listing buckets", e); + } + } + + @Override + protected S3ObjectsChunk listObjectsChunkedImpl(String bucketName, String prefix, + String delimiter, long maxListingLength, String priorLastKey, boolean completeListing) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); + } - @Override - protected S3BucketLoggingStatus getBucketLoggingStatusImpl(String bucketName) + @Override + protected S3Object[] listObjectsImpl(String bucketName, String prefix, String delimiter, + long maxListingLength) throws S3ServiceException { + // TODO Unimplemented + throw new UnsupportedOperationException(); + } + + @Override + protected void putBucketAclImpl(String bucketName, AccessControlList acl) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); - @Override - protected AccessControlList getObjectAclImpl(String bucketName, - String objectKey) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + } - @Override - protected S3Object getObjectDetailsImpl(String bucketName, - String objectKey, Calendar ifModifiedSince, - Calendar ifUnmodifiedSince, String[] ifMatchTags, - String[] ifNoneMatchTags) throws S3ServiceException - { - try { - if (ifModifiedSince != null) - throw new IllegalArgumentException("ifModifiedSince"); - if (ifUnmodifiedSince != null) - throw new IllegalArgumentException("ifUnmodifiedSince"); - if (ifMatchTags != null) - throw new IllegalArgumentException("ifMatchTags"); - if (ifNoneMatchTags != null) - throw new IllegalArgumentException("ifNoneMatchTags"); - - return Util.convertObjectHead( - connection.headObject(bucketName, objectKey).get()); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException(String.format( - "error retrieving object head: %1$s:%2$s", bucketName, objectKey), e); - } - } - - @Override - protected S3Object getObjectImpl(String bucketName, String objectKey, - Calendar ifModifiedSince, Calendar ifUnmodifiedSince, - String[] ifMatchTags, String[] ifNoneMatchTags, - Long byteRangeStart, Long byteRangeEnd) throws S3ServiceException - { - try { - GetObjectOptions options = Util.convertOptions( - ifModifiedSince, ifUnmodifiedSince, ifMatchTags, ifNoneMatchTags); - return Util.convertObject( - connection.getObject(bucketName, objectKey, options).get()); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException(String.format( - "error retrieving object: %1$s:%2$s", bucketName, objectKey), e); - } - } - - @Override - public boolean isBucketAccessible(String bucketName) + @Override + protected void putObjectAclImpl(String bucketName, String objectKey, AccessControlList acl) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); - @Override - protected boolean isRequesterPaysBucketImpl(String bucketName) + } + + @Override + protected S3Object putObjectImpl(String bucketName, S3Object object) throws S3ServiceException { + // TODO Unimplemented + return null; + } + + @Override + protected void setBucketLoggingStatusImpl(String bucketName, S3BucketLoggingStatus status) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); - @Override - protected S3Bucket[] listAllBucketsImpl() throws S3ServiceException { - try { - List jcBucketList = connection - .listOwnedBuckets().get(requestTimeoutMilliseconds, - TimeUnit.MILLISECONDS); - return Util.convertBuckets(jcBucketList); - } catch (Exception e) { - Utils.rethrowIfRuntimeOrSameType(e); - throw new S3ServiceException("error listing buckets", e); - } - } + } - @Override - protected S3ObjectsChunk listObjectsChunkedImpl(String bucketName, - String prefix, String delimiter, long maxListingLength, - String priorLastKey, boolean completeListing) + @Override + protected void setRequesterPaysBucketImpl(String bucketName, boolean requesterPays) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + // TODO Unimplemented + throw new UnsupportedOperationException(); - @Override - protected S3Object[] listObjectsImpl(String bucketName, String prefix, - String delimiter, long maxListingLength) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } - - @Override - protected void putBucketAclImpl(String bucketName, AccessControlList acl) - throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected void putObjectAclImpl(String bucketName, String objectKey, - AccessControlList acl) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected S3Object putObjectImpl(String bucketName, S3Object object) - throws S3ServiceException { - // TODO Unimplemented - return null; - } - - @Override - protected void setBucketLoggingStatusImpl(String bucketName, - S3BucketLoggingStatus status) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected void setRequesterPaysBucketImpl(String bucketName, - boolean requesterPays) throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - - } - - @Override - protected S3Owner getAccountOwnerImpl() throws S3ServiceException { - // TODO Unimplemented - throw new UnsupportedOperationException(); - } + } } diff --git a/aws/s3/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceIntegrationTest.java b/aws/s3/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceIntegrationTest.java index 194b37361d..da3b8b3d72 100644 --- a/aws/s3/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceIntegrationTest.java +++ b/aws/s3/extensions/jets3t/src/test/java/org/jclouds/aws/s3/jets3t/JCloudsS3ServiceIntegrationTest.java @@ -23,6 +23,19 @@ */ package org.jclouds.aws.s3.jets3t; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.S3IntegrationTest; import org.jclouds.aws.s3.config.StubS3ConnectionModule; @@ -31,26 +44,12 @@ import org.jets3t.service.S3ServiceException; import org.jets3t.service.model.S3Bucket; import org.jets3t.service.model.S3Object; import org.jets3t.service.security.AWSCredentials; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.StringReader; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - /** * Tests to cover JCloudsS3Service * diff --git a/aws/s3/perftest/pom.xml b/aws/s3/perftest/pom.xml index b169a2e28f..4c844ba187 100644 --- a/aws/s3/perftest/pom.xml +++ b/aws/s3/perftest/pom.xml @@ -1,103 +1,99 @@ - - + http://www.apache.org/licenses/LICENSE-2.0.html Unless required by + applicable law or agreed to in writing, software distributed under the + License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the + License. + ==================================================================== + --> + - - jclouds-s3-project - org.jclouds - 1.0-SNAPSHOT - ../pom.xml - - 4.0.0 - jclouds-s3-perftest - jclouds Performance test verses Amazon samples implementation - jar + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + jclouds-s3-project + org.jclouds + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + jclouds-s3-perftest + jclouds Performance test verses Amazon samples implementation + jar - Performance test verses Amazon samples implementation + Performance test verses Amazon samples implementation - - - ${project.groupId} - jclouds-s3 - ${project.version} - - - ${project.groupId} - jclouds-s3 - ${project.version} - test-jar - test - - - xstream - xstream - 1.2 - test - - - ${project.groupId} - jclouds-httpnio - ${project.version} - - - net.java.dev.jets3t - jets3t - 0.7.1 - - + + + ${project.groupId} + jclouds-s3 + ${project.version} + + + ${project.groupId} + jclouds-s3 + ${project.version} + test-jar + test + + + xstream + xstream + 1.2 + test + + + ${project.groupId} + jclouds-httpnio + ${project.version} + + + net.java.dev.jets3t + jets3t + 0.7.1 + + - - scm:svn:http://jclouds.googlecode.com/svn/trunk/s3core/perftest - scm:svn:https://jclouds.googlecode.com/svn/trunk/s3core/perftest - http://jclouds.googlecode.com/svn/trunk/s3core/perftest - - - - - - jets3t - jets3t - http://jets3t.s3.amazonaws.com/maven2 - - + + scm:svn:http://jclouds.googlecode.com/svn/trunk/s3core/perftest + scm:svn:https://jclouds.googlecode.com/svn/trunk/s3core/perftest + http://jclouds.googlecode.com/svn/trunk/s3core/perftest + + + + + org.apache.maven.plugins + maven-surefire-plugin + + classes + + + + diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceLiveTest.java deleted file mode 100644 index 5f344ac868..0000000000 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceLiveTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.jclouds.aws.s3.reference.S3Constants; -import org.testng.ITestContext; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; -import java.util.concurrent.ExecutionException; - - -/** - * Runs operations that amazon s3 sample code is capable of performing. - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.AmazonPerformanceLiveTest", groups = {"live"}) -public class AmazonPerformanceLiveTest extends BasePerformance { - private AWSAuthConnection amzClient; - - @Override - @BeforeTest - @Parameters({S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY}) - protected void setUpCredentials(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey, ITestContext context) throws Exception { - super.setUpCredentials(AWSAccessKeyId, AWSSecretAccessKey, context); - amzClient = new AWSAuthConnection(AWSAccessKeyId, AWSSecretAccessKey, - false); - } - - @Override - @Test(enabled = false) - public void testPutFileSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - com.amazon.s3.S3Object object = new com.amazon.s3.S3Object(data, null); - Map> headers = new TreeMap>(); - headers - .put("Content-Type", Arrays - .asList(new String[]{contentType})); - return amzClient.put(bucket, key, object, headers).connection - .getResponseMessage() != null; - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - -} diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java b/aws/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java deleted file mode 100644 index db1aacf2ec..0000000000 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java +++ /dev/null @@ -1,94 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.TimeUnit; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -public abstract class BaseJCloudsPerformance extends BasePerformance { - // boolean get - // ( - // int id) throws Exception { - // S3Bucket s3Bucket = new S3Bucket(); - // s3Bucket.setName(bucketPrefix + "-jclouds-puts"); - // org.jclouds.aws.s3.domain.S3Object object = new - // org.jclouds.aws.s3.domain.S3Object(); - // object.setKey(id + ""); - // //object.setContentType("text/plain"); - // object.setContentType("application/octetstream"); - // //object.setData("this is a test"); - // object.setData(test); - // return clientProvider.getObject(s3Bucket, - // object.getKey()).get(120,TimeUnit.SECONDS) != - // org.jclouds.aws.s3.domain.S3Object.NOT_FOUND; - - // } - - @Override - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - object.getMetadata().setSize(data.available()); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object( - key); - object.getMetadata().setContentType(contentType); - object.setData(data); - return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; - } -} diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java b/aws/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java deleted file mode 100644 index 3d8e30b54a..0000000000 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java +++ /dev/null @@ -1,252 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import com.google.inject.Provider; -import org.jclouds.aws.s3.S3IntegrationTest; -import org.testng.ITestContext; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.*; -import java.util.concurrent.atomic.AtomicInteger; - -/** - * // TODO: Adrian: Document this! - * - * @author Adrian Cole - */ -@Test(groups = {"live"}) -public abstract class BasePerformance extends S3IntegrationTest { - protected boolean debugEnabled() { - return false; - } - - protected static int LOOP_COUNT = 100; - - protected ExecutorService exec; - protected final String BUCKET_BYTES = bucketPrefix + "-bytes"; - protected final String BUCKET_INPUTSTREAM = bucketPrefix + "-inputstream"; - protected final String BUCKET_STRING = bucketPrefix + "-string"; - protected final String BUCKET_FILE = bucketPrefix + "-file"; - protected final String[] BUCKETS = {BUCKET_BYTES, BUCKET_INPUTSTREAM, - BUCKET_STRING, BUCKET_FILE}; - protected PutBytesCallable putBytesCallable; - protected PutFileCallable putFileCallable; - protected PutInputStreamCallable putInputStreamCallable; - protected PutStringCallable putStringCallable; - - protected CompletionService completer; - - @BeforeTest - protected void setUpCallables() { - putBytesCallable = new PutBytesCallable(); - putFileCallable = new PutFileCallable(); - putInputStreamCallable = new PutInputStreamCallable(); - putStringCallable = new PutStringCallable(); - exec = Executors.newCachedThreadPool(); - completer = new ExecutorCompletionService(exec); - } - - @Override - @BeforeTest - protected void setUpClient(ITestContext context) throws Exception { - super.setUpClient(context); - for (String bucket : BUCKETS) { - client.putBucketIfNotExists(bucket).get(10, TimeUnit.SECONDS); - } - } - - @AfterTest - protected void tearDownExecutor() throws Exception { - exec.shutdownNow(); - exec = null; - } - - @Test(enabled = true) - public void testPutBytesSerial() throws Exception { - doSerial(putBytesCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutBytesParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putBytesCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutFileSerial() throws Exception { - doSerial(putFileCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutFileParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putFileCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutInputStreamSerial() throws Exception { - doSerial(putInputStreamCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putInputStreamCallable, LOOP_COUNT); - } - - @Test(enabled = true) - public void testPutStringSerial() throws Exception { - doSerial(putStringCallable, LOOP_COUNT / 10); - } - - @Test(enabled = true) - public void testPutStringParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putStringCallable, LOOP_COUNT); - } - - private void doSerial(Provider> provider, int loopCount) - throws Exception, ExecutionException { - for (int i = 0; i < loopCount; i++) - assert provider.get().call(); - } - - private void doParallel(Provider> provider, int loopCount) - throws InterruptedException, ExecutionException, TimeoutException { - for (int i = 0; i < loopCount; i++) - completer.submit(provider.get()); - for (int i = 0; i < loopCount; i++) - assert completer.take().get(10, TimeUnit.SECONDS); - } - - class PutBytesCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected byte[] test = new byte[1024 * 2]; - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putByteArray(BUCKET_BYTES, key.getAndIncrement() - + "", test, "application/octetstring"); - } - }; - - } - } - - class PutFileCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected File file = new File("pom.xml"); - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putFile(BUCKET_FILE, key.getAndIncrement() + "", - file, "text/xml"); - } - }; - - } - } - - class PutInputStreamCallable extends PutBytesCallable { - final AtomicInteger key = new AtomicInteger(0); - - @Override - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putInputStream(BUCKET_INPUTSTREAM, key - .getAndIncrement() - + "", new ByteArrayInputStream(test), - "application/octetstring"); - } - }; - - } - } - - class PutStringCallable implements Provider> { - final AtomicInteger key = new AtomicInteger(0); - protected String testString = "hello world!"; - - public Callable get() { - return new Callable() { - public Boolean call() throws Exception { - return putString(BUCKET_STRING, key.getAndIncrement() + "", - testString, "text/plain"); - } - }; - - } - } - - protected abstract boolean putByteArray(String bucket, String key, - byte[] data, String contentType) throws Exception; - - protected abstract boolean putFile(String bucket, String key, File data, - String contentType) throws Exception; - - protected abstract boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception; - - protected abstract boolean putString(String bucket, String key, - String data, String contentType) throws Exception; - - // private class BucketDeleter implements Callable { - // private BucketDeleter(S3Bucket bucket) { - // this.bucket = bucket; - // } - // - // private S3Bucket bucket; - // - // @Override - // public String toString() { - // return "BucketDeleter{" + "bucket=" + bucket + '}'; - // } - // - // public Boolean call() throws Exception { - // bucket = - // clientProvider.get(10,TimeUnit.SECONDS).getBucket(bucket).get(10,TimeUnit.SECONDS); - // List> deletes = new ArrayList>(); - // for (org.jclouds.aws.s3.domain.S3Object object : bucket - // .getContents()) { - // deletes.add(clientProvider.get(10,TimeUnit.SECONDS).deleteObject(bucket, - // object.getKey())); - // } - // for (Future isdeleted : deletes) - // assert isdeleted.get(10,TimeUnit.SECONDS) : - // String.format("failed to delete %1$ss", - // isdeleted); - // return - // clientProvider.get(10,TimeUnit.SECONDS).deleteBucket(bucket).get(10,TimeUnit.SECONDS); - // } - // } -} diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java b/aws/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java index 9501aa34a7..83f703b3ba 100644 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java +++ b/aws/s3/perftest/src/test/java/com/amazon/s3/DateServiceTest.java @@ -23,6 +23,9 @@ */ package com.amazon.s3; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + import java.util.Date; import java.util.Locale; import java.util.concurrent.Callable; @@ -41,9 +44,6 @@ import org.testng.annotations.Test; import com.google.inject.Guice; import com.google.inject.Injector; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - /* * TODO: Scrap any non-DateService references (eg Joda & Amazon) if/when * we confirm that the DateService is fast enough. @@ -57,253 +57,228 @@ import static org.testng.Assert.assertTrue; */ @Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.DateTest") public class DateServiceTest extends PerformanceTest { - Injector i = Guice.createInjector(); + Injector i = Guice.createInjector(); - DateService dateService = i.getInstance(DateService.class); + DateService dateService = i.getInstance(DateService.class); - private TestData[] testData; - class TestData { - public final String iso8601DateString; - public final String rfc822DateString; - public final Date date; - - TestData(String iso8601, String rfc822, Date date) { - this.iso8601DateString = iso8601; - this.rfc822DateString = rfc822; - this.date = date; - } - } - - private long startTime; - + private TestData[] testData; - public DateServiceTest() { - // Constant time test values, each TestData item must contain matching times! - testData = new TestData[] { - new TestData("2009-03-12T02:00:07.000Z", "Thu, 12 Mar 2009 02:00:07 GMT", new Date(1236823207000l)), - new TestData("2009-03-14T04:00:07.000Z", "Sat, 14 Mar 2009 04:00:07 GMT", new Date(1237003207000l)), - new TestData("2009-03-16T06:00:07.000Z", "Mon, 16 Mar 2009 06:00:07 GMT", new Date(1237183207000l)), - new TestData("2009-03-18T08:00:07.000Z", "Wed, 18 Mar 2009 08:00:07 GMT", new Date(1237363207000l)), - new TestData("2009-03-20T10:00:07.000Z", "Fri, 20 Mar 2009 10:00:07 GMT", new Date(1237543207000l)) - }; - } - - - // Joda items for performance comparisons - private DateTimeFormatter headerDateFormat = DateTimeFormat - .forPattern("EEE, dd MMM yyyy HH:mm:ss 'GMT'").withLocale(Locale.US); + class TestData { + public final String iso8601DateString; + public final String rfc822DateString; + public final Date date; - private DateTime jodaParseIso8601(String toParse) { - return new DateTime(toParse); - } + TestData(String iso8601, String rfc822, Date date) { + this.iso8601DateString = iso8601; + this.rfc822DateString = rfc822; + this.date = date; + } + } - private DateTime jodaParseRfc822(String toParse) { - return headerDateFormat.parseDateTime(toParse); - } + private long startTime; - private String timestampAsHeaderString() { - return toHeaderString(new DateTime()); - } + public DateServiceTest() { + // Constant time test values, each TestData item must contain matching times! + testData = new TestData[] { + new TestData("2009-03-12T02:00:07.000Z", "Thu, 12 Mar 2009 02:00:07 GMT", new Date( + 1236823207000l)), + new TestData("2009-03-14T04:00:07.000Z", "Sat, 14 Mar 2009 04:00:07 GMT", new Date( + 1237003207000l)), + new TestData("2009-03-16T06:00:07.000Z", "Mon, 16 Mar 2009 06:00:07 GMT", new Date( + 1237183207000l)), + new TestData("2009-03-18T08:00:07.000Z", "Wed, 18 Mar 2009 08:00:07 GMT", new Date( + 1237363207000l)), + new TestData("2009-03-20T10:00:07.000Z", "Fri, 20 Mar 2009 10:00:07 GMT", new Date( + 1237543207000l)) }; + } - private String toHeaderString(DateTime date) { - return headerDateFormat.print(date.withZone(DateTimeZone.UTC)); - } + // Joda items for performance comparisons + private DateTimeFormatter headerDateFormat = DateTimeFormat.forPattern( + "EEE, dd MMM yyyy HH:mm:ss 'GMT'").withLocale(Locale.US); - - private void startClock() { - startTime = System.currentTimeMillis(); - } - - private void printElapsedClockTime(String testName) { - System.out.println(testName + " took " + - (System.currentTimeMillis() - startTime) + "ms for " - + LOOP_COUNT+ " loops"); - } - - @Test - public void testIso8601DateParse() throws ExecutionException, - InterruptedException - { - DateTime dsDate = dateService.iso8601DateParse(testData[0].iso8601DateString); - assertEquals(dsDate.toDate(), testData[0].date); - } + private DateTime jodaParseIso8601(String toParse) { + return new DateTime(toParse); + } - @Test - public void testRfc822DateParse() throws ExecutionException, - InterruptedException - { - DateTime dsDate = dateService.rfc822DateParse(testData[0].rfc822DateString); - assertEquals(dsDate.toDate(), testData[0].date); - } + private DateTime jodaParseRfc822(String toParse) { + return headerDateFormat.parseDateTime(toParse); + } - @Test - public void testIso8601DateFormat() throws ExecutionException, - InterruptedException - { - String dsString = dateService.iso8601DateFormat(testData[0].date); - assertEquals(dsString, testData[0].iso8601DateString); - } + private String timestampAsHeaderString() { + return toHeaderString(new DateTime()); + } - @Test - public void testRfc822DateFormat() throws ExecutionException, - InterruptedException - { - String dsString = dateService.rfc822DateFormat(testData[0].date); - assertEquals(dsString, testData[0].rfc822DateString); - } + private String toHeaderString(DateTime date) { + return headerDateFormat.print(date.withZone(DateTimeZone.UTC)); + } - @Test - void testIso8601DateFormatResponseTime() throws ExecutionException, - InterruptedException { - for (int i = 0; i < LOOP_COUNT; i++) - dateService.iso8601DateFormat(); - } + private void startClock() { + startTime = System.currentTimeMillis(); + } - @Test - void testRfc822DateFormatResponseTime() throws ExecutionException, - InterruptedException { - for (int i = 0; i < LOOP_COUNT; i++) - dateService.rfc822DateFormat(); - } - - @Test - void testFormatIso8601DateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) { - final TestData myData = testData[i % testData.length]; - completer.submit(new Callable() { - public Boolean call() throws ExecutionException, - InterruptedException - { - String dsString = dateService.iso8601DateFormat(myData.date); - /* - * Comment-in the assert below to test thread safety. - * Comment it out to test performance - */ - assertEquals(dsString, myData.iso8601DateString); - return true; - } - }); - } - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testFormatIso8601DateInParallel"); - } + private void printElapsedClockTime(String testName) { + System.out.println(testName + " took " + (System.currentTimeMillis() - startTime) + "ms for " + + LOOP_COUNT + " loops"); + } - @Test - void testFormatAmazonDateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() { - AWSAuthConnection.httpDate(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testFormatAmazonDateInParallel"); - } + @Test + public void testIso8601DateParse() throws ExecutionException, InterruptedException { + DateTime dsDate = dateService.iso8601DateParse(testData[0].iso8601DateString); + assertEquals(dsDate.toDate(), testData[0].date); + } - @Test - void testFormatJodaDateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) { - final TestData myData = testData[i % testData.length]; - completer.submit(new Callable() { - public Boolean call() { - String jodaString = toHeaderString(new DateTime(myData.date)); - assertEquals(jodaString, myData.rfc822DateString); - return true; - } - }); - } - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testFormatJodaDateInParallel"); - } + @Test + public void testRfc822DateParse() throws ExecutionException, InterruptedException { + DateTime dsDate = dateService.rfc822DateParse(testData[0].rfc822DateString); + assertEquals(dsDate.toDate(), testData[0].date); + } - @Test - void testIso8601ParseDateSerialResponseTime() throws ExecutionException, - InterruptedException { - for (int i = 0; i < LOOP_COUNT; i++) - dateService.iso8601DateParse(testData[0].iso8601DateString); - } + @Test + public void testIso8601DateFormat() throws ExecutionException, InterruptedException { + String dsString = dateService.iso8601DateFormat(testData[0].date); + assertEquals(dsString, testData[0].iso8601DateString); + } - @Test - void testAmazonParseDateSerialResponseTime() { - for (int i = 0; i < LOOP_COUNT; i++) - AWSAuthConnection.httpDate(); - } + @Test + public void testRfc822DateFormat() throws ExecutionException, InterruptedException { + String dsString = dateService.rfc822DateFormat(testData[0].date); + assertEquals(dsString, testData[0].rfc822DateString); + } - @Test - void testParseIso8601DateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) { - final TestData myData = testData[i % testData.length]; - completer.submit(new Callable() { - public Boolean call() throws ExecutionException, - InterruptedException { - DateTime dsDate = dateService.iso8601DateParse(myData.iso8601DateString); - assertEquals(dsDate.toDate(), myData.date); - return true; - } - }); - } - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testParseIso8601DateInParallel"); - } + @Test + void testIso8601DateFormatResponseTime() throws ExecutionException, InterruptedException { + for (int i = 0; i < LOOP_COUNT; i++) + dateService.iso8601DateFormat(); + } - @Test - void testParseAmazonDateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) - completer.submit(new Callable() { - public Boolean call() { - AWSAuthConnection.httpDate(); - return true; - } - }); - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testParseAmazonDateInParallel"); - } + @Test + void testRfc822DateFormatResponseTime() throws ExecutionException, InterruptedException { + for (int i = 0; i < LOOP_COUNT; i++) + dateService.rfc822DateFormat(); + } - @Test - void testParseJodaDateInParallel() throws InterruptedException, - ExecutionException { - CompletionService completer = new ExecutorCompletionService( - exec); - startClock(); - for (int i = 0; i < LOOP_COUNT; i++) { - final TestData myData = testData[i % testData.length]; - completer.submit(new Callable() { - public Boolean call() { - Date jodaDate = jodaParseIso8601(myData.iso8601DateString).toDate(); - assertEquals(jodaDate, myData.date); - return true; - } - }); - } - for (int i = 0; i < LOOP_COUNT; i++) - assertTrue(completer.take().get()); - printElapsedClockTime("testParseJodaDateInParallel"); - } + @Test + void testFormatIso8601DateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) { + final TestData myData = testData[i % testData.length]; + completer.submit(new Callable() { + public Boolean call() throws ExecutionException, InterruptedException { + String dsString = dateService.iso8601DateFormat(myData.date); + /* + * Comment-in the assert below to test thread safety. Comment it out to test + * performance + */ + assertEquals(dsString, myData.iso8601DateString); + return true; + } + }); + } + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testFormatIso8601DateInParallel"); + } + + @Test + void testFormatAmazonDateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) + completer.submit(new Callable() { + public Boolean call() { + AWSAuthConnection.httpDate(); + return true; + } + }); + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testFormatAmazonDateInParallel"); + } + + @Test + void testFormatJodaDateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) { + final TestData myData = testData[i % testData.length]; + completer.submit(new Callable() { + public Boolean call() { + String jodaString = toHeaderString(new DateTime(myData.date)); + assertEquals(jodaString, myData.rfc822DateString); + return true; + } + }); + } + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testFormatJodaDateInParallel"); + } + + @Test + void testIso8601ParseDateSerialResponseTime() throws ExecutionException, InterruptedException { + for (int i = 0; i < LOOP_COUNT; i++) + dateService.iso8601DateParse(testData[0].iso8601DateString); + } + + @Test + void testAmazonParseDateSerialResponseTime() { + for (int i = 0; i < LOOP_COUNT; i++) + AWSAuthConnection.httpDate(); + } + + @Test + void testParseIso8601DateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) { + final TestData myData = testData[i % testData.length]; + completer.submit(new Callable() { + public Boolean call() throws ExecutionException, InterruptedException { + DateTime dsDate = dateService.iso8601DateParse(myData.iso8601DateString); + assertEquals(dsDate.toDate(), myData.date); + return true; + } + }); + } + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testParseIso8601DateInParallel"); + } + + @Test + void testParseAmazonDateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) + completer.submit(new Callable() { + public Boolean call() { + AWSAuthConnection.httpDate(); + return true; + } + }); + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testParseAmazonDateInParallel"); + } + + @Test + void testParseJodaDateInParallel() throws InterruptedException, ExecutionException { + CompletionService completer = new ExecutorCompletionService(exec); + startClock(); + for (int i = 0; i < LOOP_COUNT; i++) { + final TestData myData = testData[i % testData.length]; + completer.submit(new Callable() { + public Boolean call() { + Date jodaDate = jodaParseIso8601(myData.iso8601DateString).toDate(); + assertEquals(jodaDate, myData.date); + return true; + } + }); + } + for (int i = 0; i < LOOP_COUNT; i++) + assertTrue(completer.take().get()); + printElapsedClockTime("testParseJodaDateInParallel"); + } } \ No newline at end of file diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceLiveTest.java deleted file mode 100644 index 0424c613d8..0000000000 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceLiveTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.jets3t.service.S3Service; -import org.jets3t.service.impl.rest.httpclient.RestS3Service; -import org.jets3t.service.security.AWSCredentials; -import org.testng.ITestContext; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.InputStream; -import java.util.concurrent.ExecutionException; - -/** - * Runs operations that jets3t is capable of performing. - * - * @author Adrian Cole - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.Jets3tPerformanceLiveTest", groups = {"live"}) -public class Jets3tPerformanceLiveTest extends BasePerformance { - private S3Service jetClient; - - @Override - protected void setUpCredentials(String AWSAccessKeyId, String AWSSecretAccessKey, ITestContext context) - throws Exception { - super.setUpCredentials(AWSAccessKeyId, AWSSecretAccessKey, context); - jetClient = new RestS3Service(new AWSCredentials(AWSAccessKeyId, - AWSSecretAccessKey)); - } - - @Override - @Test(enabled = false) - public void testPutStringSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - - @Override - @Test(enabled = false) - public void testPutBytesSerial() throws Exception { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutBytesParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); - } - - @Override - @Test(enabled = false) - protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - - } - - @Override - protected boolean putFile(String bucket, String key, File data, - String contentType) throws Exception { - org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object( - key); - object.setContentType(contentType); - object.setDataInputFile(data); - object.setContentLength(data.length()); - return jetClient.putObject(bucket, object) != null; - } - - @Override - protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object( - key); - object.setContentType(contentType); - object.setDataInputStream(data); - object.setContentLength(data.available()); - return jetClient.putObject(bucket, object) != null; - } - - @Override - protected boolean putString(String bucket, String key, String data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); - } - -} \ No newline at end of file diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java b/aws/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java deleted file mode 100644 index 403ece911f..0000000000 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/S3UtilsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * Copyright (C) 2009 Adrian Cole - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package com.amazon.s3; - -import org.testng.annotations.Test; - -import java.security.InvalidKeyException; -import java.security.NoSuchAlgorithmException; -import java.security.NoSuchProviderException; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorCompletionService; - -/** - * Compares performance of encryption operations. - * - * @author Adrian Cole - * - */ -@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.S3UtilsTest") -public class S3UtilsTest extends org.jclouds.aws.s3.S3UtilsTest { - - @Test(dataProvider = "hmacsha1") - void testAmazonSampleDigestSerialResponseTime(byte[] key, String message, String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException { - for (int i = 0; i < 10000; i++) - testAmazonSampleDigest(key, message, base64Digest); - } - - @Test(dataProvider = "hmacsha1") - public void testAmazonSampleDigest(byte[] key, String message, String base64Digest) { - String encoded = Utils.encode(new String(key), message, false); - assert encoded.equals(base64Digest); - } - - @Test(dataProvider = "hmacsha1") - void testAmazonSampleDigestParallelResponseTime(final byte[] key, final String message, final String base64Digest) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, InterruptedException, ExecutionException { - CompletionService completer = new ExecutorCompletionService(exec); - for (int i = 0; i < 10000; i++) - completer.submit(new Callable() { - public Boolean call() { - try { - testAmazonSampleDigest(key, message, base64Digest); - return true; - } catch (Exception e) { - return false; - } - } - }); - for (int i = 0; i < 10000; i++) assert completer.take().get(); - } -} \ No newline at end of file diff --git a/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/AmazonPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/AmazonPerformanceLiveTest.java new file mode 100644 index 0000000000..1708aec2ec --- /dev/null +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/AmazonPerformanceLiveTest.java @@ -0,0 +1,124 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3; + +import java.io.File; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.ExecutionException; + +import org.jclouds.aws.s3.reference.S3Constants; +import org.testng.ITestContext; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; + +import com.amazon.s3.AWSAuthConnection; + +/** + * Runs operations that amazon s3 sample code is capable of performing. + * + * @author Adrian Cole + */ +@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.AmazonPerformanceLiveTest", groups = { "live" }) +public class AmazonPerformanceLiveTest extends BasePerformance { + private AWSAuthConnection amzClient; + + @Override + @BeforeTest + @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) + protected void setUpCredentials(@Optional String AWSAccessKeyId, + @Optional String AWSSecretAccessKey, ITestContext context) throws Exception { + super.setUpCredentials(AWSAccessKeyId, AWSSecretAccessKey, context); + amzClient = new AWSAuthConnection(AWSAccessKeyId, AWSSecretAccessKey, false); + } + + @Override + @Test(enabled = false) + public void testPutFileSerial() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutFileParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutInputStreamSerial() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutInputStreamParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutStringSerial() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutStringParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + protected boolean putByteArray(String bucket, String key, byte[] data, String contentType) + throws Exception { + com.amazon.s3.S3Object object = new com.amazon.s3.S3Object(data, null); + Map> headers = new TreeMap>(); + headers.put("Content-Type", Arrays.asList(new String[] { contentType })); + return amzClient.put(bucket, key, object, headers).connection.getResponseMessage() != null; + } + + @Override + protected boolean putFile(String bucket, String key, File data, String contentType) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + protected boolean putInputStream(String bucket, String key, InputStream data, String contentType) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + protected boolean putString(String bucket, String key, String data, String contentType) + throws Exception { + throw new UnsupportedOperationException(); + } + +} diff --git a/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BaseJCloudsPerformance.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BaseJCloudsPerformance.java new file mode 100644 index 0000000000..03f2ca409e --- /dev/null +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BaseJCloudsPerformance.java @@ -0,0 +1,90 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3; + +import java.io.File; +import java.io.InputStream; +import java.util.concurrent.TimeUnit; + +/** + * // TODO: Adrian: Document this! + * + * @author Adrian Cole + */ +public abstract class BaseJCloudsPerformance extends BasePerformance { + // boolean get + // ( + // int id) throws Exception { + // S3Bucket s3Bucket = new S3Bucket(); + // s3Bucket.setName(bucketPrefix + "-jclouds-puts"); + // org.jclouds.aws.s3.domain.S3Object object = new + // org.jclouds.aws.s3.domain.S3Object(); + // object.setKey(id + ""); + // //object.setContentType("text/plain"); + // object.setContentType("application/octetstream"); + // //object.setData("this is a test"); + // object.setData(test); + // return clientProvider.getObject(s3Bucket, + // object.getKey()).get(120,TimeUnit.SECONDS) != + // org.jclouds.aws.s3.domain.S3Object.NOT_FOUND; + + // } + + @Override + protected boolean putByteArray(String bucket, String key, byte[] data, String contentType) + throws Exception { + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(key); + object.getMetadata().setContentType(contentType); + object.setData(data); + return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; + } + + @Override + protected boolean putFile(String bucket, String key, File data, String contentType) + throws Exception { + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(key); + object.getMetadata().setContentType(contentType); + object.setData(data); + return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; + } + + @Override + protected boolean putInputStream(String bucket, String key, InputStream data, String contentType) + throws Exception { + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(key); + object.getMetadata().setContentType(contentType); + object.setData(data); + object.getMetadata().setSize(data.available()); + return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; + } + + @Override + protected boolean putString(String bucket, String key, String data, String contentType) + throws Exception { + org.jclouds.aws.s3.domain.S3Object object = new org.jclouds.aws.s3.domain.S3Object(key); + object.getMetadata().setContentType(contentType); + object.setData(data); + return client.putObject(bucket, object).get(120, TimeUnit.SECONDS) != null; + } +} diff --git a/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BasePerformance.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BasePerformance.java new file mode 100644 index 0000000000..6dc2ccee68 --- /dev/null +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/BasePerformance.java @@ -0,0 +1,226 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletionService; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorCompletionService; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicInteger; + +import org.jclouds.aws.s3.S3IntegrationTest; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.inject.Provider; + +/** + * Tests relative performance of S3 functions. + * + * @author Adrian Cole + */ +@Test(groups = { "live" }) +public abstract class BasePerformance extends S3IntegrationTest { + @Override + protected boolean debugEnabled() { + return false; + } + + protected static int LOOP_COUNT = 100; + + protected ExecutorService exec; + + protected CompletionService completer; + + @BeforeTest + protected void setUpCallables() { + exec = Executors.newCachedThreadPool(); + completer = new ExecutorCompletionService(exec); + } + + @AfterTest + protected void tearDownExecutor() throws Exception { + exec.shutdownNow(); + exec = null; + } + + @Test(enabled = true) + public void testPutBytesSerial() throws Exception { + doSerial(new PutBytesCallable(this.bucketName), LOOP_COUNT / 10); + } + + @Test(enabled = true) + public void testPutBytesParallel() throws InterruptedException, ExecutionException, + TimeoutException { + doParallel(new PutBytesCallable(this.bucketName), LOOP_COUNT); + } + + @Test(enabled = true) + public void testPutFileSerial() throws Exception { + doSerial(new PutFileCallable(this.bucketName), LOOP_COUNT / 10); + } + + @Test(enabled = true) + public void testPutFileParallel() throws InterruptedException, ExecutionException, + TimeoutException { + doParallel(new PutFileCallable(this.bucketName), LOOP_COUNT); + } + + @Test(enabled = true) + public void testPutInputStreamSerial() throws Exception { + doSerial(new PutInputStreamCallable(this.bucketName), LOOP_COUNT / 10); + } + + @Test(enabled = true) + public void testPutInputStreamParallel() throws InterruptedException, ExecutionException, + TimeoutException { + doParallel(new PutInputStreamCallable(this.bucketName), LOOP_COUNT); + } + + @Test(enabled = true) + public void testPutStringSerial() throws Exception { + doSerial(new PutStringCallable(this.bucketName), LOOP_COUNT / 10); + } + + @Test(enabled = true) + public void testPutStringParallel() throws InterruptedException, ExecutionException, + TimeoutException { + doParallel(new PutStringCallable(this.bucketName), LOOP_COUNT); + } + + private void doSerial(Provider> provider, int loopCount) throws Exception, + ExecutionException { + for (int i = 0; i < loopCount; i++) + assert provider.get().call(); + } + + private void doParallel(Provider> provider, int loopCount) + throws InterruptedException, ExecutionException, TimeoutException { + for (int i = 0; i < loopCount; i++) + completer.submit(provider.get()); + for (int i = 0; i < loopCount; i++) + assert completer.take().get(10, TimeUnit.SECONDS); + } + + class PutBytesCallable implements Provider> { + final AtomicInteger key = new AtomicInteger(0); + protected byte[] test = new byte[1024 * 2]; + private final String bucketName; + + public PutBytesCallable(String bucketName) { + this.bucketName = bucketName; + } + + public Callable get() { + return new Callable() { + public Boolean call() throws Exception { + String bucketName2 = bucketName; + return putByteArray(bucketName2, key.getAndIncrement() + "", test, + "application/octetstring"); + } + }; + + } + } + + class PutFileCallable implements Provider> { + final AtomicInteger key = new AtomicInteger(0); + protected File file = new File("pom.xml"); + private final String bucketName; + + public PutFileCallable(String bucketName) { + this.bucketName = bucketName; + } + + public Callable get() { + return new Callable() { + public Boolean call() throws Exception { + return putFile(bucketName, key.getAndIncrement() + "", file, "text/xml"); + } + }; + + } + } + + class PutInputStreamCallable extends PutBytesCallable { + final AtomicInteger key = new AtomicInteger(0); + private final String bucketName; + + public PutInputStreamCallable(String bucketName) { + super(bucketName); + this.bucketName = bucketName; + } + + @Override + public Callable get() { + return new Callable() { + public Boolean call() throws Exception { + return putInputStream(bucketName, key.getAndIncrement() + "", + new ByteArrayInputStream(test), "application/octetstring"); + } + }; + + } + } + + class PutStringCallable implements Provider> { + final AtomicInteger key = new AtomicInteger(0); + protected String testString = "hello world!"; + private final String bucketName; + + public PutStringCallable(String bucketName) { + this.bucketName = bucketName; + } + + public Callable get() { + return new Callable() { + public Boolean call() throws Exception { + return putString(bucketName, key.getAndIncrement() + "", testString, "text/plain"); + } + }; + + } + } + + protected abstract boolean putByteArray(String bucket, String key, byte[] data, + String contentType) throws Exception; + + protected abstract boolean putFile(String bucket, String key, File data, String contentType) + throws Exception; + + protected abstract boolean putInputStream(String bucket, String key, InputStream data, + String contentType) throws Exception; + + protected abstract boolean putString(String bucket, String key, String data, String contentType) + throws Exception; + +} diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsNioPerformanceLiveTest.java similarity index 98% rename from aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceLiveTest.java rename to aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsNioPerformanceLiveTest.java index 5caa213bb8..b30a27df51 100644 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsNioPerformanceLiveTest.java +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsNioPerformanceLiveTest.java @@ -21,14 +21,14 @@ * under the License. * ==================================================================== */ -package com.amazon.s3; +package org.jclouds.aws.s3; +import java.util.Properties; -import com.google.inject.Module; import org.jclouds.http.httpnio.config.HttpNioConnectionPoolClientModule; import org.testng.annotations.Test; -import java.util.Properties; +import com.google.inject.Module; @Test(sequential = true, testName = "s3.JCloudsNioPerformanceLiveTest", groups = {"live"}) public class JCloudsNioPerformanceLiveTest extends BaseJCloudsPerformance { diff --git a/aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsPerformanceLiveTest.java similarity index 97% rename from aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceLiveTest.java rename to aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsPerformanceLiveTest.java index 45201b3ca5..ae37943559 100644 --- a/aws/s3/perftest/src/test/java/com/amazon/s3/JCloudsPerformanceLiveTest.java +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/JCloudsPerformanceLiveTest.java @@ -21,8 +21,7 @@ * under the License. * ==================================================================== */ -package com.amazon.s3; - +package org.jclouds.aws.s3; import org.testng.annotations.Test; /** diff --git a/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/Jets3tPerformanceLiveTest.java b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/Jets3tPerformanceLiveTest.java new file mode 100644 index 0000000000..ed22a3e8b2 --- /dev/null +++ b/aws/s3/perftest/src/test/java/org/jclouds/aws/s3/Jets3tPerformanceLiveTest.java @@ -0,0 +1,127 @@ +package org.jclouds.aws.s3; + +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +import java.io.File; +import java.io.InputStream; +import java.util.concurrent.ExecutionException; + +import org.jclouds.aws.s3.reference.S3Constants; +import org.jets3t.service.S3Service; +import org.jets3t.service.S3ServiceException; +import org.jets3t.service.impl.rest.httpclient.RestS3Service; +import org.jets3t.service.security.AWSCredentials; +import org.testng.ITestContext; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +/** + * Runs operations that jets3t is capable of performing. + * + * @author Adrian Cole + */ +@Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.Jets3tPerformanceLiveTest", groups = { "live" }) +public class Jets3tPerformanceLiveTest extends BasePerformance { + private S3Service jetClient; + + @BeforeTest + public void setUpJetS3t(ITestContext testContext) throws S3ServiceException { + String AWSAccessKeyId = (String) testContext + .getAttribute(S3Constants.PROPERTY_AWS_ACCESSKEYID); + String AWSSecretAccessKey = (String) testContext + .getAttribute(S3Constants.PROPERTY_AWS_SECRETACCESSKEY); + jetClient = new RestS3Service(new AWSCredentials(AWSAccessKeyId, AWSSecretAccessKey)); + } + + @Override + @Test(enabled = false) + public void testPutStringSerial() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutBytesSerial() throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutStringParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutBytesParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutInputStreamParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + public void testPutFileParallel() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + @Test(enabled = false) + protected boolean putByteArray(String bucket, String key, byte[] data, String contentType) + throws Exception { + throw new UnsupportedOperationException(); + + } + + @Override + protected boolean putFile(String bucket, String key, File data, String contentType) + throws Exception { + org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object(key); + object.setContentType(contentType); + object.setDataInputFile(data); + object.setContentLength(data.length()); + return jetClient.putObject(bucket, object) != null; + } + + @Override + protected boolean putInputStream(String bucket, String key, InputStream data, String contentType) + throws Exception { + org.jets3t.service.model.S3Object object = new org.jets3t.service.model.S3Object(key); + object.setContentType(contentType); + object.setDataInputStream(data); + object.setContentLength(data.available()); + return jetClient.putObject(bucket, object) != null; + } + + @Override + protected boolean putString(String bucket, String key, String data, String contentType) + throws Exception { + throw new UnsupportedOperationException(); + } + +} \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/http/commands/callables/ReturnStringIf200Test.java b/core/src/test/java/org/jclouds/http/commands/callables/ReturnStringIf200Test.java index 59433a0715..640613c325 100644 --- a/core/src/test/java/org/jclouds/http/commands/callables/ReturnStringIf200Test.java +++ b/core/src/test/java/org/jclouds/http/commands/callables/ReturnStringIf200Test.java @@ -35,66 +35,55 @@ import java.util.concurrent.TimeoutException; import org.apache.commons.io.IOUtils; import org.jclouds.http.HttpFutureCommand; import org.jclouds.http.HttpResponse; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -@Test +@Test(groups = { "unit" }) public class ReturnStringIf200Test { - private HttpFutureCommand.ResponseCallable callable = null; + @Test + public void testExceptionWhenNoContentOn200() throws ExecutionException, InterruptedException, + TimeoutException, IOException { + HttpFutureCommand.ResponseCallable callable = new ReturnStringIf200(); + HttpResponse response = createMock(HttpResponse.class); + expect(response.getStatusCode()).andReturn(200).atLeastOnce(); + expect(response.getContent()).andReturn(null); + replay(response); + callable.setResponse(response); + try { + callable.call(); + } catch (Exception e) { + assert e.getMessage().equals("no content"); + } + verify(response); + } - @BeforeMethod - void setUp() { - callable = new ReturnStringIf200(); - } + @Test + public void testExceptionWhenIOExceptionOn200() throws ExecutionException, InterruptedException, + TimeoutException, IOException { + HttpFutureCommand.ResponseCallable callable = new ReturnStringIf200(); + HttpResponse response = createMock(HttpResponse.class); + expect(response.getStatusCode()).andReturn(200).atLeastOnce(); + RuntimeException exception = new RuntimeException("bad"); + expect(response.getContent()).andThrow(exception); + replay(response); + callable.setResponse(response); + try { + callable.call(); + } catch (Exception e) { + assert e.equals(exception); + } + verify(response); + } - @AfterMethod - void tearDown() { - callable = null; - } - - @Test - public void testExceptionWhenNoContentOn200() throws ExecutionException, - InterruptedException, TimeoutException, IOException { - HttpResponse response = createMock(HttpResponse.class); - expect(response.getStatusCode()).andReturn(200).atLeastOnce(); - expect(response.getContent()).andReturn(null); - replay(response); - callable.setResponse(response); - try { - callable.call(); - } catch (Exception e) { - assert e.getMessage().equals("no content"); - } - verify(response); - } - - @Test - public void testExceptionWhenIOExceptionOn200() throws ExecutionException, - InterruptedException, TimeoutException, IOException { - HttpResponse response = createMock(HttpResponse.class); - expect(response.getStatusCode()).andReturn(200).atLeastOnce(); - RuntimeException exception = new RuntimeException("bad"); - expect(response.getContent()).andThrow(exception); - replay(response); - callable.setResponse(response); - try { - callable.call(); - } catch (Exception e) { - assert e.equals(exception); - } - verify(response); - } - - @Test - public void testResponseOk() throws Exception { - HttpResponse response = createMock(HttpResponse.class); - expect(response.getStatusCode()).andReturn(200).atLeastOnce(); - expect(response.getContent()).andReturn(IOUtils.toInputStream("hello")); - replay(response); - callable.setResponse(response); - assert "hello".equals(callable.call()); - verify(response); - } + @Test + public void testResponseOk() throws Exception { + HttpFutureCommand.ResponseCallable callable = new ReturnStringIf200(); + HttpResponse response = createMock(HttpResponse.class); + expect(response.getStatusCode()).andReturn(200).atLeastOnce(); + expect(response.getContent()).andReturn(IOUtils.toInputStream("hello")); + replay(response); + callable.setResponse(response); + assert "hello".equals(callable.call()); + verify(response); + } } \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/test/testng/UnitTestStatusListener.java b/core/src/test/java/org/jclouds/test/testng/UnitTestStatusListener.java new file mode 100644 index 0000000000..3b83d0d22b --- /dev/null +++ b/core/src/test/java/org/jclouds/test/testng/UnitTestStatusListener.java @@ -0,0 +1,76 @@ +package org.jclouds.test.testng; + +import java.util.concurrent.atomic.AtomicInteger; + +import org.testng.IClass; +import org.testng.ITestContext; +import org.testng.ITestListener; +import org.testng.ITestResult; + +/** + * adapted from the following class: + * + * @see org.UnitTestStatusListener.test.testng.UnitTestTestNGListener + * @author Adrian Cole + * @author dpospisi@redhat.com + * @author Mircea.Markus@jboss.com + */ +public class UnitTestStatusListener implements ITestListener { + + /** + * Holds test classes actually running in all threads. + */ + private ThreadLocal threadTestClass = new ThreadLocal(); + private ThreadLocal threadTestStart = new ThreadLocal(); + + private AtomicInteger failed = new AtomicInteger(0); + private AtomicInteger succeded = new AtomicInteger(0); + private AtomicInteger skipped = new AtomicInteger(0); + + public void onTestStart(ITestResult res) { + System.out.println("Starting test " + getTestDesc(res)); + threadTestClass.set(res.getTestClass()); + threadTestStart.set(System.currentTimeMillis()); + } + + synchronized public void onTestSuccess(ITestResult arg0) { + System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " succeeded: " + + (System.currentTimeMillis() - threadTestStart.get()) + "ms"); + succeded.incrementAndGet(); + printStatus(); + } + + synchronized public void onTestFailure(ITestResult arg0) { + System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " failed."); + failed.incrementAndGet(); + printStatus(); + } + + synchronized public void onTestSkipped(ITestResult arg0) { + System.out.println(getThreadId() + " Test " + getTestDesc(arg0) + " skipped."); + skipped.incrementAndGet(); + printStatus(); + } + + public void onTestFailedButWithinSuccessPercentage(ITestResult arg0) { + } + + public void onStart(ITestContext arg0) { + } + + public void onFinish(ITestContext arg0) { + } + + private String getThreadId() { + return "[" + Thread.currentThread().getName() + "]"; + } + + private String getTestDesc(ITestResult res) { + return res.getMethod().getMethodName() + "(" + res.getTestClass().getName() + ")"; + } + + private void printStatus() { + System.out.println("Test suite progress: tests succeeded: " + succeded.get() + ", failed: " + + failed.get() + ", skipped: " + skipped.get() + "."); + } +} diff --git a/project/pom.xml b/project/pom.xml index 5cbf14e8bb..abd0506ba6 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -169,7 +169,9 @@ test - @@ -183,14 +185,22 @@ + methods + 5 + unit,performance + integration,live --> **/*IntegrationTest.java **/*LiveTest.java + + + listener + org.jclouds.test.testng.UnitTestStatusListener + +