Skip to content

Commit 4c04cef

Browse files
committed
---
yaml --- r: 1073 b: refs/heads/master c: 1c5030a h: refs/heads/master i: 1071: 36124c8 v: v3
1 parent 519394a commit 4c04cef

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
2-
refs/heads/master: f24b2bf3808a74aff13c5cb8223b5d3b649f7646
2+
refs/heads/master: 1c5030aba170f9c421381a59bfa6b97757943ea4
33
refs/heads/travis: 0fa997e2fc9c6b61b2d91e6d163655aae67d44b6
44
refs/heads/gh-pages: 5a10432ecc75f29812e33a8236c900379509fe99

trunk/gcloud-java-storage/src/test/java/com/google/gcloud/storage/RemoteGcsHelperTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class RemoteGcsHelperTest {
7272
private static final List<BlobInfo> BLOB_LIST = ImmutableList.of(
7373
BlobInfo.builder(BUCKET_NAME, "n1").build(),
7474
BlobInfo.builder(BUCKET_NAME, "n2").build());
75+
private static final StorageException RETRYABLE_EXCEPTION = new StorageException(409, "", true);
76+
private static final StorageException FATAL_EXCEPTION = new StorageException(500, "", false);
7577
private static final ListResult<BlobInfo> BLOB_LIST_RESULT = new ListResult<BlobInfo>() {
7678

7779
@Override
@@ -116,14 +118,32 @@ public void testForceDelete() throws InterruptedException, ExecutionException {
116118

117119
@Test
118120
public void testForceDeleteTimeout() throws InterruptedException, ExecutionException {
121+
Storage storageMock = EasyMock.createMock(Storage.class);
122+
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_LIST_RESULT).anyTimes();
123+
for (BlobInfo info : BLOB_LIST) {
124+
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true).anyTimes();
125+
}
126+
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(RETRYABLE_EXCEPTION).anyTimes();
127+
EasyMock.replay(storageMock);
128+
assertTrue(!RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME, 50, TimeUnit.MICROSECONDS));
129+
EasyMock.verify(storageMock);
130+
}
131+
132+
@Test
133+
public void testForceDeleteFail() throws InterruptedException, ExecutionException {
119134
Storage storageMock = EasyMock.createMock(Storage.class);
120135
EasyMock.expect(storageMock.list(BUCKET_NAME)).andReturn(BLOB_LIST_RESULT);
121136
for (BlobInfo info : BLOB_LIST) {
122137
EasyMock.expect(storageMock.delete(BUCKET_NAME, info.name())).andReturn(true);
123138
}
124-
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andReturn(false);
139+
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
125140
EasyMock.replay(storageMock);
126-
assertTrue(!RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME, 50, TimeUnit.MICROSECONDS));
141+
thrown.expect(ExecutionException.class);
142+
try {
143+
RemoteGcsHelper.forceDelete(storageMock, BUCKET_NAME, 5, TimeUnit.SECONDS);
144+
} finally {
145+
EasyMock.verify(storageMock);
146+
}
127147
}
128148

129149
@Test

0 commit comments

Comments
 (0)