Skip to content

Commit

Permalink
test(retry): add a test which ensures expected behavior of new retry …
Browse files Browse the repository at this point in the history
…handlers (#1119)

* test(retry): add a test which ensures expected behavior of new retry handlers

In addition to providing the new handlers which are validated to some extent with the retry conformance suite, we also want to ensure we maintain support for "java specific" errors which historically are already handled my the core library. In some ways this also functions as a regression suite of errors we want to keep track of for retry purposes.

* chore: run formatter to turn a ~450 line file into a 900 line one!!!!
  • Loading branch information
BenWhitehead committed Nov 1, 2021
1 parent 57bec4d commit 2d64f90
Show file tree
Hide file tree
Showing 2 changed files with 952 additions and 26 deletions.
Expand Up @@ -73,41 +73,48 @@ public RetryResult afterEval(Exception exception, RetryResult retryResult) {

@Override
public RetryResult beforeEval(Exception exception) {
Throwable t = exception;

if (t instanceof BaseServiceException) {
BaseServiceException storageException = (BaseServiceException) t;
Throwable cause = storageException.getCause();
// if the cause of the exception is an IOException lift it before we continue
// evaluation
if (cause instanceof IOException) {
t = cause;
}
}

if (t instanceof BaseServiceException) {
BaseServiceException baseServiceException = (BaseServiceException) t;
int code = baseServiceException.getCode();
String reason = baseServiceException.getReason();
return shouldRetryCode(code, reason);
} else if (t instanceof HttpResponseException) {
int code = ((HttpResponseException) t).getStatusCode();
return shouldRetryCode(code, null);
} else if (t instanceof IOException) {
IOException ioException = (IOException) t;
return BaseServiceException.isRetryable(idempotent, ioException)
? RetryResult.RETRY
: RetryResult.NO_RETRY;
if (exception instanceof BaseServiceException) {
BaseServiceException baseServiceException = (BaseServiceException) exception;
return deepShouldRetry(baseServiceException);
} else if (exception instanceof HttpResponseException) {
int code = ((HttpResponseException) exception).getStatusCode();
return shouldRetryCodeReason(code, null);
} else if (exception instanceof IOException) {
IOException ioException = (IOException) exception;
return shouldRetryIOException(ioException);
}
return RetryResult.CONTINUE_EVALUATION;
}

private RetryResult shouldRetryCode(Integer code, String reason) {
private RetryResult shouldRetryCodeReason(Integer code, String reason) {
if (BaseServiceException.isRetryable(code, reason, idempotent, retryableErrors)) {
return RetryResult.RETRY;
} else {
return RetryResult.NO_RETRY;
}
}

private RetryResult shouldRetryIOException(IOException ioException) {
if (BaseServiceException.isRetryable(idempotent, ioException)) {
return RetryResult.RETRY;
} else {
return RetryResult.NO_RETRY;
}
}

private RetryResult deepShouldRetry(BaseServiceException baseServiceException) {
if (baseServiceException.getCode() == BaseServiceException.UNKNOWN_CODE
&& baseServiceException.getReason() == null) {
final Throwable cause = baseServiceException.getCause();
if (cause instanceof IOException) {
IOException ioException = (IOException) cause;
return shouldRetryIOException(ioException);
}
}

int code = baseServiceException.getCode();
String reason = baseServiceException.getReason();
return shouldRetryCodeReason(code, reason);
}
}
}

0 comments on commit 2d64f90

Please sign in to comment.