From 57fbcb5fd84b5af30c335f2420a4a38f04a2da31 Mon Sep 17 00:00:00 2001 From: Olav Loite Date: Fri, 13 Mar 2020 14:53:15 +0100 Subject: [PATCH] tests: fix failing test cases --- .../cloud/spanner/DatabaseAdminClientTest.java | 13 +++++++------ .../cloud/spanner/MockOperationsServiceImpl.java | 4 ++-- .../com/google/cloud/spanner/it/ITBackupTest.java | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java index fc0b8088bd3..38bcd8437d4 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseAdminClientTest.java @@ -45,6 +45,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import org.hamcrest.BaseMatcher; @@ -252,18 +253,18 @@ public void backupCreateCancel() { RetryingFuture pollingFuture = op.getPollingFuture(); // Wait for the operation to finish. // isDone will return true if the operation has finished successfully or if it was cancelled - // or any other error occurred.. + // or any other error occurred. while (!pollingFuture.get().isDone()) { Thread.sleep(TimeUnit.MILLISECONDS.convert(5, TimeUnit.SECONDS)); } - if (pollingFuture.get().getErrorCode() == null) { - // The cancellation of the backup creation failed. Delete the backup. - backup.delete(); - } + } catch (CancellationException e) { + // ignore, this exception may also occur if the polling future has been cancelled. } catch (ExecutionException e) { - throw (SpannerException) e.getCause(); + throw (RuntimeException) e.getCause(); } catch (InterruptedException e) { throw SpannerExceptionFactory.propagateInterrupt(e); + } finally { + backup.delete(); } } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockOperationsServiceImpl.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockOperationsServiceImpl.java index 04cba956d5e..35d6bcdce30 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockOperationsServiceImpl.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/MockOperationsServiceImpl.java @@ -148,9 +148,9 @@ public void cancelOperation( .build()) .build()); fut.cancel(true); - responseObserver.onNext(Empty.getDefaultInstance()); - responseObserver.onCompleted(); } + responseObserver.onNext(Empty.getDefaultInstance()); + responseObserver.onCompleted(); } else { responseObserver.onError(Status.NOT_FOUND.asRuntimeException()); } diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBackupTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBackupTest.java index ca6c708807d..1e49783aa39 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBackupTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITBackupTest.java @@ -316,7 +316,7 @@ public void testBackups() throws InterruptedException, ExecutionException { .doesNotContain(backup1); // Test pagination. - testPagination(3); + testPagination(2); logger.info("Finished listBackup tests"); // Execute other tests as part of this integration test to reduce total execution time.