File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed
samples/snippets/src/test/java/com/example/spanner Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -451,13 +451,33 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
451451 } finally {
452452 // Delete the backups from the test instance first, as the instance can only be deleted once
453453 // all backups have been deleted.
454- for (Backup backup : dbClient .listBackups (instanceId ).iterateAll ()) {
455- backup .delete ();
456- }
454+ deleteAllBackups (instanceId );
457455 instanceAdminClient .deleteInstance (instanceId );
458456 }
459457 }
460458
459+ private void deleteAllBackups (String instanceId ) throws InterruptedException {
460+ for (Backup backup : dbClient .listBackups (instanceId ).iterateAll ()) {
461+ int attempts = 0 ;
462+ while (attempts < 30 ) {
463+ try {
464+ attempts ++;
465+ backup .delete ();
466+ break ;
467+ } catch (SpannerException e ) {
468+ if (e .getErrorCode () == ErrorCode .FAILED_PRECONDITION && e .getMessage ()
469+ .contains ("Please try deleting the backup once the restore or post-restore optimize "
470+ + "operations have completed on these databases." )) {
471+ // Wait 30 seconds and then retry.
472+ Thread .sleep (30_000L );
473+ } else {
474+ throw e ;
475+ }
476+ }
477+ }
478+ }
479+ }
480+
461481 private String runSampleRunnable (Runnable sample ) {
462482 PrintStream stdOut = System .out ;
463483 ByteArrayOutputStream bout = new ByteArrayOutputStream ();
You can’t perform that action at this time.
0 commit comments