From dac9da390a0e20d20b3aef1c95169eeaed373e1c Mon Sep 17 00:00:00 2001 From: jamurty Date: Sun, 21 Jun 2009 00:26:30 +0000 Subject: [PATCH] Issues 57: Added a sanity check when bucket names are returned, to ensure they actually exist. This check is only applied when running against the Stub connection, to avoid slowing down integration tests with real services git-svn-id: http://jclouds.googlecode.com/svn/trunk@1450 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../org/jclouds/aws/s3/S3IntegrationTest.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) 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 cb4c2147f5..8d30fa6ed3 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 @@ -48,6 +48,7 @@ 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; +import org.jclouds.aws.s3.domain.S3Bucket.Metadata; import org.jclouds.aws.s3.domain.S3Bucket.Metadata.LocationConstraint; import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.util.S3Utils; @@ -59,6 +60,8 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Optional; import org.testng.annotations.Parameters; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import com.google.inject.Module; public class S3IntegrationTest { @@ -200,6 +203,9 @@ public class S3IntegrationTest { } client = context.getConnection(); assert client != null; + + SANITY_CHECK_RETURNED_BUCKET_NAME = (client instanceof StubS3Connection); + goodMd5 = S3Utils.md5(TEST_STRING); badMd5 = S3Utils.md5("alf"); } @@ -230,11 +236,30 @@ public class S3IntegrationTest { return getBucketName(); } - public void returnBucket(String bucketName) throws InterruptedException, ExecutionException, - TimeoutException { + public void returnBucket(final String bucketName) throws InterruptedException, + ExecutionException, TimeoutException { if (bucketName != null) { bucketNames.add(bucketName); - bucketName = null; + + /* + * Ensure that any returned bucket name actually exists on the server. + * Return of a non-existent bucket introduces subtle testing bugs, where later + * unrelated tests will fail. + * + * NOTE: This sanity check should only be run for Stub-based Integration testing -- + * it will *substantially* slow down tests on a real server over a network. + */ + if (SANITY_CHECK_RETURNED_BUCKET_NAME) { + if (!Iterables.any(client.listOwnedBuckets().get(), new Predicate() { + public boolean apply(Metadata md) { + return bucketName.equals(md.getName()); + } + })) + { + throw new IllegalStateException( + "Test returned the name of a non-existent bucket: " + bucketName); + } + } } } @@ -254,6 +279,8 @@ public class S3IntegrationTest { protected static int bucketCount = 20; protected static volatile int bucketIndex = 0; + protected boolean SANITY_CHECK_RETURNED_BUCKET_NAME = false; + /** * two test groups integration and live. */