From 8b3424eaad7079a99d4468f3aff8b81be1af00ac Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Wed, 20 May 2009 11:51:31 +0000 Subject: [PATCH] fixed broken build for performance test git-svn-id: http://jclouds.googlecode.com/svn/trunk@812 3d8758e0-26b5-11de-8745-db77d3ebf521 --- s3/perftest/pom.xml | 6 + .../com/amazon/s3/AmazonPerformanceTest.java | 75 +++---- .../com/amazon/s3/BaseJCloudsPerformance.java | 52 ++--- .../java/com/amazon/s3/BasePerformance.java | 196 ++++++++---------- .../com/amazon/s3/Jets3tPerformanceTest.java | 81 ++++---- 5 files changed, 202 insertions(+), 208 deletions(-) diff --git a/s3/perftest/pom.xml b/s3/perftest/pom.xml index 04b5b559a3..afd2a04985 100644 --- a/s3/perftest/pom.xml +++ b/s3/perftest/pom.xml @@ -72,6 +72,12 @@ test-jar test + + xstream + xstream + 1.2 + test + ${project.groupId} jclouds-httpnio diff --git a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java index 45be6ec032..8b0482a89f 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java +++ b/s3/perftest/src/test/java/com/amazon/s3/AmazonPerformanceTest.java @@ -23,6 +23,13 @@ */ 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; @@ -31,16 +38,10 @@ import java.util.Map; import java.util.TreeMap; import java.util.concurrent.ExecutionException; -import org.jclouds.aws.s3.reference.S3Constants; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - /** * Runs operations that amazon s3 sample code is capable of performing. - * + * * @author Adrian Cole */ @Test(sequential = true, timeOut = 2 * 60 * 1000, testName = "s3.AmazonPerformance") @@ -49,82 +50,82 @@ public class AmazonPerformanceTest extends BasePerformance { @Override @BeforeTest - @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) - protected void setUpClient(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey) throws Exception { - super.setUpClient(AWSAccessKeyId, AWSSecretAccessKey); - amzClient = new AWSAuthConnection(AWSAccessKeyId, AWSSecretAccessKey, - false); + @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(); + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutInputStreamSerial() throws Exception { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutStringSerial() throws Exception { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + 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; + 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(); + String contentType) throws Exception { + throw new UnsupportedOperationException(); } @Override protected boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception { - throw new UnsupportedOperationException(); + 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(); + String contentType) throws Exception { + throw new UnsupportedOperationException(); } } diff --git a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java b/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java index ad6412005b..db1aacf2ec 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java +++ b/s3/perftest/src/test/java/com/amazon/s3/BaseJCloudsPerformance.java @@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public abstract class BaseJCloudsPerformance extends BasePerformance { @@ -53,42 +53,42 @@ public abstract class BaseJCloudsPerformance extends BasePerformance { @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; + 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; + 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; + 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; + 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/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java b/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java index f0128e8560..1724b24aba 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java +++ b/s3/perftest/src/test/java/com/amazon/s3/BasePerformance.java @@ -23,39 +23,28 @@ */ package com.amazon.s3; +import com.google.inject.Provider; +import org.jclouds.aws.s3.S3IntegrationTest; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import org.testng.ITestContext; + 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.*; import java.util.concurrent.atomic.AtomicInteger; -import org.jclouds.aws.s3.S3IntegrationTest; -import org.jclouds.aws.s3.reference.S3Constants; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Optional; -import org.testng.annotations.Parameters; -import org.testng.annotations.Test; - - -import com.google.inject.Provider; - /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ @Test public abstract class BasePerformance extends S3IntegrationTest { protected boolean debugEnabled() { - return false; + return false; } protected static int LOOP_COUNT = 100; @@ -65,8 +54,8 @@ public abstract class BasePerformance extends S3IntegrationTest { 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 final String[] BUCKETS = {BUCKET_BYTES, BUCKET_INPUTSTREAM, + BUCKET_STRING, BUCKET_FILE}; protected PutBytesCallable putBytesCallable; protected PutFileCallable putFileCallable; protected PutInputStreamCallable putInputStreamCallable; @@ -76,163 +65,160 @@ public abstract class BasePerformance extends S3IntegrationTest { @BeforeTest protected void setUpCallables() { - putBytesCallable = new PutBytesCallable(); - putFileCallable = new PutFileCallable(); - putInputStreamCallable = new PutInputStreamCallable(); - putStringCallable = new PutStringCallable(); - exec = Executors.newCachedThreadPool(); - completer = new ExecutorCompletionService(exec); + putBytesCallable = new PutBytesCallable(); + putFileCallable = new PutFileCallable(); + putInputStreamCallable = new PutInputStreamCallable(); + putStringCallable = new PutStringCallable(); + exec = Executors.newCachedThreadPool(); + completer = new ExecutorCompletionService(exec); } @Override @BeforeTest - @Parameters( { S3Constants.PROPERTY_AWS_ACCESSKEYID, - S3Constants.PROPERTY_AWS_SECRETACCESSKEY }) - protected void setUpClient(@Optional String AWSAccessKeyId, - @Optional String AWSSecretAccessKey) throws Exception { - super.setUpClient(AWSAccessKeyId, AWSSecretAccessKey); - for (String bucket : BUCKETS) { - client.putBucketIfNotExists(bucket).get(10, TimeUnit.SECONDS); - } + 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; + exec.shutdownNow(); + exec = null; } @Test(enabled = true) public void testPutBytesSerial() throws Exception { - doSerial(putBytesCallable, LOOP_COUNT / 10); + doSerial(putBytesCallable, LOOP_COUNT / 10); } @Test(enabled = true) public void testPutBytesParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putBytesCallable, LOOP_COUNT); + ExecutionException, TimeoutException { + doParallel(putBytesCallable, LOOP_COUNT); } @Test(enabled = true) public void testPutFileSerial() throws Exception { - doSerial(putFileCallable, LOOP_COUNT / 10); + doSerial(putFileCallable, LOOP_COUNT / 10); } @Test(enabled = true) public void testPutFileParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putFileCallable, LOOP_COUNT); + ExecutionException, TimeoutException { + doParallel(putFileCallable, LOOP_COUNT); } @Test(enabled = true) public void testPutInputStreamSerial() throws Exception { - doSerial(putInputStreamCallable, LOOP_COUNT / 10); + doSerial(putInputStreamCallable, LOOP_COUNT / 10); } @Test(enabled = true) public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putInputStreamCallable, LOOP_COUNT); + ExecutionException, TimeoutException { + doParallel(putInputStreamCallable, LOOP_COUNT); } @Test(enabled = true) public void testPutStringSerial() throws Exception { - doSerial(putStringCallable, LOOP_COUNT / 10); + doSerial(putStringCallable, LOOP_COUNT / 10); } @Test(enabled = true) public void testPutStringParallel() throws InterruptedException, - ExecutionException, TimeoutException { - doParallel(putStringCallable, LOOP_COUNT); + 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(); + 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); + 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]; + 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"); - } - }; + 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"); + 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"); - } - }; + 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); + 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"); - } - }; + @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!"; + 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"); - } - }; + 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; + byte[] data, String contentType) throws Exception; protected abstract boolean putFile(String bucket, String key, File data, - String contentType) throws Exception; + String contentType) throws Exception; protected abstract boolean putInputStream(String bucket, String key, - InputStream data, String contentType) throws Exception; + InputStream data, String contentType) throws Exception; protected abstract boolean putString(String bucket, String key, - String data, String contentType) throws Exception; + String data, String contentType) throws Exception; // private class BucketDeleter implements Callable { // private BucketDeleter(S3Bucket bucket) { diff --git a/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java b/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java index 08832c43b1..a8518d6f19 100644 --- a/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java +++ b/s3/perftest/src/test/java/com/amazon/s3/Jets3tPerformanceTest.java @@ -23,18 +23,19 @@ */ 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; -import org.jets3t.service.S3Service; -import org.jets3t.service.impl.rest.httpclient.RestS3Service; -import org.jets3t.service.security.AWSCredentials; -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.Jets3tPerformance") @@ -42,88 +43,88 @@ public class Jets3tPerformanceTest extends BasePerformance { private S3Service jetClient; @Override - protected void setUpClient(String AWSAccessKeyId, String AWSSecretAccessKey) - throws Exception { - super.setUpClient(AWSAccessKeyId, AWSSecretAccessKey); - jetClient = new RestS3Service(new AWSCredentials(AWSAccessKeyId, - AWSSecretAccessKey)); + 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(); + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutBytesSerial() throws Exception { - throw new UnsupportedOperationException(); + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutStringParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } - + @Override @Test(enabled = false) public void testPutBytesParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutInputStreamParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) public void testPutFileParallel() throws InterruptedException, - ExecutionException { - throw new UnsupportedOperationException(); + ExecutionException { + throw new UnsupportedOperationException(); } @Override @Test(enabled = false) protected boolean putByteArray(String bucket, String key, byte[] data, - String contentType) throws Exception { - throw new UnsupportedOperationException(); + 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; + 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; + 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(); + String contentType) throws Exception { + throw new UnsupportedOperationException(); } } \ No newline at end of file