Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@

@RunWith(JUnit4.class)
public class ReadIT {

private String prefix;

@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -761,6 +762,7 @@ public void onSuccess(Row result) {
}

static class AccumulatingObserver implements ResponseObserver<Row> {

final List<Row> responses = Lists.newArrayList();
final SettableApiFuture<Void> completionFuture = SettableApiFuture.create();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minute seems heavy handed, how about exponential backoff?

// exponential backoff delay starting at 100ms
int expSleep = 100 * Math.pow(2, retryCount);
Thread.sleep(Math.min(expSleep, TimeUnit.MINUTES.toMillis(1));
``

}
}
}
}
Loading