File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
main/java/org/springframework/scheduling/config
test/java/org/springframework/scheduling/config Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 1818
1919import java .time .Instant ;
2020
21+ import org .springframework .lang .Nullable ;
22+ import org .springframework .scheduling .SchedulingAwareRunnable ;
2123import org .springframework .util .Assert ;
2224
2325/**
@@ -68,7 +70,7 @@ public String toString() {
6870 }
6971
7072
71- private class OutcomeTrackingRunnable implements Runnable {
73+ private class OutcomeTrackingRunnable implements SchedulingAwareRunnable {
7274
7375 private final Runnable runnable ;
7476
@@ -89,6 +91,23 @@ public void run() {
8991 }
9092 }
9193
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+
92111 @ Override
93112 public String toString () {
94113 return this .runnable .toString ();
Original file line number Diff line number Diff line change 1616
1717package org .springframework .scheduling .config ;
1818
19+ import io .micrometer .observation .tck .TestObservationRegistry ;
1920import org .junit .jupiter .api .Test ;
2021
22+ import org .springframework .scheduling .SchedulingAwareRunnable ;
23+ import org .springframework .scheduling .support .ScheduledMethodRunnable ;
24+
2125import static org .assertj .core .api .Assertions .assertThat ;
2226import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
2327import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
@@ -72,6 +76,18 @@ void stateShouldUpdateAfterFailingRun() {
7276 assertThat (executionOutcome .throwable ()).isInstanceOf (IllegalStateException .class );
7377 }
7478
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+
7591
7692 static class TestRunnable implements Runnable {
7793
You can’t perform that action at this time.
0 commit comments