Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
### Documentation

### Internal Changes
* Capture DatabricksError when retrying API calls ([#427](https://github.com/databricks/databricks-sdk-java/pull/427)).

### API Changes
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,13 @@ private Response executeInner(Request in, String path) {
}
if (attemptNumber == maxAttempts) {
throw new DatabricksException(
String.format("Request %s failed after %d retries", in, maxAttempts), err);
String.format("Request %s failed after %d retries", in, maxAttempts), databricksError);
}

// Retry after a backoff.
long sleepMillis = getBackoffMillis(out, attemptNumber);
LOG.debug(String.format("Retry %s in %dms", in.getRequestLine(), sleepMillis));
LOG.debug(
String.format("Retry %s in %dms", in.getRequestLine(), sleepMillis), databricksError);
try {
timer.sleep(sleepMillis);
} catch (InterruptedException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -88,12 +89,14 @@ private <T> void runApiClientTest(
runApiClientTest(client, request, clazz, expectedResponse);
}

private void runFailingApiClientTest(
@CanIgnoreReturnValue
private DatabricksException runFailingApiClientTest(
Request request, List<ResponseProvider> responses, Class<?> clazz, String expectedMessage)
throws IOException {
DatabricksException exception =
runFailingApiClientTest(request, responses, clazz, DatabricksException.class);
assertEquals(exception.getMessage(), expectedMessage);
return exception;
}

private <T extends Throwable> T runFailingApiClientTest(
Expand Down Expand Up @@ -217,16 +220,21 @@ void retry429() throws IOException {
@Test
void failAfterTooManyRetries() throws IOException {
Request req = getBasicRequest();
runFailingApiClientTest(
req,
Arrays.asList(
getTooManyRequestsResponseWithRetryAfterDateHeader(req),
getTooManyRequestsResponse(req),
getTooManyRequestsResponse(req),
getTooManyRequestsResponse(req),
getSuccessResponse(req)),
MyEndpointResponse.class,
"Request GET /api/my/endpoint failed after 4 retries");
DatabricksException exception =
runFailingApiClientTest(
req,
Arrays.asList(
getTooManyRequestsResponseWithRetryAfterDateHeader(req),
getTooManyRequestsResponse(req),
getTooManyRequestsResponse(req),
getTooManyRequestsResponse(req),
getSuccessResponse(req)),
MyEndpointResponse.class,
"Request GET /api/my/endpoint failed after 4 retries");
assertInstanceOf(DatabricksError.class, exception.getCause());
DatabricksError cause = (DatabricksError) exception.getCause();
assertEquals(cause.getErrorCode(), "TOO_MANY_REQUESTS");
assertEquals(cause.getStatusCode(), 429);
}

@Test
Expand Down
Loading