diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java index f1f631603e..cab0646113 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/blobstore/GoogleCloudStorageBlobStore.java @@ -291,11 +291,14 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore { @Override protected boolean deleteAndVerifyContainerGone(String container) { ListPageWithPrefixes list = api.getObjectApi().listObjects(container); - if (list == null) { - return api.getBucketApi().deleteBucket(container); + + if (list == null || (!list.iterator().hasNext() && list.prefixes().isEmpty())) { + if (!api.getBucketApi().deleteBucket(container)) { + return true; + } else { + return !api.getBucketApi().bucketExist(container); + } } - if (!list.iterator().hasNext() && list.prefixes().isEmpty()) - return api.getBucketApi().deleteBucket(container); return false; } diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java index bb418b0206..8636625b38 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/BucketApi.java @@ -31,7 +31,6 @@ import javax.ws.rs.QueryParam; import org.jclouds.Fallbacks.FalseOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.TrueOnNotFoundOr404; import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists; import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.NullOnBucketAlreadyExists; @@ -155,7 +154,7 @@ public interface BucketApi { @Named("Bucket:delete") @DELETE @Path("/b/{bucket}") - @Fallback(TrueOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) boolean deleteBucket(@PathParam("bucket") String bucketName); /** @@ -169,7 +168,7 @@ public interface BucketApi { @Named("Bucket:delete") @DELETE @Path("/b/{bucket}") - @Fallback(TrueOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) boolean deleteBucket(@PathParam("bucket") String bucketName, DeleteBucketOptions options); /** diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java index cdc200fd72..570a0891bd 100644 --- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java +++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java @@ -31,7 +31,6 @@ import javax.ws.rs.Produces; import org.jclouds.Fallbacks.FalseOnNotFoundOr404; import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.TrueOnNotFoundOr404; import org.jclouds.googlecloudstorage.binders.MultipartUploadBinder; import org.jclouds.googlecloudstorage.binders.UploadBinder; import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject; @@ -199,7 +198,7 @@ public interface ObjectApi { @Named("Object:delete") @DELETE @Path("storage/v1/b/{bucket}/o/{object}") - @Fallback(TrueOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName); /** @@ -216,7 +215,7 @@ public interface ObjectApi { @Named("Object:delete") @DELETE @Path("storage/v1/b/{bucket}/o/{object}") - @Fallback(TrueOnNotFoundOr404.class) + @Fallback(FalseOnNotFoundOr404.class) boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName, DeleteObjectOptions options); diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiLiveTest.java index afa05acb69..21f0a18509 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiLiveTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/BucketApiLiveTest.java @@ -17,6 +17,7 @@ package org.jclouds.googlecloudstorage.features; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; @@ -204,7 +205,7 @@ public class BucketApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { @Test(groups = "live", dependsOnMethods = { "testDeleteBucket" }) public void testDeleteNotExistingBucket() { - assertTrue(api().deleteBucket(BUCKET_NAME)); + assertFalse(api().deleteBucket(BUCKET_NAME)); } @Test(groups = "live", dependsOnMethods = { "testGetBucketWithOptions" }) diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java index 5a78c4414f..ec117188eb 100644 --- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java +++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java @@ -20,7 +20,9 @@ import static com.google.common.io.BaseEncoding.base64; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertTrue; import java.io.IOException; import java.util.List; @@ -73,6 +75,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { private static final String COPIED_OBJECT_NAME = "copyofObjectOperation.txt"; private static final String COMPOSED_OBJECT = "ComposedObject1.txt"; private static final String COMPOSED_OBJECT2 = "ComposedObject2.json"; + private static final String NONEXISTENT_OBJECT_NAME = "noSuchObject.txt"; private PayloadEnclosing testPayload; private Long RANDOM_LONG = 100L; @@ -284,7 +287,6 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { @Test(groups = "live", dependsOnMethods = "testComposeObjectWithOptions") public void testUpdateObject() { - ObjectAccessControls oacl = ObjectAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers") .role(ObjectRole.OWNER).build(); @@ -403,13 +405,14 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest { @Test(groups = "live", dependsOnMethods = "testMultipartJpegUpload") public void testDeleteObject() { - api().deleteObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME); - api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT2); - api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT); - api().deleteObject(BUCKET_NAME2, COPIED_OBJECT_NAME); - api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME); - api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME2); - api().deleteObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT); + assertTrue(api().deleteObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME)); + assertTrue(api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT2)); + assertTrue(api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT)); + assertTrue(api().deleteObject(BUCKET_NAME2, COPIED_OBJECT_NAME)); + assertFalse(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME)); + assertTrue(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME2)); + assertTrue(api().deleteObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT)); + assertFalse(api().deleteObject(BUCKET_NAME, NONEXISTENT_OBJECT_NAME)); } @Test(groups = "live", dependsOnMethods = "testPatchObjectsWithOptions")