File tree 2 files changed +36
-1
lines changed
main/java/org/springframework/scheduling/config
test/java/org/springframework/scheduling/config
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 18
18
19
19
import java .time .Instant ;
20
20
21
+ import org .springframework .lang .Nullable ;
22
+ import org .springframework .scheduling .SchedulingAwareRunnable ;
21
23
import org .springframework .util .Assert ;
22
24
23
25
/**
@@ -68,7 +70,7 @@ public String toString() {
68
70
}
69
71
70
72
71
- private class OutcomeTrackingRunnable implements Runnable {
73
+ private class OutcomeTrackingRunnable implements SchedulingAwareRunnable {
72
74
73
75
private final Runnable runnable ;
74
76
@@ -89,6 +91,23 @@ public void run() {
89
91
}
90
92
}
91
93
94
+ @ Override
95
+ public boolean isLongLived () {
96
+ if (this .runnable instanceof SchedulingAwareRunnable sar ) {
97
+ return sar .isLongLived ();
98
+ }
99
+ return SchedulingAwareRunnable .super .isLongLived ();
100
+ }
101
+
102
+ @ Nullable
103
+ @ Override
104
+ public String getQualifier () {
105
+ if (this .runnable instanceof SchedulingAwareRunnable sar ) {
106
+ return sar .getQualifier ();
107
+ }
108
+ return SchedulingAwareRunnable .super .getQualifier ();
109
+ }
110
+
92
111
@ Override
93
112
public String toString () {
94
113
return this .runnable .toString ();
Original file line number Diff line number Diff line change 16
16
17
17
package org .springframework .scheduling .config ;
18
18
19
+ import io .micrometer .observation .tck .TestObservationRegistry ;
19
20
import org .junit .jupiter .api .Test ;
20
21
22
+ import org .springframework .scheduling .SchedulingAwareRunnable ;
23
+ import org .springframework .scheduling .support .ScheduledMethodRunnable ;
24
+
21
25
import static org .assertj .core .api .Assertions .assertThat ;
22
26
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
23
27
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
@@ -72,6 +76,18 @@ void stateShouldUpdateAfterFailingRun() {
72
76
assertThat (executionOutcome .throwable ()).isInstanceOf (IllegalStateException .class );
73
77
}
74
78
79
+ @ Test
80
+ void shouldDelegateToSchedulingAwareRunnable () throws Exception {
81
+ ScheduledMethodRunnable methodRunnable = new ScheduledMethodRunnable (new TestRunnable (),
82
+ TestRunnable .class .getMethod ("run" ), "myScheduler" , TestObservationRegistry ::create );
83
+ Task task = new Task (methodRunnable );
84
+
85
+ assertThat (task .getRunnable ()).isInstanceOf (SchedulingAwareRunnable .class );
86
+ SchedulingAwareRunnable actual = (SchedulingAwareRunnable ) task .getRunnable ();
87
+ assertThat (actual .getQualifier ()).isEqualTo (methodRunnable .getQualifier ());
88
+ assertThat (actual .isLongLived ()).isEqualTo (methodRunnable .isLongLived ());
89
+ }
90
+
75
91
76
92
static class TestRunnable implements Runnable {
77
93
You can’t perform that action at this time.
0 commit comments