mirror of https://github.com/apache/jclouds.git
Make deleteObject() return false on 404 response
This commit is contained in:
parent
c1033d1eda
commit
ad495ab1bc
|
@ -291,11 +291,14 @@ public final class GoogleCloudStorageBlobStore extends BaseBlobStore {
|
||||||
@Override
|
@Override
|
||||||
protected boolean deleteAndVerifyContainerGone(String container) {
|
protected boolean deleteAndVerifyContainerGone(String container) {
|
||||||
ListPageWithPrefixes<GoogleCloudStorageObject> list = api.getObjectApi().listObjects(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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ import javax.ws.rs.QueryParam;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
||||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
import org.jclouds.Fallbacks.TrueOnNotFoundOr404;
|
|
||||||
import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists;
|
import org.jclouds.blobstore.BlobStoreFallbacks.NullOnKeyAlreadyExists;
|
||||||
import org.jclouds.googlecloud.domain.ListPage;
|
import org.jclouds.googlecloud.domain.ListPage;
|
||||||
import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.NullOnBucketAlreadyExists;
|
import org.jclouds.googlecloudstorage.GoogleCloudStorageFallbacks.NullOnBucketAlreadyExists;
|
||||||
|
@ -155,7 +154,7 @@ public interface BucketApi {
|
||||||
@Named("Bucket:delete")
|
@Named("Bucket:delete")
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/b/{bucket}")
|
@Path("/b/{bucket}")
|
||||||
@Fallback(TrueOnNotFoundOr404.class)
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean deleteBucket(@PathParam("bucket") String bucketName);
|
boolean deleteBucket(@PathParam("bucket") String bucketName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +168,7 @@ public interface BucketApi {
|
||||||
@Named("Bucket:delete")
|
@Named("Bucket:delete")
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/b/{bucket}")
|
@Path("/b/{bucket}")
|
||||||
@Fallback(TrueOnNotFoundOr404.class)
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean deleteBucket(@PathParam("bucket") String bucketName, DeleteBucketOptions options);
|
boolean deleteBucket(@PathParam("bucket") String bucketName, DeleteBucketOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,6 @@ import javax.ws.rs.Produces;
|
||||||
|
|
||||||
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
import org.jclouds.Fallbacks.FalseOnNotFoundOr404;
|
||||||
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
import org.jclouds.Fallbacks.TrueOnNotFoundOr404;
|
|
||||||
import org.jclouds.googlecloudstorage.binders.MultipartUploadBinder;
|
import org.jclouds.googlecloudstorage.binders.MultipartUploadBinder;
|
||||||
import org.jclouds.googlecloudstorage.binders.UploadBinder;
|
import org.jclouds.googlecloudstorage.binders.UploadBinder;
|
||||||
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
|
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
|
||||||
|
@ -199,7 +198,7 @@ public interface ObjectApi {
|
||||||
@Named("Object:delete")
|
@Named("Object:delete")
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("storage/v1/b/{bucket}/o/{object}")
|
@Path("storage/v1/b/{bucket}/o/{object}")
|
||||||
@Fallback(TrueOnNotFoundOr404.class)
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName);
|
boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,7 +215,7 @@ public interface ObjectApi {
|
||||||
@Named("Object:delete")
|
@Named("Object:delete")
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("storage/v1/b/{bucket}/o/{object}")
|
@Path("storage/v1/b/{bucket}/o/{object}")
|
||||||
@Fallback(TrueOnNotFoundOr404.class)
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName,
|
boolean deleteObject(@PathParam("bucket") String bucketName, @PathParam("object") String objectName,
|
||||||
DeleteObjectOptions options);
|
DeleteObjectOptions options);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.jclouds.googlecloudstorage.features;
|
package org.jclouds.googlecloudstorage.features;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
import static org.testng.Assert.assertSame;
|
import static org.testng.Assert.assertSame;
|
||||||
|
@ -204,7 +205,7 @@ public class BucketApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = { "testDeleteBucket" })
|
@Test(groups = "live", dependsOnMethods = { "testDeleteBucket" })
|
||||||
public void testDeleteNotExistingBucket() {
|
public void testDeleteNotExistingBucket() {
|
||||||
assertTrue(api().deleteBucket(BUCKET_NAME));
|
assertFalse(api().deleteBucket(BUCKET_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = { "testGetBucketWithOptions" })
|
@Test(groups = "live", dependsOnMethods = { "testGetBucketWithOptions" })
|
||||||
|
|
|
@ -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.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.entry;
|
import static org.assertj.core.api.Assertions.entry;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
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 COPIED_OBJECT_NAME = "copyofObjectOperation.txt";
|
||||||
private static final String COMPOSED_OBJECT = "ComposedObject1.txt";
|
private static final String COMPOSED_OBJECT = "ComposedObject1.txt";
|
||||||
private static final String COMPOSED_OBJECT2 = "ComposedObject2.json";
|
private static final String COMPOSED_OBJECT2 = "ComposedObject2.json";
|
||||||
|
private static final String NONEXISTENT_OBJECT_NAME = "noSuchObject.txt";
|
||||||
|
|
||||||
private PayloadEnclosing testPayload;
|
private PayloadEnclosing testPayload;
|
||||||
private Long RANDOM_LONG = 100L;
|
private Long RANDOM_LONG = 100L;
|
||||||
|
@ -284,7 +287,6 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = "testComposeObjectWithOptions")
|
@Test(groups = "live", dependsOnMethods = "testComposeObjectWithOptions")
|
||||||
public void testUpdateObject() {
|
public void testUpdateObject() {
|
||||||
|
|
||||||
ObjectAccessControls oacl = ObjectAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers")
|
ObjectAccessControls oacl = ObjectAccessControls.builder().bucket(BUCKET_NAME).entity("allUsers")
|
||||||
.role(ObjectRole.OWNER).build();
|
.role(ObjectRole.OWNER).build();
|
||||||
|
|
||||||
|
@ -403,13 +405,14 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = "testMultipartJpegUpload")
|
@Test(groups = "live", dependsOnMethods = "testMultipartJpegUpload")
|
||||||
public void testDeleteObject() {
|
public void testDeleteObject() {
|
||||||
api().deleteObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME);
|
assertTrue(api().deleteObject(BUCKET_NAME2, UPLOAD_OBJECT_NAME));
|
||||||
api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT2);
|
assertTrue(api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT2));
|
||||||
api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT);
|
assertTrue(api().deleteObject(BUCKET_NAME2, COMPOSED_OBJECT));
|
||||||
api().deleteObject(BUCKET_NAME2, COPIED_OBJECT_NAME);
|
assertTrue(api().deleteObject(BUCKET_NAME2, COPIED_OBJECT_NAME));
|
||||||
api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME);
|
assertFalse(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME));
|
||||||
api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME2);
|
assertTrue(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME2));
|
||||||
api().deleteObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT);
|
assertTrue(api().deleteObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT));
|
||||||
|
assertFalse(api().deleteObject(BUCKET_NAME, NONEXISTENT_OBJECT_NAME));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(groups = "live", dependsOnMethods = "testPatchObjectsWithOptions")
|
@Test(groups = "live", dependsOnMethods = "testPatchObjectsWithOptions")
|
||||||
|
|
Loading…
Reference in New Issue