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