34
34
35
35
import static org .assertj .core .api .Assertions .assertThat ;
36
36
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
37
+ import static org .springframework .scheduling .annotation .ScheduledAnnotationReactiveSupport .getPublisherForReactiveMethod ;
37
38
38
39
class ScheduledAnnotationReactiveSupportTests {
39
40
@@ -47,17 +48,17 @@ void ensureReactor() {
47
48
"publisherString" , "monoThrows" }) //note: monoWithParams can't be found by this test
48
49
void checkIsReactive (String method ) {
49
50
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , method );
50
- assertThat (ScheduledAnnotationReactiveSupport .isReactive (m )).as (m .getName ()).isTrue ();
51
+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (m )).as (m .getName ()).isTrue ();
51
52
}
52
53
53
54
@ Test
54
55
void checkNotReactive () {
55
56
Method string = ReflectionUtils .findMethod (ReactiveMethods .class , "oops" );
56
57
Method future = ReflectionUtils .findMethod (ReactiveMethods .class , "future" );
57
58
58
- assertThat (ScheduledAnnotationReactiveSupport .isReactive (string ))
59
+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (string ))
59
60
.as ("String-returning" ).isFalse ();
60
- assertThat (ScheduledAnnotationReactiveSupport .isReactive (future ))
61
+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (future ))
61
62
.as ("Future-returning" ).isFalse ();
62
63
}
63
64
@@ -131,24 +132,37 @@ void init() {
131
132
this .target = new ReactiveMethods ();
132
133
}
133
134
135
+ @ SuppressWarnings ("ReactiveStreamsUnusedPublisher" )
134
136
@ Test
135
137
void rejectWithParams () {
136
138
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoWithParam" , String .class );
137
139
138
- assertThat (ScheduledAnnotationReactiveSupport .isReactive (m )).as ("isReactive" ).isTrue ();
140
+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (m )).as ("isReactive" ).isTrue ();
139
141
142
+ //static helper method
143
+ assertThatIllegalArgumentException ().isThrownBy (() -> getPublisherForReactiveMethod (m , target ))
144
+ .withMessage ("Only no-arg reactive methods may be annotated with @Scheduled" )
145
+ .withNoCause ();
146
+
147
+ //constructor of task
140
148
assertThatIllegalArgumentException ().isThrownBy (() -> new ScheduledAnnotationReactiveSupport .ReactiveTask (
141
- m , target , Duration .ZERO , Duration .ZERO , false ))
142
- .withMessage ("Only no-arg methods may be annotated with @Scheduled" )
149
+ m , target , Duration .ZERO , Duration .ZERO , false , false ))
150
+ .withMessage ("Only no-arg reactive methods may be annotated with @Scheduled" )
143
151
.withNoCause ();
144
152
}
145
153
146
154
@ Test
147
155
void rejectCantProducePublisher () {
148
156
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoThrows" );
149
157
158
+ //static helper method
159
+ assertThatIllegalArgumentException ().isThrownBy (() -> getPublisherForReactiveMethod (m , target ))
160
+ .withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
161
+ .withCause (new IllegalStateException ("expected" ));
162
+
163
+ //constructor of task
150
164
assertThatIllegalArgumentException ().isThrownBy (() -> new ScheduledAnnotationReactiveSupport .ReactiveTask (
151
- m , target , Duration .ZERO , Duration .ZERO , false ))
165
+ m , target , Duration .ZERO , Duration .ZERO , false , false ))
152
166
.withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
153
167
.withCause (new IllegalStateException ("expected" ));
154
168
}
@@ -157,8 +171,14 @@ void rejectCantProducePublisher() {
157
171
void rejectCantAccessMethod () {
158
172
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoThrowsIllegalAccess" );
159
173
174
+ //static helper method
175
+ assertThatIllegalArgumentException ().isThrownBy (() -> getPublisherForReactiveMethod (m , target ))
176
+ .withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
177
+ .withCause (new IllegalAccessException ("expected" ));
178
+
179
+ //constructor of task
160
180
assertThatIllegalArgumentException ().isThrownBy (() -> new ScheduledAnnotationReactiveSupport .ReactiveTask (
161
- m , target , Duration .ZERO , Duration .ZERO , false ))
181
+ m , target , Duration .ZERO , Duration .ZERO , false , false ))
162
182
.withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
163
183
.withCause (new IllegalAccessException ("expected" ));
164
184
}
@@ -167,7 +187,7 @@ void rejectCantAccessMethod() {
167
187
void hasCheckpointToString () {
168
188
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "mono" );
169
189
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
170
- m , target , Duration .ZERO , Duration .ZERO , false );
190
+ m , target , Duration .ZERO , Duration .ZERO , false , false );
171
191
172
192
assertThat (reactiveTask ).hasToString ("@Scheduled 'org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods#mono()' [ScheduledAnnotationReactiveSupport]" );
173
193
}
@@ -176,7 +196,7 @@ void hasCheckpointToString() {
176
196
void cancelledEarlyPreventsSubscription () {
177
197
Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "trackingMono" );
178
198
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
179
- m , target , Duration .ZERO , Duration .ofSeconds (10 ), false );
199
+ m , target , Duration .ZERO , Duration .ofSeconds (10 ), false , false );
180
200
reactiveTask .cancel ();
181
201
reactiveTask .subscribe ();
182
202
@@ -187,7 +207,7 @@ void cancelledEarlyPreventsSubscription() {
187
207
void noInitialDelayFixedDelay () throws InterruptedException {
188
208
Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
189
209
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
190
- m , target , Duration .ZERO , Duration .ofSeconds (10 ), false );
210
+ m , target , Duration .ZERO , Duration .ofSeconds (10 ), false , false );
191
211
reactiveTask .subscribe ();
192
212
Thread .sleep (500 );
193
213
reactiveTask .cancel ();
@@ -199,7 +219,7 @@ void noInitialDelayFixedDelay() throws InterruptedException {
199
219
void noInitialDelayFixedRate () throws InterruptedException {
200
220
Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
201
221
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
202
- m , target , Duration .ZERO , Duration .ofSeconds (10 ), true );
222
+ m , target , Duration .ZERO , Duration .ofSeconds (10 ), true , false );
203
223
reactiveTask .subscribe ();
204
224
Thread .sleep (500 );
205
225
reactiveTask .cancel ();
@@ -211,7 +231,7 @@ void noInitialDelayFixedRate() throws InterruptedException {
211
231
void initialDelayFixedDelay () throws InterruptedException {
212
232
Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
213
233
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
214
- m , target , Duration .ofSeconds (10 ), Duration .ofMillis (500 ), false );
234
+ m , target , Duration .ofSeconds (10 ), Duration .ofMillis (500 ), false , false );
215
235
reactiveTask .subscribe ();
216
236
Thread .sleep (500 );
217
237
reactiveTask .cancel ();
@@ -223,7 +243,7 @@ void initialDelayFixedDelay() throws InterruptedException {
223
243
void initialDelayFixedRate () throws InterruptedException {
224
244
Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
225
245
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
226
- m , target , Duration .ofSeconds (10 ), Duration .ofMillis (500 ), true );
246
+ m , target , Duration .ofSeconds (10 ), Duration .ofMillis (500 ), true , false );
227
247
reactiveTask .subscribe ();
228
248
Thread .sleep (500 );
229
249
reactiveTask .cancel ();
@@ -235,7 +255,7 @@ void initialDelayFixedRate() throws InterruptedException {
235
255
void monoErrorHasCheckpoint () throws InterruptedException {
236
256
Method m = ReflectionUtils .findMethod (target .getClass (), "monoError" );
237
257
final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
238
- m , target , Duration .ZERO , Duration .ofSeconds (10 ), true );
258
+ m , target , Duration .ZERO , Duration .ofSeconds (10 ), true , false );
239
259
240
260
assertThat (reactiveTask .checkpoint ).isEqualTo ("@Scheduled 'org.springframework.scheduling.annotation"
241
261
+ ".ScheduledAnnotationReactiveSupportTests$ReactiveMethods#monoError()'"
0 commit comments