4343import java .io .ByteArrayOutputStream ;
4444import java .io .IOException ;
4545import java .io .PrintStream ;
46+ import java .time .Duration ;
4647import java .util .UUID ;
4748import java .util .concurrent .TimeUnit ;
4849import java .util .function .Predicate ;
@@ -590,6 +591,7 @@ public void testEncryptedDatabaseAndBackupSamples() throws Exception {
590591 } finally {
591592 // Delete the backups from the test instance first, as the instance can only be deleted once
592593 // all backups have been deleted.
594+ Uninterruptibles .sleepUninterruptibly (Duration .ofMinutes (1 ));
593595 System .out .println ("Deleting backups ..." );
594596 deleteAllBackups (instanceId );
595597 instanceAdminClient .deleteInstance (instanceId );
@@ -752,15 +754,21 @@ static String formatForTest(String name) {
752754
753755 static class ShouldRetryBackupOperation implements Predicate <SpannerException > {
754756
755- private static final int MAX_ATTEMPTS = 20 ;
757+ private int maxAttempts = 20 ;
756758 private int attempts = 0 ;
757759
760+ ShouldRetryBackupOperation () {}
761+
762+ ShouldRetryBackupOperation (int maxAttempts ) {
763+ this .maxAttempts = maxAttempts ;
764+ }
765+
758766 @ Override
759767 public boolean test (SpannerException e ) {
760768 if (e .getErrorCode () == ErrorCode .FAILED_PRECONDITION
761769 && e .getMessage ().contains ("Please retry the operation once the pending" )) {
762770 attempts ++;
763- if (attempts == MAX_ATTEMPTS ) {
771+ if (attempts == maxAttempts ) {
764772 // Throw custom exception so it is easier to locate in the log why it went wrong.
765773 throw SpannerExceptionFactory .newSpannerException (
766774 ErrorCode .DEADLINE_EXCEEDED ,
@@ -770,6 +778,7 @@ public boolean test(SpannerException e) {
770778 attempts ),
771779 e );
772780 }
781+ System .out .println ("Attempt " + attempts );
773782 // Wait one minute before retrying.
774783 Uninterruptibles .sleepUninterruptibly (60L , TimeUnit .SECONDS );
775784 return true ;
0 commit comments