Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 9fb33f0

Browse files
igorbernstein2garrettjonesgoogle
authored andcommitted
Fix misinterpretation of maxAttempts (#497)
1 parent c9e181a commit 9fb33f0

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

gax-grpc/src/main/java/com/google/api/gax/grpc/GrpcCallableFactory.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBas
7474
}
7575
callable = new GrpcExceptionCallable<>(callable, callSettings.getRetryableCodes());
7676

77-
if (!callSettings.getRetryableCodes().isEmpty()
78-
&& callSettings.getRetrySettings().getMaxAttempts() > 1) {
79-
callable = Callables.retrying(callable, callSettings, clientContext);
80-
}
77+
callable = Callables.retrying(callable, callSettings, clientContext);
8178

8279
return callable;
8380
}

gax-grpc/src/test/java/com/google/api/gax/grpc/GrpcCallableFactoryTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.api.gax.grpc.testing.FakeServiceGrpc;
3333
import com.google.api.gax.grpc.testing.FakeServiceImpl;
3434
import com.google.api.gax.grpc.testing.InProcessServer;
35+
import com.google.api.gax.retrying.RetrySettings;
3536
import com.google.api.gax.rpc.ClientContext;
3637
import com.google.api.gax.rpc.InvalidArgumentException;
3738
import com.google.api.gax.rpc.ServerStreamingCallSettings;
@@ -48,6 +49,7 @@
4849
import org.junit.Test;
4950
import org.junit.runner.RunWith;
5051
import org.junit.runners.JUnit4;
52+
import org.threeten.bp.Duration;
5153

5254
@RunWith(JUnit4.class)
5355
public class GrpcCallableFactoryTest {
@@ -84,7 +86,10 @@ public void createServerStreamingCallableRetryableExceptions() throws Exception
8486

8587
// Base case: without config, invalid argument errors are not retryable.
8688
ServerStreamingCallSettings<Color, Money> nonRetryableSettings =
87-
ServerStreamingCallSettings.<Color, Money>newBuilder().build();
89+
ServerStreamingCallSettings.<Color, Money>newBuilder()
90+
.setRetrySettings(
91+
RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(1)).build())
92+
.build();
8893

8994
ServerStreamingCallable<Color, Money> nonRetryableCallable =
9095
GrpcCallableFactory.createServerStreamingCallable(
@@ -105,6 +110,8 @@ public void createServerStreamingCallableRetryableExceptions() throws Exception
105110
ServerStreamingCallSettings<Color, Money> retryableSettings =
106111
ServerStreamingCallSettings.<Color, Money>newBuilder()
107112
.setRetryableCodes(Code.INVALID_ARGUMENT)
113+
.setRetrySettings(
114+
RetrySettings.newBuilder().setTotalTimeout(Duration.ofSeconds(1)).build())
108115
.build();
109116

110117
ServerStreamingCallable<Color, Money> retryableCallable =

gax/src/main/java/com/google/api/gax/rpc/Callables.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public static <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> retrying(
5555
UnaryCallSettings<?, ?> callSettings,
5656
ClientContext clientContext) {
5757

58+
if (callSettings.getRetryableCodes().isEmpty()) {
59+
return innerCallable;
60+
}
61+
5862
RetryAlgorithm<ResponseT> retryAlgorithm =
5963
new RetryAlgorithm<>(
6064
new ApiResultRetryAlgorithm<ResponseT>(),
@@ -72,9 +76,7 @@ public static <RequestT, ResponseT> ServerStreamingCallable<RequestT, ResponseT>
7276
ServerStreamingCallSettings<RequestT, ResponseT> callSettings,
7377
ClientContext clientContext) {
7478

75-
if (callSettings.getRetryableCodes().isEmpty()
76-
|| callSettings.getRetrySettings().getMaxAttempts() <= 1) {
77-
79+
if (callSettings.getRetryableCodes().isEmpty()) {
7880
return innerCallable;
7981
}
8082

gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.google.api.gax.core.FakeApiClock;
3535
import com.google.api.gax.core.RecordingScheduler;
3636
import com.google.api.gax.retrying.RetrySettings;
37+
import com.google.api.gax.rpc.StatusCode.Code;
3738
import com.google.api.gax.rpc.testing.FakeCallContext;
3839
import com.google.api.gax.rpc.testing.FakeCallableFactory;
3940
import com.google.api.gax.rpc.testing.FakeChannel;
@@ -288,6 +289,7 @@ public void testUnknownStatusCode() {
288289

289290
public static UnaryCallSettings<Integer, Integer> createSettings(RetrySettings retrySettings) {
290291
return UnaryCallSettings.<Integer, Integer>newUnaryCallSettingsBuilder()
292+
.setRetryableCodes(Code.UNAVAILABLE)
291293
.setRetrySettings(retrySettings)
292294
.build();
293295
}

0 commit comments

Comments
 (0)