3434
3535import static org .assertj .core .api .Assertions .assertThat ;
3636import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
37+ import static org .springframework .scheduling .annotation .ScheduledAnnotationReactiveSupport .getPublisherForReactiveMethod ;
3738
3839class ScheduledAnnotationReactiveSupportTests {
3940
@@ -47,17 +48,17 @@ void ensureReactor() {
4748 "publisherString" , "monoThrows" }) //note: monoWithParams can't be found by this test
4849 void checkIsReactive (String method ) {
4950 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 ();
5152 }
5253
5354 @ Test
5455 void checkNotReactive () {
5556 Method string = ReflectionUtils .findMethod (ReactiveMethods .class , "oops" );
5657 Method future = ReflectionUtils .findMethod (ReactiveMethods .class , "future" );
5758
58- assertThat (ScheduledAnnotationReactiveSupport .isReactive (string ))
59+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (string ))
5960 .as ("String-returning" ).isFalse ();
60- assertThat (ScheduledAnnotationReactiveSupport .isReactive (future ))
61+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (future ))
6162 .as ("Future-returning" ).isFalse ();
6263 }
6364
@@ -131,24 +132,37 @@ void init() {
131132 this .target = new ReactiveMethods ();
132133 }
133134
135+ @ SuppressWarnings ("ReactiveStreamsUnusedPublisher" )
134136 @ Test
135137 void rejectWithParams () {
136138 Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoWithParam" , String .class );
137139
138- assertThat (ScheduledAnnotationReactiveSupport .isReactive (m )).as ("isReactive" ).isTrue ();
140+ assertThat (ScheduledAnnotationReactiveSupport .checkReactorRuntimeIfNeeded (m )).as ("isReactive" ).isTrue ();
139141
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
140148 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" )
143151 .withNoCause ();
144152 }
145153
146154 @ Test
147155 void rejectCantProducePublisher () {
148156 Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoThrows" );
149157
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
150164 assertThatIllegalArgumentException ().isThrownBy (() -> new ScheduledAnnotationReactiveSupport .ReactiveTask (
151- m , target , Duration .ZERO , Duration .ZERO , false ))
165+ m , target , Duration .ZERO , Duration .ZERO , false , false ))
152166 .withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
153167 .withCause (new IllegalStateException ("expected" ));
154168 }
@@ -157,8 +171,14 @@ void rejectCantProducePublisher() {
157171 void rejectCantAccessMethod () {
158172 Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "monoThrowsIllegalAccess" );
159173
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
160180 assertThatIllegalArgumentException ().isThrownBy (() -> new ScheduledAnnotationReactiveSupport .ReactiveTask (
161- m , target , Duration .ZERO , Duration .ZERO , false ))
181+ m , target , Duration .ZERO , Duration .ZERO , false , false ))
162182 .withMessage ("Cannot obtain a Publisher from the @Scheduled reactive method" )
163183 .withCause (new IllegalAccessException ("expected" ));
164184 }
@@ -167,7 +187,7 @@ void rejectCantAccessMethod() {
167187 void hasCheckpointToString () {
168188 Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "mono" );
169189 final ScheduledAnnotationReactiveSupport .ReactiveTask reactiveTask = new ScheduledAnnotationReactiveSupport .ReactiveTask (
170- m , target , Duration .ZERO , Duration .ZERO , false );
190+ m , target , Duration .ZERO , Duration .ZERO , false , false );
171191
172192 assertThat (reactiveTask ).hasToString ("@Scheduled 'org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods#mono()' [ScheduledAnnotationReactiveSupport]" );
173193 }
@@ -176,7 +196,7 @@ void hasCheckpointToString() {
176196 void cancelledEarlyPreventsSubscription () {
177197 Method m = ReflectionUtils .findMethod (ReactiveMethods .class , "trackingMono" );
178198 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 );
180200 reactiveTask .cancel ();
181201 reactiveTask .subscribe ();
182202
@@ -187,7 +207,7 @@ void cancelledEarlyPreventsSubscription() {
187207 void noInitialDelayFixedDelay () throws InterruptedException {
188208 Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
189209 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 );
191211 reactiveTask .subscribe ();
192212 Thread .sleep (500 );
193213 reactiveTask .cancel ();
@@ -199,7 +219,7 @@ void noInitialDelayFixedDelay() throws InterruptedException {
199219 void noInitialDelayFixedRate () throws InterruptedException {
200220 Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
201221 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 );
203223 reactiveTask .subscribe ();
204224 Thread .sleep (500 );
205225 reactiveTask .cancel ();
@@ -211,7 +231,7 @@ void noInitialDelayFixedRate() throws InterruptedException {
211231 void initialDelayFixedDelay () throws InterruptedException {
212232 Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
213233 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 );
215235 reactiveTask .subscribe ();
216236 Thread .sleep (500 );
217237 reactiveTask .cancel ();
@@ -223,7 +243,7 @@ void initialDelayFixedDelay() throws InterruptedException {
223243 void initialDelayFixedRate () throws InterruptedException {
224244 Method m = ReflectionUtils .findMethod (target .getClass (), "trackingMono" );
225245 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 );
227247 reactiveTask .subscribe ();
228248 Thread .sleep (500 );
229249 reactiveTask .cancel ();
@@ -235,7 +255,7 @@ void initialDelayFixedRate() throws InterruptedException {
235255 void monoErrorHasCheckpoint () throws InterruptedException {
236256 Method m = ReflectionUtils .findMethod (target .getClass (), "monoError" );
237257 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 );
239259
240260 assertThat (reactiveTask .checkpoint ).isEqualTo ("@Scheduled 'org.springframework.scheduling.annotation"
241261 + ".ScheduledAnnotationReactiveSupportTests$ReactiveMethods#monoError()'"
0 commit comments