GH-188: Expose @CircuitBreaker(recover) attribute
Fixes: #188 Issue link: https://github.com/spring-projects/spring-retry/issues/188 All the logic to determine a recover method is there. We are just missing the `CircuitBreaker(recover)` attribute with an `@AliasFor(annotation = Retryable.class)`
This commit is contained in:
@@ -190,4 +190,13 @@ public @interface CircuitBreaker {
|
||||
*/
|
||||
boolean throwLastExceptionOnExhausted() default false;
|
||||
|
||||
/**
|
||||
* Name of method in this class to use for recover. Method had to be marked with
|
||||
* {@link Recover} annotation.
|
||||
* @return the name of recover method
|
||||
* @since 2.0.9
|
||||
*/
|
||||
@AliasFor(annotation = Retryable.class)
|
||||
String recover() default "";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2023 the original author or authors.
|
||||
* Copyright 2006-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
*
|
||||
*/
|
||||
public class CircuitBreakerInterceptorStatisticsTests {
|
||||
@@ -106,7 +107,7 @@ public class CircuitBreakerInterceptorStatisticsTests {
|
||||
|
||||
private RetryContext status;
|
||||
|
||||
@CircuitBreaker(label = "test", maxAttempts = 1)
|
||||
@CircuitBreaker(label = "test", maxAttempts = 1, recover = "recover")
|
||||
public Object service(String input) throws Exception {
|
||||
this.status = RetrySynchronizationManager.getContext();
|
||||
Integer attempts = (Integer) status.getAttribute("attempts");
|
||||
@@ -122,11 +123,16 @@ public class CircuitBreakerInterceptorStatisticsTests {
|
||||
}
|
||||
|
||||
@Recover
|
||||
public Object recover() {
|
||||
public Object recover(String input) {
|
||||
this.status.setAttribute(RECOVERED, true);
|
||||
return RECOVERED;
|
||||
}
|
||||
|
||||
@Recover
|
||||
public Object anotherRecover(Object input) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return this.status != null && this.status.getAttribute("open") == Boolean.TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user