diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java index 95ed16817e..ce45b0fdf1 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java @@ -73,6 +73,7 @@ @RunWith(JUnit4.class) public class ReadIT { + private String prefix; @ClassRule public static TestEnvRule testEnvRule = new TestEnvRule(); @@ -460,7 +461,7 @@ public void rangeQueries() { } @Test - public void rangeQueriesOnAuthorizedView() { + public void rangeQueriesOnAuthorizedView() throws InterruptedException { assume() .withMessage("AuthorizedView is not supported on Emulator") .that(testEnvRule.env()) @@ -761,6 +762,7 @@ public void onSuccess(Row result) { } static class AccumulatingObserver implements ResponseObserver { + final List responses = Lists.newArrayList(); final SettableApiFuture completionFuture = SettableApiFuture.create(); diff --git a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java index 83c40403f8..d91c12440d 100644 --- a/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java +++ b/google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java @@ -16,18 +16,26 @@ package com.google.cloud.bigtable.misc_utilities; +import com.google.api.gax.rpc.UnavailableException; import com.google.cloud.bigtable.admin.v2.models.AuthorizedView; import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest; import com.google.cloud.bigtable.admin.v2.models.FamilySubsets; import com.google.cloud.bigtable.admin.v2.models.SubsetView; import com.google.cloud.bigtable.test_helpers.env.TestEnvRule; +import java.time.Duration; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; public class AuthorizedViewTestHelper { + public static String AUTHORIZED_VIEW_ROW_PREFIX = "row#"; public static String AUTHORIZED_VIEW_COLUMN_QUALIFIER = "qualifier"; - public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) { + private static final Logger logger = Logger.getLogger(AuthorizedViewTestHelper.class.getName()); + + public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) + throws InterruptedException { String tableId = testEnvRule.env().getTableId(); String authorizedViewId = UUID.randomUUID().toString(); CreateAuthorizedViewRequest request = @@ -40,6 +48,25 @@ public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) { FamilySubsets.create() .addQualifierPrefix(AUTHORIZED_VIEW_COLUMN_QUALIFIER))) .setDeletionProtection(false); - return testEnvRule.env().getTableAdminClient().createAuthorizedView(request); + int retryCount = 0; + int maxRetries = 10; + while (true) { + try { + return testEnvRule.env().getTableAdminClient().createAuthorizedView(request); + } catch (UnavailableException e) { + if (++retryCount == maxRetries) { + throw e; + } + logger.log( + Level.INFO, + "Retrying createAuthorizedView " + + authorizedViewId + + " in table " + + tableId + + ", retryCount: " + + retryCount); + Thread.sleep(Duration.ofMinutes(1).toMillis()); + } + } } }