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

#56 deprecate FailureInterpreter methods in CircuitBreaker and add tests #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,10 @@ public String getHealthCheck() {
* CircuitBreaker} by default.
* @see DefaultFailureInterpreter
* @param limit the number of tolerated failures in a window
*
* Deprecated methods will be removed in the 4.0 release
*/
public void setLimit(int limit) {
@Deprecated public void setLimit(int limit) {
FailureInterpreter fi = getFailureInterpreter();
if (!(fi instanceof DefaultFailureInterpreter)) {
throw new IllegalStateException("setLimit() not supported: this CircuitBreaker's FailureInterpreter isn't a DefaultFailureInterpreter.");
Expand All @@ -480,8 +482,10 @@ public void setLimit(int limit) {
* @see DefaultFailureInterpreter
* @param ignore a {@link java.util.Collection} of {@link Throwable}
* classes
*
* Deprecated methods will be removed in the 4.0 release
*/
public void setIgnore(Collection<Class<? extends Throwable>> ignore) {
@Deprecated public void setIgnore(Collection<Class<? extends Throwable>> ignore) {
FailureInterpreter fi = getFailureInterpreter();
if (!(fi instanceof DefaultFailureInterpreter)) {
throw new IllegalStateException("setIgnore() not supported: this CircuitBreaker's FailureInterpreter isn't a DefaultFailureInterpreter.");
Expand All @@ -503,8 +507,10 @@ public void setIgnore(Collection<Class<? extends Throwable>> ignore) {
* CircuitBreaker} by default.
* @see DefaultFailureInterpreter
* @param windowMillis length of the window in milliseconds
*
* Deprecated methods will be removed in the 4.0 release
*/
public void setWindowMillis(long windowMillis) {
@Deprecated public void setWindowMillis(long windowMillis) {
FailureInterpreter fi = getFailureInterpreter();
if (!(fi instanceof DefaultFailureInterpreter)) {
throw new IllegalStateException("setWindowMillis() not supported: this CircuitBreaker's FailureInterpreter isn't a DefaultFailureInterpreter.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void setUp() {
@Test
public void testCreateCircuitBreaker() {
CircuitBreaker breaker = factory.createCircuitBreaker("testCreate", config);
checkBreaker(breaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
checkBreakerWithDefaultFailureInterpreter(breaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
}

@Test
Expand All @@ -55,7 +55,7 @@ public void testCreateDuplicateCircuitBreaker() {
CircuitBreaker secondBreaker = factory.createCircuitBreaker(name, config);

assertSame(createdBreaker, secondBreaker);
checkBreaker(createdBreaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
checkBreakerWithDefaultFailureInterpreter(createdBreaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
}

@Test
Expand All @@ -64,7 +64,7 @@ public void testCreateCircuitBreakerEmptyConfig() {
new CircuitBreakerConfig(-1, new DefaultFailureInterpreter());
CircuitBreaker breaker = factory.createCircuitBreaker("testCreateEmpty", emptyConfig);

checkBreaker(breaker, 0, 0, 15000L); // These are the CircuitBreaker Defaults.
checkBreakerWithDefaultFailureInterpreter(breaker, 0, 0, 15000L); // These are the CircuitBreaker Defaults.
}

@Test
Expand All @@ -76,6 +76,24 @@ public void testCreateCircuitBreakerNullFailureInterpreter() {
checkBreakerNoFailureInterpreter(breaker, 15000L); // These are the CircuitBreaker Defaults.
}

@Test
public void testCreateCircuitBreakerDefaultFailureInterpreter() {
CircuitBreakerConfig emptyConfig =
new CircuitBreakerConfig(-1, new DefaultFailureInterpreter());
CircuitBreaker breaker = factory.createCircuitBreaker("testDefaultFailureInterpreter", emptyConfig);

checkBreakerWithDefaultFailureInterpreter(breaker, 0, 0L, 15000L); // These are the CircuitBreaker Defaults.
}

@Test
public void testCreateCircuitBreakerPercentErrPerTimeFailureInterpreter() {
CircuitBreakerConfig emptyConfig =
new CircuitBreakerConfig(-1, new PercentErrPerTimeFailureInterpreter());
CircuitBreaker breaker = factory.createCircuitBreaker("testPercentErrFailureInterpreter", emptyConfig);

checkBreakerWithPercentErrPerTimeFailureInterpreter(breaker,0L, 15000L);
}

@Test
public void testFindANamedCircuitBreaker() {
String monitorName = "testFind";
Expand Down Expand Up @@ -111,7 +129,7 @@ public void testEmptyPropertyOverrides() {
Properties overrideProperties = new Properties();
factory.setProperties(overrideProperties);
CircuitBreaker breaker = factory.createCircuitBreaker("emptyOverrides", config);
checkBreaker(breaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
checkBreakerWithDefaultFailureInterpreter(breaker, TEST_LIMIT, TEST_WINDOW_MILLIS, TEST_RESET_MILLIS);
}

@Test
Expand All @@ -128,7 +146,7 @@ public void testPropertyOverrides() {
factory.setProperties(overrideProperties);

CircuitBreaker breaker = factory.createCircuitBreaker(name, config);
checkBreaker(breaker, overrideLimit, overrideWindowMillis, overrideResetMillis);
checkBreakerWithDefaultFailureInterpreter(breaker, overrideLimit, overrideWindowMillis, overrideResetMillis);
}

@Test
Expand All @@ -144,14 +162,14 @@ public void testInvalidPropertyOverrides() {
CircuitBreakerConfig emptyConfig =
new CircuitBreakerConfig(-1, new DefaultFailureInterpreter());
CircuitBreaker breaker = factory.createCircuitBreaker(name, emptyConfig);
checkBreaker(breaker, 0, 0L, 15000L); // These are the CircuitBreaker defaults.
checkBreakerWithDefaultFailureInterpreter(breaker, 0, 0L, 15000L); // These are the CircuitBreaker defaults.
assertNotNull(breaker);
}

private void checkBreaker(CircuitBreaker breaker,
int expectedLimit,
long expectedWindowMillis,
long expectedResetMillis) {
private void checkBreakerWithDefaultFailureInterpreter(CircuitBreaker breaker,
int expectedLimit,
long expectedWindowMillis,
long expectedResetMillis) {

assertNotNull(breaker);

Expand All @@ -165,6 +183,21 @@ private void checkBreaker(CircuitBreaker breaker,
assertEquals(breaker.getResetMillis(), expectedResetMillis);
}

private void checkBreakerWithPercentErrPerTimeFailureInterpreter(CircuitBreaker breaker,
long expectedWindowMillis,
long expectedResetMillis) {

assertNotNull(breaker);

PercentErrPerTimeFailureInterpreter failureInterpreter = (PercentErrPerTimeFailureInterpreter) breaker.getFailureInterpreter();

if (failureInterpreter != null) {
assertEquals(failureInterpreter.getWindowMillis(), expectedWindowMillis);
}

assertEquals(breaker.getResetMillis(), expectedResetMillis);
}

private void checkBreakerNoFailureInterpreter(CircuitBreaker breaker,
long expectedResetMillis) {

Expand Down