Skip to content

Commit

Permalink
Use runtime exceptions for DeleteBucketTask.call()
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Jan 11, 2016
1 parent 863c572 commit 33f6ad8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ public StorageOptions options() {

/**
* Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket
* deletion succeeds or {@code timeout} expires.
* deletion succeeds or {@code timeout} expires. To allow for the timeout, this method uses a
* separate thread to send the delete requests. Use
* {@link #forceDelete(Storage storage, String bucket)} if spawning an additional thread is
* undesirable, such as in the App Engine production runtime.
*
* @param storage the storage service to be used to issue requests
* @param bucket the bucket to be deleted
Expand All @@ -89,20 +92,14 @@ public static Boolean forceDelete(Storage storage, String bucket, long timeout,
}

/**
* Deletes a bucket, even if non-empty. Objects in the bucket are listed and deleted until bucket
* deletion succeeds. This method can be used to delete buckets from within App Engine. Note that
* this method does not set a timeout.
* Deletes a bucket, even if non-empty. This method blocks until the deletion completes or fails.
*
* @param storage the storage service to be used to issue requests
* @param bucket the bucket to be deleted
* @throws StorageException if an exception is encountered during bucket deletion
*/
public static void forceDelete(Storage storage, String bucket) throws StorageException {
try {
new DeleteBucketTask(storage, bucket).call();
} catch (Exception e) {
throw (StorageException) e;
}
public static void forceDelete(Storage storage, String bucket) {
new DeleteBucketTask(storage, bucket).call();
}

/**
Expand Down Expand Up @@ -174,7 +171,7 @@ public DeleteBucketTask(Storage storage, String bucket) {
}

@Override
public Boolean call() throws Exception {
public Boolean call() {
while (true) {
for (BlobInfo info : storage.list(bucket).values()) {
storage.delete(bucket, info.name());
Expand All @@ -184,7 +181,12 @@ public Boolean call() throws Exception {
return true;
} catch (StorageException e) {
if (e.code() == 409) {
Thread.sleep(500);
try {
Thread.sleep(500);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
throw e;
}
} else {
throw e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio
}
}


@Test
public void testForceDeleteNoTimeout() throws Exception {
public void testForceDeleteNoTimeout() {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
for (BlobInfo info : BLOB_LIST) {
Expand All @@ -155,7 +154,7 @@ public void testForceDeleteNoTimeout() throws Exception {
}

@Test
public void testForceDeleteNoTimeoutFail() throws Exception {
public void testForceDeleteNoTimeoutFail() {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
for (BlobInfo info : BLOB_LIST) {
Expand Down

0 comments on commit 33f6ad8

Please sign in to comment.