This repository was archived by the owner on Mar 30, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-5
lines changed
main/java/com/nurkiewicz/asyncretry
test/java/com/nurkiewicz/asyncretry Expand file tree Collapse file tree 2 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -53,11 +53,20 @@ protected void handleThrowable(Throwable t, long duration) {
53
53
54
54
protected void handleUserThrowable (Throwable t , long duration ) {
55
55
final AsyncRetryContext nextRetryContext = context .nextRetry (t );
56
- if (parent .getRetryPolicy ().shouldContinue (nextRetryContext )) {
57
- final long delay = calculateNextDelay (duration , nextRetryContext , parent .getBackoff ());
58
- retryWithDelay (nextRetryContext , delay , duration );
59
- } else {
60
- logFailure (nextRetryContext , duration );
56
+
57
+ try {
58
+ if (parent .getRetryPolicy ().shouldContinue (nextRetryContext )) {
59
+ final long delay = calculateNextDelay (duration , nextRetryContext , parent .getBackoff ());
60
+ retryWithDelay (nextRetryContext , delay , duration );
61
+ } else {
62
+ logFailure (nextRetryContext , duration );
63
+ future .completeExceptionally (t );
64
+ }
65
+ } catch (Throwable t2 ) {
66
+ log .error ("Threw while trying to decide on retry {} after {}" ,
67
+ nextRetryContext .getRetryCount (),
68
+ duration ,
69
+ t2 );
61
70
future .completeExceptionally (t );
62
71
}
63
72
}
Original file line number Diff line number Diff line change @@ -106,6 +106,32 @@ public void shouldRethrowOriginalExceptionFromUserFutureCompletion() throws Exce
106
106
}
107
107
}
108
108
109
+ @ Test
110
+ public void shouldRethrowOriginalExceptionFromUserFutureCompletionAndAbortWhenTestFails () throws Exception {
111
+ //given
112
+ final RetryExecutor executor = new AsyncRetryExecutor (schedulerMock ).
113
+ abortIf (t -> { throw new RuntimeException ("test invalid" ); });
114
+
115
+ given (serviceMock .safeAsync ()).willReturn (
116
+ failedAsync (new SocketException (DON_T_PANIC ))
117
+ );
118
+
119
+ //when
120
+ final CompletableFuture <String > future = executor .getFutureWithRetry (ctx -> serviceMock .safeAsync ());
121
+
122
+ //then
123
+ assertThat (future .isCompletedExceptionally ()).isTrue ();
124
+
125
+ try {
126
+ future .get ();
127
+ failBecauseExceptionWasNotThrown (ExecutionException .class );
128
+ } catch (ExecutionException e ) {
129
+ final Throwable cause = e .getCause ();
130
+ assertThat (cause ).isInstanceOf (SocketException .class );
131
+ assertThat (cause ).hasMessage (DON_T_PANIC );
132
+ }
133
+ }
134
+
109
135
@ Test
110
136
public void shouldAbortWhenTargetFutureWantsToAbort () throws Exception {
111
137
//given
You can’t perform that action at this time.
0 commit comments