Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(refactor) make RetryException constructor public #1657

Merged
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
17 changes: 17 additions & 0 deletions riptide-failsafe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ RetryPolicy.<ClientHttpResponse>builder()
.build();
```

By default, you can use RetryException in your routes to retry the request:

```java
retryClient.get()
.dispatch(
series(), on(CLIENT_ERROR).call(
response -> {
if (specificCondition(response)) {
throw new RetryException(response); // we will retry this one
} else {
throw new AnyOtherException(response); // we wont retry this one
}
}
)
).join()
```

Failsafe supports dynamically computed delays using a custom function.

Riptide: Failsafe offers implementations that understand:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@API(status = STABLE)
public final class RetryException extends HttpResponseException {

RetryException(final ClientHttpResponse response) throws IOException {
public RetryException(final ClientHttpResponse response) throws IOException {
super("Retrying response", response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
import org.zalando.riptide.autoconfigure.MetricsTestAutoConfiguration;
import org.zalando.riptide.autoconfigure.OpenTracingTestAutoConfiguration;
import org.zalando.riptide.autoconfigure.RiptideClientTest;
import org.zalando.riptide.failsafe.RetryException;

import java.util.concurrent.CompletionException;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.springframework.http.HttpStatus.Series.SERVER_ERROR;
import static org.springframework.http.HttpStatus.Series.CLIENT_ERROR;
import static org.springframework.test.web.client.ExpectedCount.times;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withServerError;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest;
import static org.zalando.riptide.Bindings.on;
import static org.zalando.riptide.Navigators.series;
import static org.zalando.riptide.failsafe.RetryRoute.retry;
Expand Down Expand Up @@ -54,4 +57,17 @@ void shouldRetryForAtMostMaxRetriesTimes() {

server.verify();
}

@Test
void shouldRetryForCustomRetryException() {
server.expect(times(3), requestTo("http://retry-test")).andRespond(withBadRequest());


assertThrows(CompletionException.class,
() -> retryClient.get().dispatch(series(), on(CLIENT_ERROR).call(response -> {
throw new RetryException(response);
})).join());

server.verify();
}
}
Loading