Skip to content

Commit 78a47c9

Browse files
committed
polish and fix tests
1 parent a413f4f commit 78a47c9

File tree

3 files changed

+16
-98
lines changed

3 files changed

+16
-98
lines changed

spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static boolean isReactive(Method method) {
7171
Assert.isTrue(method.getParameterCount() == 1,"Kotlin suspending functions may only be"
7272
+ " annotated with @Scheduled if declared without arguments");
7373
Assert.isTrue(coroutinesReactorPresent, "Kotlin suspending functions may only be annotated with"
74-
+ " @Scheduled if the Coroutine-Reactor bridge (kotlinx.coroutines.reactive) is present at runtime");
74+
+ " @Scheduled if the Coroutine-Reactor bridge (kotlinx.coroutines.reactor) is present at runtime");
7575
return true;
7676
}
7777
ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance();
@@ -165,8 +165,8 @@ public void onNext(Object o) {
165165
}
166166

167167
@Override
168-
public void onError(Throwable e) {
169-
LOGGER.warn("Unexpected error occurred in scheduled reactive task", e);
168+
public void onError(Throwable ex) {
169+
LOGGER.warn("Unexpected error occurred in scheduled reactive task", ex);
170170
latch.countDown();
171171
}
172172

@@ -178,8 +178,8 @@ public void onComplete() {
178178
try {
179179
latch.await();
180180
}
181-
catch (InterruptedException e) {
182-
throw new RuntimeException(e);
181+
catch (InterruptedException ex) {
182+
throw new RuntimeException(ex);
183183
}
184184
};
185185
}
@@ -195,8 +195,8 @@ public void onNext(Object o) {
195195
}
196196

197197
@Override
198-
public void onError(Throwable e) {
199-
LOGGER.warn("Unexpected error occurred in scheduled reactive task", e);
198+
public void onError(Throwable ex) {
199+
LOGGER.warn("Unexpected error occurred in scheduled reactive task", ex);
200200
}
201201

202202
@Override

spring-context/src/test/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupportTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,15 @@ void rejectCantAccessMethod() {
105105

106106
@Test
107107
void hasCheckpointToString() {
108-
//FIXME test checkpointing
109-
assertThat("FIXME").isEqualTo("@Scheduled 'mono()' in bean 'org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods'");
108+
ReactiveMethods target = new ReactiveMethods();
109+
Method m = ReflectionUtils.findMethod(ReactiveMethods.class, "mono");
110+
Publisher<?> p = getPublisherFor(m, target);
111+
112+
assertThat(p.getClass().getName())
113+
.as("checkpoint class")
114+
.isEqualTo("reactor.core.publisher.FluxOnAssembly");
115+
116+
assertThat(p).hasToString("checkpoint(\"@Scheduled 'mono()' in bean 'org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupportTests$ReactiveMethods'\")");
110117
}
111118

112119
static class ReactiveMethods {

spring-context/src/test/kotlin/org/springframework/scheduling/annotation/KotlinScheduledAnnotationReactiveSupportTests.kt

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ import org.junit.jupiter.api.BeforeEach
2626
import org.junit.jupiter.api.Test
2727
import org.junit.jupiter.params.ParameterizedTest
2828
import org.junit.jupiter.params.provider.ValueSource
29-
import org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupport.ReactiveTask
3029
import org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupport.getPublisherFor
3130
import org.springframework.scheduling.annotation.ScheduledAnnotationReactiveSupport.isReactive
3231
import org.springframework.util.ReflectionUtils
3332
import reactor.core.publisher.Mono
34-
import java.time.Duration
3533
import java.util.concurrent.atomic.AtomicInteger
3634
import kotlin.coroutines.Continuation
3735

@@ -122,11 +120,6 @@ class KotlinScheduledAnnotationReactiveSupportTests {
122120
Assertions.assertThatIllegalArgumentException().isThrownBy { isReactive(m) }
123121
.withMessage("Kotlin suspending functions may only be annotated with @Scheduled if declared without arguments")
124122
.withNoCause()
125-
126-
//constructor of task doesn't reject
127-
Assertions.assertThatNoException().isThrownBy {
128-
ReactiveTask(m, target!!, Duration.ZERO, Duration.ZERO, false)
129-
}
130123
}
131124

132125
@Test
@@ -137,13 +130,6 @@ class KotlinScheduledAnnotationReactiveSupportTests {
137130
Assertions.assertThatIllegalArgumentException().isThrownBy { getPublisherFor(m!!, target!!) }
138131
.withMessage("Cannot convert the @Scheduled reactive method return type to Publisher")
139132
.withNoCause()
140-
141-
//constructor of task
142-
Assertions.assertThatIllegalArgumentException().isThrownBy {
143-
ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ZERO, false)
144-
}
145-
.withMessage("Cannot convert the @Scheduled reactive method return type to Publisher")
146-
.withNoCause()
147133
}
148134

149135
@Test
@@ -155,11 +141,6 @@ class KotlinScheduledAnnotationReactiveSupportTests {
155141
Assertions.assertThatIllegalStateException().isThrownBy { mono.block() }
156142
.withMessage("expected")
157143
.withNoCause()
158-
159-
//constructor of task doesn't throw
160-
Assertions.assertThatNoException().isThrownBy {
161-
ReactiveTask(m, target!!, Duration.ZERO, Duration.ZERO, false)
162-
}
163144
}
164145

165146
@Test
@@ -171,74 +152,4 @@ class KotlinScheduledAnnotationReactiveSupportTests {
171152
mono.block()
172153
assertThat(target!!.subscription).describedAs("after subscription").hasValue(1)
173154
}
174-
175-
@Test
176-
fun hasCheckpointToString() {
177-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspending", Continuation::class.java)
178-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ZERO, false)
179-
assertThat(reactiveTask).hasToString("@Scheduled 'suspending()' in bean 'org.springframework.scheduling.annotation.KotlinScheduledAnnotationReactiveSupportTests\$SuspendingFunctions'")
180-
}
181-
182-
@Test
183-
fun cancelledEarlyPreventsSubscription() {
184-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
185-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ofSeconds(10), false)
186-
reactiveTask.cancel()
187-
reactiveTask.subscribe()
188-
assertThat(target!!.subscription).hasValue(0)
189-
}
190-
191-
@Test
192-
fun multipleSubscriptionsTracked() {
193-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
194-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ofMillis(500), false)
195-
reactiveTask.subscribe()
196-
Thread.sleep(1500)
197-
reactiveTask.cancel()
198-
assertThat(target!!.subscription).hasValueGreaterThanOrEqualTo(3)
199-
}
200-
201-
@Test
202-
@Throws(InterruptedException::class)
203-
fun noInitialDelayFixedDelay() {
204-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
205-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ofSeconds(10), false)
206-
reactiveTask.subscribe()
207-
Thread.sleep(500)
208-
reactiveTask.cancel()
209-
assertThat(target!!.subscription).hasValue(1)
210-
}
211-
212-
@Test
213-
@Throws(InterruptedException::class)
214-
fun noInitialDelayFixedRate() {
215-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
216-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ZERO, Duration.ofSeconds(10), true)
217-
reactiveTask.subscribe()
218-
Thread.sleep(500)
219-
reactiveTask.cancel()
220-
assertThat(target!!.subscription).hasValue(1)
221-
}
222-
223-
@Test
224-
@Throws(InterruptedException::class)
225-
fun initialDelayFixedDelay() {
226-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
227-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ofSeconds(10), Duration.ofMillis(500), false)
228-
reactiveTask.subscribe()
229-
Thread.sleep(500)
230-
reactiveTask.cancel()
231-
assertThat(target!!.subscription).hasValue(0)
232-
}
233-
234-
@Test
235-
@Throws(InterruptedException::class)
236-
fun initialDelayFixedRate() {
237-
val m = ReflectionUtils.findMethod(SuspendingFunctions::class.java, "suspendingTracking", Continuation::class.java)
238-
val reactiveTask = ReactiveTask(m!!, target!!, Duration.ofSeconds(10), Duration.ofMillis(500), true)
239-
reactiveTask.subscribe()
240-
Thread.sleep(500)
241-
reactiveTask.cancel()
242-
assertThat(target!!.subscription).hasValue(0)
243-
}
244155
}

0 commit comments

Comments
 (0)