Skip to content

Commit

Permalink
Create simple forceDelete that can be used on AppEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajay Kannan committed Jan 9, 2016
1 parent 5a23e57 commit 863c572
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ 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.
*
* @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;
}
}

/**
* Returns a bucket name generated using a random UUID.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,37 @@ public void testForceDeleteFail() throws InterruptedException, ExecutionExceptio
}
}


@Test
public void testForceDeleteNoTimeout() throws Exception {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
for (BlobInfo info : BLOB_LIST) {
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true);
}
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(true);
EasyMock.replay(storageMock);
RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME);
EasyMock.verify(storageMock);
}

@Test
public void testForceDeleteNoTimeoutFail() throws Exception {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_PAGE);
for (BlobInfo info : BLOB_LIST) {
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true);
}
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
EasyMock.replay(storageMock);
thrown.expect(StorageException.class);
try {
RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME);
} finally {
EasyMock.verify(storageMock);
}
}

@Test
public void testCreateFromStream() {
RemoteGcsHelper helper = RemoteGcsHelper.create(PROJECT_ID, JSON_KEY_STREAM);
Expand Down

0 comments on commit 863c572

Please sign in to comment.