Skip to content

Commit 6b2f585

Browse files
trollyxiamutianf
andauthored
test: Wrap createTestAuthorizedView with retries (#2789)
* test: Wrap createTestAuthorizedView with retries Change-Id: I307ff677ffcd007999402b2e55d99226b2be68bc * test: use exponential backoff Change-Id: Ied51f268f8b68f692d97626e7a84a72236901198 --------- Co-authored-by: Mattie Fu <[email protected]>
1 parent d9b9fda commit 6b2f585

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/data/v2/it/ReadIT.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373

7474
@RunWith(JUnit4.class)
7575
public class ReadIT {
76+
7677
private String prefix;
7778

7879
@ClassRule public static TestEnvRule testEnvRule = new TestEnvRule();
@@ -460,7 +461,7 @@ public void rangeQueries() {
460461
}
461462

462463
@Test
463-
public void rangeQueriesOnAuthorizedView() {
464+
public void rangeQueriesOnAuthorizedView() throws InterruptedException {
464465
assume()
465466
.withMessage("AuthorizedView is not supported on Emulator")
466467
.that(testEnvRule.env())
@@ -761,6 +762,7 @@ public void onSuccess(Row result) {
761762
}
762763

763764
static class AccumulatingObserver implements ResponseObserver<Row> {
765+
764766
final List<Row> responses = Lists.newArrayList();
765767
final SettableApiFuture<Void> completionFuture = SettableApiFuture.create();
766768

google-cloud-bigtable/src/test/java/com/google/cloud/bigtable/misc_utilities/AuthorizedViewTestHelper.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,26 @@
1616

1717
package com.google.cloud.bigtable.misc_utilities;
1818

19+
import com.google.api.gax.rpc.UnavailableException;
1920
import com.google.cloud.bigtable.admin.v2.models.AuthorizedView;
2021
import com.google.cloud.bigtable.admin.v2.models.CreateAuthorizedViewRequest;
2122
import com.google.cloud.bigtable.admin.v2.models.FamilySubsets;
2223
import com.google.cloud.bigtable.admin.v2.models.SubsetView;
2324
import com.google.cloud.bigtable.test_helpers.env.TestEnvRule;
2425
import java.util.UUID;
26+
import java.util.concurrent.TimeUnit;
27+
import java.util.logging.Level;
28+
import java.util.logging.Logger;
2529

2630
public class AuthorizedViewTestHelper {
31+
2732
public static String AUTHORIZED_VIEW_ROW_PREFIX = "row#";
2833
public static String AUTHORIZED_VIEW_COLUMN_QUALIFIER = "qualifier";
2934

30-
public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) {
35+
private static final Logger logger = Logger.getLogger(AuthorizedViewTestHelper.class.getName());
36+
37+
public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule)
38+
throws InterruptedException {
3139
String tableId = testEnvRule.env().getTableId();
3240
String authorizedViewId = UUID.randomUUID().toString();
3341
CreateAuthorizedViewRequest request =
@@ -40,6 +48,27 @@ public static AuthorizedView createTestAuthorizedView(TestEnvRule testEnvRule) {
4048
FamilySubsets.create()
4149
.addQualifierPrefix(AUTHORIZED_VIEW_COLUMN_QUALIFIER)))
4250
.setDeletionProtection(false);
43-
return testEnvRule.env().getTableAdminClient().createAuthorizedView(request);
51+
int retryCount = 0;
52+
int maxRetries = 10;
53+
while (true) {
54+
try {
55+
return testEnvRule.env().getTableAdminClient().createAuthorizedView(request);
56+
} catch (UnavailableException e) {
57+
if (++retryCount == maxRetries) {
58+
throw e;
59+
}
60+
logger.log(
61+
Level.INFO,
62+
"Retrying createAuthorizedView "
63+
+ authorizedViewId
64+
+ " in table "
65+
+ tableId
66+
+ ", retryCount: "
67+
+ retryCount);
68+
// Exponential backoff delay starting at 100ms.
69+
double expSleep = 100 * Math.pow(2, retryCount);
70+
Thread.sleep((long) Math.min(expSleep, TimeUnit.MINUTES.toMillis(1)));
71+
}
72+
}
4473
}
4574
}

0 commit comments

Comments
 (0)