1818import static com .google .common .truth .Truth .assertThat ;
1919import static com .google .common .truth .Truth .assertWithMessage ;
2020import static com .google .common .truth .TruthJUnit .assume ;
21- import static io .grpc .Status .Code .NOT_FOUND ;
22- import static org .junit .Assert .fail ;
21+ import static org .junit .Assert .assertThrows ;
2322
2423import com .google .api .gax .batching .Batcher ;
25- import com .google .api .gax .rpc .ApiException ;
24+ import com .google .api .gax .rpc .DeadlineExceededException ;
25+ import com .google .api .gax .rpc .NotFoundException ;
2626import com .google .cloud .Policy ;
2727import com .google .cloud .bigtable .admin .v2 .BigtableInstanceAdminClient ;
2828import com .google .cloud .bigtable .admin .v2 .BigtableTableAdminClient ;
4444import com .google .cloud .bigtable .test_helpers .env .TestEnvRule ;
4545import com .google .common .base .Stopwatch ;
4646import com .google .protobuf .ByteString ;
47- import io .grpc .StatusRuntimeException ;
4847import java .io .IOException ;
4948import java .util .List ;
5049import java .util .Random ;
5150import java .util .concurrent .ExecutionException ;
5251import java .util .concurrent .TimeUnit ;
5352import java .util .concurrent .TimeoutException ;
53+ import java .util .logging .Level ;
5454import java .util .logging .Logger ;
5555import org .junit .AfterClass ;
5656import org .junit .BeforeClass ;
@@ -104,6 +104,20 @@ public static void tearDownClass() {
104104 }
105105 }
106106
107+ private static void deleteBackupIgnoreErrors (
108+ BigtableTableAdminClient tableAdmin , String clusterId , String backupId ) {
109+ try {
110+ tableAdmin .deleteBackup (clusterId , backupId );
111+ } catch (DeadlineExceededException ex ) {
112+ LOGGER .log (Level .WARNING , "Error deleting backup" , ex );
113+ // Don't rethrow
114+ }
115+ }
116+
117+ private void deleteBackupIgnoreErrors (String clusterId , String backupId ) {
118+ deleteBackupIgnoreErrors (tableAdmin , clusterId , backupId );
119+ }
120+
107121 @ Test
108122 public void createAndGetBackupTest () {
109123 String backupId = prefixGenerator .newPrefix ();
@@ -146,7 +160,7 @@ public void createAndGetBackupTest() {
146160 .isAnyOf (Backup .State .CREATING , Backup .State .READY );
147161
148162 } finally {
149- tableAdmin . deleteBackup (targetCluster , backupId );
163+ deleteBackupIgnoreErrors (targetCluster , backupId );
150164 }
151165 }
152166
@@ -166,8 +180,8 @@ public void listBackupTest() {
166180 .that (response )
167181 .containsAtLeast (backupId1 , backupId2 );
168182 } finally {
169- tableAdmin . deleteBackup (targetCluster , backupId1 );
170- tableAdmin . deleteBackup (targetCluster , backupId2 );
183+ deleteBackupIgnoreErrors (targetCluster , backupId1 );
184+ deleteBackupIgnoreErrors (targetCluster , backupId2 );
171185 }
172186 }
173187
@@ -183,33 +197,18 @@ public void updateBackupTest() {
183197 Backup backup = tableAdmin .updateBackup (req );
184198 assertWithMessage ("Incorrect expire time" ).that (backup .getExpireTime ()).isEqualTo (expireTime );
185199 } finally {
186- tableAdmin . deleteBackup (targetCluster , backupId );
200+ deleteBackupIgnoreErrors (targetCluster , backupId );
187201 }
188202 }
189203
190204 @ Test
191- public void deleteBackupTest () throws InterruptedException {
205+ public void deleteBackupTest () {
192206 String backupId = prefixGenerator .newPrefix ();
193207
194208 tableAdmin .createBackup (createBackupRequest (backupId ));
195209 tableAdmin .deleteBackup (targetCluster , backupId );
196210
197- try {
198- for (int i = 0 ; i < BACKOFF_DURATION .length ; i ++) {
199- tableAdmin .getBackup (targetCluster , backupId );
200-
201- LOGGER .info ("Wait for " + BACKOFF_DURATION [i ] + " seconds for deleting backup " + backupId );
202- Thread .sleep (BACKOFF_DURATION [i ] * 1000 );
203- }
204- fail ("backup was not deleted." );
205- } catch (ApiException ex ) {
206- assertWithMessage ("Incorrect exception type" )
207- .that (ex .getCause ())
208- .isInstanceOf (StatusRuntimeException .class );
209- assertWithMessage ("Incorrect error message" )
210- .that (((StatusRuntimeException ) ex .getCause ()).getStatus ().getCode ())
211- .isEqualTo (NOT_FOUND );
212- }
211+ assertThrows (NotFoundException .class , () -> tableAdmin .getBackup (targetCluster , backupId ));
213212 }
214213
215214 @ Test
@@ -240,7 +239,7 @@ public void restoreTableTest() throws InterruptedException, ExecutionException {
240239 .isEqualTo (restoredTableId );
241240 }
242241 } finally {
243- tableAdmin . deleteBackup (targetCluster , backupId );
242+ deleteBackupIgnoreErrors (targetCluster , backupId );
244243 tableAdmin .deleteTable (restoredTableId );
245244 }
246245 }
@@ -298,7 +297,7 @@ public void crossInstanceRestoreTest()
298297 destTableAdmin .awaitOptimizeRestoredTable (result .getOptimizeRestoredTableOperationToken ());
299298 destTableAdmin .getTable (restoredTableId );
300299 } finally {
301- tableAdmin . deleteBackup (targetCluster , backupId );
300+ deleteBackupIgnoreErrors (targetCluster , backupId );
302301 instanceAdmin .deleteInstance (targetInstance );
303302 }
304303 }
@@ -340,8 +339,8 @@ public void copyBackupTest()
340339 .isAnyOf (Backup .State .CREATING , Backup .State .READY );
341340
342341 } finally {
343- tableAdmin . deleteBackup (targetCluster , copiedBackupId );
344- tableAdmin . deleteBackup (targetCluster , backupId );
342+ deleteBackupIgnoreErrors (targetCluster , copiedBackupId );
343+ deleteBackupIgnoreErrors (targetCluster , backupId );
345344 }
346345 }
347346
@@ -395,8 +394,8 @@ public void crossInstanceCopyBackupTest()
395394 .isAnyOf (Backup .State .CREATING , Backup .State .READY );
396395
397396 } finally {
398- destTableAdmin . deleteBackup ( destCluster , copiedBackupId );
399- tableAdmin . deleteBackup (targetCluster , backupId );
397+ deleteBackupIgnoreErrors ( destTableAdmin , destCluster , copiedBackupId );
398+ deleteBackupIgnoreErrors (targetCluster , backupId );
400399 instanceAdmin .deleteInstance (destInstance );
401400 }
402401 }
@@ -430,7 +429,7 @@ public void backupIamTest() {
430429 "bigtable.backups.restore" );
431430 assertThat (permissions ).hasSize (4 );
432431 } finally {
433- tableAdmin . deleteBackup (targetCluster , backupId );
432+ deleteBackupIgnoreErrors (targetCluster , backupId );
434433 }
435434 }
436435
0 commit comments