Make deleteObject() return false on 404 response

This commit is contained in:
snotling 2015-01-14 23:35:20 +01:00 committed by Andrew Gaul
parent c1033d1eda
commit ad495ab1bc
5 changed files with 24 additions and 19 deletions

View File

@ -291,11 +291,14 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
@Override
protected boolean deleteAndVerifyContainerGone(String container) {
ListPageWithPrefixes<GoogleCloudStorageObject> 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;
}

View File

@ -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);
/**

View File

@ -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);

View File

@ -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" })

View File

@ -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")