-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #331: CircuitBreaker not handle java.lang.Error, but only java.…
…lang.Exception.
- Loading branch information
Robert Winkler
committed
Apr 2, 2019
1 parent
626d9a4
commit 53199cb
Showing
1 changed file
with
43 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,10 +404,11 @@ static <T> CheckedFunction0<T> decorateCheckedSupplier(CircuitBreaker circuitBre | |
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
return returnValue; | ||
} catch (Throwable throwable) { | ||
} catch (Exception exception) { | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -439,12 +440,15 @@ static <T> Supplier<CompletionStage<T>> decorateCompletionStage( | |
try { | ||
supplier.get().whenComplete((result, throwable) -> { | ||
long durationInNanos = System.nanoTime() - start; | ||
if (throwable != null) { | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
promise.completeExceptionally(throwable); | ||
} else { | ||
if (result != null) { | ||
circuitBreaker.onSuccess(durationInNanos); | ||
promise.complete(result); | ||
} else if (throwable instanceof Exception) { | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
promise.completeExceptionally(throwable); | ||
} else{ | ||
// Do not handle java.lang.Error | ||
promise.completeExceptionally(throwable); | ||
} | ||
}); | ||
} catch (Throwable throwable) { | ||
|
@@ -474,10 +478,11 @@ static CheckedRunnable decorateCheckedRunnable(CircuitBreaker circuitBreaker, Ch | |
runnable.run(); | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
} catch (Throwable throwable){ | ||
} catch (Exception exception){ | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
RobWin
Member
|
||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -500,10 +505,11 @@ static <T> Callable<T> decorateCallable(CircuitBreaker circuitBreaker, Callable< | |
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
return returnValue; | ||
} catch (Throwable throwable) { | ||
} catch (Exception exception) { | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -526,10 +532,11 @@ static <T> Supplier<T> decorateSupplier(CircuitBreaker circuitBreaker, Supplier< | |
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
return returnValue; | ||
} catch (Throwable throwable) { | ||
} catch (Exception exception) { | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -551,10 +558,11 @@ static <T> Consumer<T> decorateConsumer(CircuitBreaker circuitBreaker, Consumer< | |
consumer.accept(t); | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
} catch (Throwable throwable) { | ||
} catch (Exception exception) { | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -576,10 +584,11 @@ static <T> CheckedConsumer<T> decorateCheckedConsumer(CircuitBreaker circuitBrea | |
consumer.accept(t); | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
} catch (Throwable throwable) { | ||
} catch (Exception exception) { | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -600,10 +609,11 @@ static Runnable decorateRunnable(CircuitBreaker circuitBreaker, Runnable runnabl | |
runnable.run(); | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
} catch (Throwable throwable){ | ||
} catch (Exception exception){ | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -626,10 +636,11 @@ static <T, R> Function<T, R> decorateFunction(CircuitBreaker circuitBreaker, Fun | |
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
return returnValue; | ||
} catch (Throwable throwable){ | ||
} catch (Exception exception){ | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
@@ -652,10 +663,11 @@ static <T, R> CheckedFunction1<T, R> decorateCheckedFunction(CircuitBreaker circ | |
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onSuccess(durationInNanos); | ||
return returnValue; | ||
} catch (Throwable throwable){ | ||
} catch (Exception exception){ | ||
// Do not handle java.lang.Error | ||
long durationInNanos = System.nanoTime() - start; | ||
circuitBreaker.onError(durationInNanos, throwable); | ||
throw throwable; | ||
circuitBreaker.onError(durationInNanos, exception); | ||
throw exception; | ||
} | ||
}; | ||
} | ||
|
Hi, Because of this change, it break our testcase where incase of OutOfMemory Error the CB state is now changed from OPEN to CLOSE? is it valid?