Skip to content

Commit

Permalink
Merge branch '6.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
bclozel committed Dec 10, 2024
2 parents 41f8ac6 + 0c68874 commit 11db31a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.time.Instant;

import org.springframework.lang.Nullable;
import org.springframework.scheduling.SchedulingAwareRunnable;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -68,7 +70,7 @@ public String toString() {
}


private class OutcomeTrackingRunnable implements Runnable {
private class OutcomeTrackingRunnable implements SchedulingAwareRunnable {

private final Runnable runnable;

Expand All @@ -89,6 +91,23 @@ public void run() {
}
}

@Override
public boolean isLongLived() {
if (this.runnable instanceof SchedulingAwareRunnable sar) {
return sar.isLongLived();
}
return SchedulingAwareRunnable.super.isLongLived();
}

@Nullable
@Override
public String getQualifier() {
if (this.runnable instanceof SchedulingAwareRunnable sar) {
return sar.getQualifier();
}
return SchedulingAwareRunnable.super.getQualifier();
}

@Override
public String toString() {
return this.runnable.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

package org.springframework.scheduling.config;

import io.micrometer.observation.tck.TestObservationRegistry;
import org.junit.jupiter.api.Test;

import org.springframework.scheduling.SchedulingAwareRunnable;
import org.springframework.scheduling.support.ScheduledMethodRunnable;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
Expand Down Expand Up @@ -72,6 +76,18 @@ void stateShouldUpdateAfterFailingRun() {
assertThat(executionOutcome.throwable()).isInstanceOf(IllegalStateException.class);
}

@Test
void shouldDelegateToSchedulingAwareRunnable() throws Exception {
ScheduledMethodRunnable methodRunnable = new ScheduledMethodRunnable(new TestRunnable(),
TestRunnable.class.getMethod("run"), "myScheduler", TestObservationRegistry::create);
Task task = new Task(methodRunnable);

assertThat(task.getRunnable()).isInstanceOf(SchedulingAwareRunnable.class);
SchedulingAwareRunnable actual = (SchedulingAwareRunnable) task.getRunnable();
assertThat(actual.getQualifier()).isEqualTo(methodRunnable.getQualifier());
assertThat(actual.isLongLived()).isEqualTo(methodRunnable.isLongLived());
}


static class TestRunnable implements Runnable {

Expand Down

0 comments on commit 11db31a

Please sign in to comment.