22
22
import java .time .Duration ;
23
23
import java .util .concurrent .atomic .AtomicInteger ;
24
24
25
+ import org .assertj .core .api .ThrowingConsumer ;
25
26
import org .junit .jupiter .api .Test ;
26
27
import reactor .core .publisher .Flux ;
27
28
import reactor .core .publisher .Mono ;
@@ -56,6 +57,7 @@ void withSimpleInterceptor() {
56
57
NonAnnotatedBean proxy = (NonAnnotatedBean ) pf .getProxy ();
57
58
58
59
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
60
+ .satisfies (isRetryExhaustedException ())
59
61
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("6" );
60
62
assertThat (target .counter .get ()).isEqualTo (6 );
61
63
}
@@ -71,6 +73,7 @@ void withPostProcessorForMethod() {
71
73
AnnotatedMethodBean target = (AnnotatedMethodBean ) AopProxyUtils .getSingletonTarget (proxy );
72
74
73
75
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
76
+ .satisfies (isRetryExhaustedException ())
74
77
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("6" );
75
78
assertThat (target .counter .get ()).isEqualTo (6 );
76
79
}
@@ -86,12 +89,15 @@ void withPostProcessorForClass() {
86
89
AnnotatedClassBean target = (AnnotatedClassBean ) AopProxyUtils .getSingletonTarget (proxy );
87
90
88
91
assertThatRuntimeException ().isThrownBy (() -> proxy .retryOperation ().block ())
92
+ .satisfies (isReactiveException ())
89
93
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("3" );
90
94
assertThat (target .counter .get ()).isEqualTo (3 );
91
95
assertThatRuntimeException ().isThrownBy (() -> proxy .otherOperation ().block ())
96
+ .satisfies (isReactiveException ())
92
97
.withCauseInstanceOf (IOException .class );
93
98
assertThat (target .counter .get ()).isEqualTo (4 );
94
99
assertThatIllegalStateException ().isThrownBy (() -> proxy .overrideOperation ().blockFirst ())
100
+ .satisfies (isRetryExhaustedException ())
95
101
.withCauseInstanceOf (IOException .class );
96
102
assertThat (target .counter .get ()).isEqualTo (6 );
97
103
}
@@ -108,6 +114,7 @@ void adaptReactiveResultWithMinimalRetrySpec() {
108
114
109
115
// Should execute only 2 times, because maxAttempts=1 means 1 call + 1 retry
110
116
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
117
+ .satisfies (isRetryExhaustedException ())
111
118
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("2" );
112
119
assertThat (target .counter .get ()).isEqualTo (2 );
113
120
}
@@ -123,6 +130,7 @@ void adaptReactiveResultWithZeroDelayAndJitter() {
123
130
ZeroDelayJitterBean proxy = (ZeroDelayJitterBean ) pf .getProxy ();
124
131
125
132
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
133
+ .satisfies (isRetryExhaustedException ())
126
134
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("4" );
127
135
assertThat (target .counter .get ()).isEqualTo (4 );
128
136
}
@@ -138,6 +146,7 @@ void adaptReactiveResultWithJitterGreaterThanDelay() {
138
146
JitterGreaterThanDelayBean proxy = (JitterGreaterThanDelayBean ) pf .getProxy ();
139
147
140
148
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
149
+ .satisfies (ex -> assertThat (ex .getClass ().getSimpleName ()).isEqualTo ("RetryExhaustedException" ))
141
150
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("4" );
142
151
assertThat (target .counter .get ()).isEqualTo (4 );
143
152
}
@@ -153,6 +162,7 @@ void adaptReactiveResultWithFluxMultiValue() {
153
162
FluxMultiValueBean proxy = (FluxMultiValueBean ) pf .getProxy ();
154
163
155
164
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().blockFirst ())
165
+ .satisfies (isRetryExhaustedException ())
156
166
.withCauseInstanceOf (IOException .class ).havingCause ().withMessage ("4" );
157
167
assertThat (target .counter .get ()).isEqualTo (4 );
158
168
}
@@ -184,11 +194,21 @@ void adaptReactiveResultWithImmediateFailure() {
184
194
ImmediateFailureBean proxy = (ImmediateFailureBean ) pf .getProxy ();
185
195
186
196
assertThatIllegalStateException ().isThrownBy (() -> proxy .retryOperation ().block ())
197
+ .satisfies (isRetryExhaustedException ())
187
198
.withCauseInstanceOf (RuntimeException .class ).havingCause ().withMessage ("immediate failure" );
188
199
assertThat (target .counter .get ()).isEqualTo (4 );
189
200
}
190
201
191
202
203
+ private static ThrowingConsumer <? super Throwable > isReactiveException () {
204
+ return ex -> assertThat (ex .getClass ().getSimpleName ()).isEqualTo ("ReactiveException" );
205
+ }
206
+
207
+ private static ThrowingConsumer <? super Throwable > isRetryExhaustedException () {
208
+ return ex -> assertThat (ex .getClass ().getSimpleName ()).isEqualTo ("RetryExhaustedException" );
209
+ }
210
+
211
+
192
212
static class NonAnnotatedBean {
193
213
194
214
AtomicInteger counter = new AtomicInteger ();
0 commit comments