From 344cf6a3a748628099013bf0749acb2f223ebacb Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sat, 27 Jun 2009 21:28:46 +0000 Subject: [PATCH] replay bucket listing before re-attempting clearing the bucket git-svn-id: http://jclouds.googlecode.com/svn/trunk@1479 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../org/jclouds/aws/s3/S3IntegrationTest.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 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 1e0e3b4c57..7f68c3256d 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 @@ -67,7 +67,7 @@ import com.google.inject.Module; public class S3IntegrationTest { protected static final String TEST_STRING = " "; - public static long INCONSISTENCY_WINDOW = 2000; + public static long INCONSISTENCY_WINDOW = 1000; /** * Due to eventual consistency, bucket commands may not return correctly immediately. Hence, we @@ -300,12 +300,7 @@ public class S3IntegrationTest { public void setUpBuckets(ITestContext context) throws Exception { synchronized (bucketNames) { if (bucketNames.peek() == null) { - // try twice to delete everything - try { - deleteEverything(); - } catch (AssertionError e) { - deleteEverything(); - } + deleteEverything(); for (; bucketIndex < bucketCount; bucketIndex++) { String bucketName = bucketPrefix + bucketIndex; try { @@ -351,28 +346,36 @@ public class S3IntegrationTest { /** * Remove any objects in a bucket, leaving it empty. - * - * @param name - * @throws InterruptedException - * @throws ExecutionException - * @throws TimeoutException */ - protected void emptyBucket(String name) throws InterruptedException, ExecutionException, + protected void emptyBucket(final String name) throws InterruptedException, ExecutionException, TimeoutException { if (client.bucketExists(name).get(10, TimeUnit.SECONDS)) { - List> results = new ArrayList>(); + // This can fail to be zero length because of stale bucket lists. Ex. client.listBucket() + // could return 9 keys, when there are 10. When all the deletions finish, one entry would + // be left in this case. Instead of failing, we will attempt this entire bucket deletion + // operation multiple times to ensure we can acheive a zero length bucket. + assertEventually(new Runnable() { + public void run() { + try { + List> results = new ArrayList>(); + + 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(); + } + assertEventuallyBucketEmpty(name); + } catch (Exception e) { + Utils. rethrowIfRuntimeOrSameType(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(); - } } - assertEventuallyBucketEmpty(name); } protected String createScratchBucketInEU() throws InterruptedException, ExecutionException,