|
11 | 11 | import com.fasterxml.jackson.annotation.JsonProperty; |
12 | 12 | import com.fasterxml.jackson.core.JsonProcessingException; |
13 | 13 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 14 | +import com.google.errorprone.annotations.CanIgnoreReturnValue; |
14 | 15 | import java.io.IOException; |
15 | 16 | import java.net.MalformedURLException; |
16 | 17 | import java.net.URL; |
@@ -88,12 +89,14 @@ private <T> void runApiClientTest( |
88 | 89 | runApiClientTest(client, request, clazz, expectedResponse); |
89 | 90 | } |
90 | 91 |
|
91 | | - private void runFailingApiClientTest( |
| 92 | + @CanIgnoreReturnValue |
| 93 | + private DatabricksException runFailingApiClientTest( |
92 | 94 | Request request, List<ResponseProvider> responses, Class<?> clazz, String expectedMessage) |
93 | 95 | throws IOException { |
94 | 96 | DatabricksException exception = |
95 | 97 | runFailingApiClientTest(request, responses, clazz, DatabricksException.class); |
96 | 98 | assertEquals(exception.getMessage(), expectedMessage); |
| 99 | + return exception; |
97 | 100 | } |
98 | 101 |
|
99 | 102 | private <T extends Throwable> T runFailingApiClientTest( |
@@ -217,16 +220,21 @@ void retry429() throws IOException { |
217 | 220 | @Test |
218 | 221 | void failAfterTooManyRetries() throws IOException { |
219 | 222 | Request req = getBasicRequest(); |
220 | | - runFailingApiClientTest( |
221 | | - req, |
222 | | - Arrays.asList( |
223 | | - getTooManyRequestsResponseWithRetryAfterDateHeader(req), |
224 | | - getTooManyRequestsResponse(req), |
225 | | - getTooManyRequestsResponse(req), |
226 | | - getTooManyRequestsResponse(req), |
227 | | - getSuccessResponse(req)), |
228 | | - MyEndpointResponse.class, |
229 | | - "Request GET /api/my/endpoint failed after 4 retries"); |
| 223 | + DatabricksException exception = |
| 224 | + runFailingApiClientTest( |
| 225 | + req, |
| 226 | + Arrays.asList( |
| 227 | + getTooManyRequestsResponseWithRetryAfterDateHeader(req), |
| 228 | + getTooManyRequestsResponse(req), |
| 229 | + getTooManyRequestsResponse(req), |
| 230 | + getTooManyRequestsResponse(req), |
| 231 | + getSuccessResponse(req)), |
| 232 | + MyEndpointResponse.class, |
| 233 | + "Request GET /api/my/endpoint failed after 4 retries"); |
| 234 | + assertInstanceOf(DatabricksError.class, exception.getCause()); |
| 235 | + DatabricksError cause = (DatabricksError) exception.getCause(); |
| 236 | + assertEquals(cause.getErrorCode(), "TOO_MANY_REQUESTS"); |
| 237 | + assertEquals(cause.getStatusCode(), 429); |
230 | 238 | } |
231 | 239 |
|
232 | 240 | @Test |
|
0 commit comments