|
27 | 27 | import com.google.api.client.http.HttpHeaders;
|
28 | 28 | import com.google.api.client.http.HttpResponseException;
|
29 | 29 | import com.google.api.gax.retrying.ResultRetryAlgorithm;
|
| 30 | +import com.google.auth.Retryable; |
30 | 31 | import com.google.common.collect.ImmutableList;
|
31 | 32 | import com.google.common.collect.ImmutableSet;
|
32 | 33 | import com.google.common.collect.Sets;
|
@@ -339,6 +340,8 @@ enum ThrowableCategory {
|
339 | 340 | STORAGE_EXCEPTION_0_GSON_MALFORMED_EXCEPTION(
|
340 | 341 | new StorageException(0, "parse error", C.GSON_MALFORMED_EXCEPTION)),
|
341 | 342 | IO_EXCEPTION(new IOException("no retry")),
|
| 343 | + AUTH_RETRYABLE_TRUE(new RetryableException(true)), |
| 344 | + AUTH_RETRYABLE_FALSE(new RetryableException(false)), |
342 | 345 | ;
|
343 | 346 |
|
344 | 347 | private final Throwable throwable;
|
@@ -1042,7 +1045,52 @@ private static ImmutableList<Case> getAllCases() {
|
1042 | 1045 | ThrowableCategory.STORAGE_EXCEPTION_0_GSON_MALFORMED_EXCEPTION,
|
1043 | 1046 | HandlerCategory.NONIDEMPOTENT,
|
1044 | 1047 | ExpectRetry.NO,
|
| 1048 | + Behavior.SAME), |
| 1049 | + new Case( |
| 1050 | + ThrowableCategory.AUTH_RETRYABLE_TRUE, |
| 1051 | + HandlerCategory.IDEMPOTENT, |
| 1052 | + ExpectRetry.YES, |
| 1053 | + Behavior.DEFAULT_MORE_PERMISSIBLE), |
| 1054 | + new Case( |
| 1055 | + ThrowableCategory.AUTH_RETRYABLE_TRUE, |
| 1056 | + HandlerCategory.NONIDEMPOTENT, |
| 1057 | + ExpectRetry.NO, |
| 1058 | + Behavior.SAME), |
| 1059 | + new Case( |
| 1060 | + ThrowableCategory.AUTH_RETRYABLE_FALSE, |
| 1061 | + HandlerCategory.IDEMPOTENT, |
| 1062 | + ExpectRetry.NO, |
| 1063 | + Behavior.SAME), |
| 1064 | + new Case( |
| 1065 | + ThrowableCategory.AUTH_RETRYABLE_FALSE, |
| 1066 | + HandlerCategory.NONIDEMPOTENT, |
| 1067 | + ExpectRetry.NO, |
1045 | 1068 | Behavior.SAME))
|
1046 | 1069 | .build();
|
1047 | 1070 | }
|
| 1071 | + |
| 1072 | + /** |
| 1073 | + * The auth library provides the interface {@link Retryable} to annotate an exception as |
| 1074 | + * retryable. Add a definition here. Explicitly extend IOException to ensure our handling of this |
| 1075 | + * type is sooner than IOExceptions |
| 1076 | + */ |
| 1077 | + private static final class RetryableException extends IOException implements Retryable { |
| 1078 | + |
| 1079 | + private final boolean isRetryable; |
| 1080 | + |
| 1081 | + private RetryableException(boolean isRetryable) { |
| 1082 | + super(String.format("RetryableException{isRetryable=%s}", isRetryable)); |
| 1083 | + this.isRetryable = isRetryable; |
| 1084 | + } |
| 1085 | + |
| 1086 | + @Override |
| 1087 | + public boolean isRetryable() { |
| 1088 | + return isRetryable; |
| 1089 | + } |
| 1090 | + |
| 1091 | + @Override |
| 1092 | + public int getRetryCount() { |
| 1093 | + return 0; |
| 1094 | + } |
| 1095 | + } |
1048 | 1096 | }
|
0 commit comments