Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle retry info so client respect the delay server sets #2026

Merged
merged 14 commits into from
Dec 19, 2023
Prev Previous commit
Next Next commit
fix format
  • Loading branch information
mutianf committed Dec 19, 2023
commit cf0066135e47c24f65c489bd3cdeb37173625190
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public void testCheckAndMutateDisableRetryInfo() throws IOException {

@Test
public void testReadModifyWrite() {

verifyRetryInfoIsUsed(
() ->
client.readModifyWriteRow(
Expand All @@ -278,7 +277,6 @@ public void testReadModifyWriteDisableRetryInfo() throws IOException {

@Test
public void testReadChangeStream() {

verifyRetryInfoIsUsed(
() -> client.readChangeStream(ReadChangeStreamQuery.create("table")).iterator().hasNext(),
true);
Expand Down Expand Up @@ -307,7 +305,6 @@ public void testReadChangeStreamDisableRetryInfo() throws IOException {

@Test
public void testGenerateInitialChangeStreamPartition() {

verifyRetryInfoIsUsed(
() -> client.generateInitialChangeStreamPartitions("table").iterator().hasNext(), true);
}
Expand Down Expand Up @@ -342,33 +339,28 @@ private void verifyRetryInfoIsUsed(Runnable runnable, boolean retryableError) {
assertThat(stopwatch.elapsed()).isAtLeast(Duration.ofSeconds(delay.getSeconds()));
}

private void verifyRetryInfoCanBeDisabled(Runnable runnable) throws IOException {
settings.stubSettings().setEnableRetryInfo(false);

try (BigtableDataClient client = BigtableDataClient.create(settings.build())) {
enqueueRetryableExceptionWithDelay(delay);
Stopwatch stopwatch = Stopwatch.createStarted();
runnable.run();
stopwatch.stop();
private void verifyRetryInfoCanBeDisabled(Runnable runnable) {
enqueueRetryableExceptionWithDelay(delay);
Stopwatch stopwatch = Stopwatch.createStarted();
runnable.run();
stopwatch.stop();

assertThat(attemptCounter.get()).isEqualTo(2);
assertThat(stopwatch.elapsed()).isLessThan(Duration.ofSeconds(delay.getSeconds()));
assertThat(attemptCounter.get()).isEqualTo(2);
assertThat(stopwatch.elapsed()).isLessThan(Duration.ofSeconds(delay.getSeconds()));

attemptCounter.set(0);
ApiException exception = enqueueNonRetryableExceptionWithDelay(delay);
try {
runnable.run();
} catch (ApiException e) {
if (e instanceof MutateRowsException) {
assertThat(
((MutateRowsException) e).getFailedMutations().get(0).getError().getStatusCode())
.isEqualTo(exception.getStatusCode());
} else {
assertThat(e.getStatusCode()).isEqualTo(exception.getStatusCode());
}
attemptCounter.set(0);
ApiException exception = enqueueNonRetryableExceptionWithDelay(delay);
try {
runnable.run();
} catch (ApiException e) {
if (e instanceof MutateRowsException) {
assertThat(((MutateRowsException) e).getFailedMutations().get(0).getError().getStatusCode())
.isEqualTo(exception.getStatusCode());
} else {
assertThat(e.getStatusCode()).isEqualTo(exception.getStatusCode());
}
assertThat(attemptCounter.get()).isEqualTo(1);
}
assertThat(attemptCounter.get()).isEqualTo(1);
}

private void enqueueRetryableExceptionWithDelay(com.google.protobuf.Duration delay) {
Expand Down
Loading