-
Notifications
You must be signed in to change notification settings - Fork 337
feat(spring): Spring Boot 4 / Spring Framework 7 — spring-scheduling-3.1 latestDepTest #11598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 59 additions & 43 deletions
102
dd-java-agent/instrumentation/spring/spring-scheduling-3.1/gradle.lockfile
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
...va-agent/instrumentation/spring/spring-scheduling-3.1/src/test/groovy/ShedlockTest.groovy
This file was deleted.
Oops, something went wrong.
56 changes: 0 additions & 56 deletions
56
...agent/instrumentation/spring/spring-scheduling-3.1/src/test/groovy/SpringAsyncTest.groovy
This file was deleted.
Oops, something went wrong.
149 changes: 0 additions & 149 deletions
149
.../instrumentation/spring/spring-scheduling-3.1/src/test/groovy/SpringSchedulingTest.groovy
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src/test/java/AsyncErrorTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import java.util.concurrent.CompletableFuture; | ||
| import org.springframework.scheduling.annotation.Async; | ||
|
|
||
| public class AsyncErrorTask { | ||
|
|
||
| public static final String ERROR_MESSAGE = "async boom"; | ||
|
|
||
| @Async | ||
| public CompletableFuture<Integer> asyncThrow() { | ||
| throw new IllegalStateException(ERROR_MESSAGE); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...gent/instrumentation/spring/spring-scheduling-3.1/src/test/java/AsyncErrorTaskConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.EnableAsync; | ||
|
|
||
| @Configuration | ||
| @EnableAsync | ||
| public class AsyncErrorTaskConfig { | ||
|
|
||
| @Bean | ||
| AsyncErrorTask asyncErrorTask() { | ||
| return new AsyncErrorTask(); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...-agent/instrumentation/spring/spring-scheduling-3.1/src/test/java/ScheduledErrorTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.springframework.scheduling.annotation.Scheduled; | ||
|
|
||
| public class ScheduledErrorTask implements Runnable { | ||
|
|
||
| public static final String ERROR_MESSAGE = "scheduled boom"; | ||
|
|
||
| private final CountDownLatch latch = new CountDownLatch(1); | ||
|
|
||
| @Scheduled(fixedRate = 5000) | ||
| @Override | ||
| public void run() { | ||
| try { | ||
| throw new IllegalStateException(ERROR_MESSAGE); | ||
| } finally { | ||
| latch.countDown(); | ||
| } | ||
| } | ||
|
|
||
| public boolean blockUntilExecute() throws InterruptedException { | ||
| return latch.await(10, TimeUnit.SECONDS); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
.../instrumentation/spring/spring-scheduling-3.1/src/test/java/ScheduledErrorTaskConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
|
||
| @Configuration | ||
| @EnableScheduling | ||
| public class ScheduledErrorTaskConfig { | ||
|
|
||
| @Bean | ||
| public ScheduledErrorTask scheduledErrorTask() { | ||
| return new ScheduledErrorTask(); | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
dd-java-agent/instrumentation/spring/spring-scheduling-3.1/src/test/java/ShedlockTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| import datadog.trace.agent.test.AbstractInstrumentationTest; | ||
| import datadog.trace.test.util.Flaky; | ||
| import java.util.concurrent.TimeUnit; | ||
| import javax.sql.DataSource; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
| class ShedlockTest extends AbstractInstrumentationTest { | ||
|
|
||
| @Flaky("task.invocationCount() == 0") | ||
| @Test | ||
| void shouldNotDisableShedlock() throws InterruptedException { | ||
| AnnotationConfigApplicationContext context = | ||
| new AnnotationConfigApplicationContext(ShedlockConfig.class); | ||
| try { | ||
| JdbcTemplate jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class)); | ||
| jdbcTemplate.execute( | ||
| "CREATE TABLE shedlock(name VARCHAR(64) NOT NULL PRIMARY KEY, lock_until TIMESTAMP NOT NULL,\n" | ||
| + " locked_at TIMESTAMP NOT NULL, locked_by VARCHAR(255) NOT NULL);"); | ||
| ShedLockedTask task = context.getBean(ShedLockedTask.class); | ||
|
|
||
| // lock is held for more than one second: wait, then verify the task ran exactly once | ||
| task.awaitInvocation(1000, TimeUnit.MILLISECONDS); | ||
| assertEquals(1, task.invocationCount()); | ||
| } finally { | ||
| context.close(); | ||
| } | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...gent/instrumentation/spring/spring-scheduling-3.1/src/test/java/SpringAsyncErrorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import static datadog.trace.agent.test.assertions.SpanMatcher.span; | ||
| import static datadog.trace.agent.test.assertions.TagsMatcher.defaultTags; | ||
| import static datadog.trace.agent.test.assertions.TagsMatcher.error; | ||
| import static datadog.trace.agent.test.assertions.TraceMatcher.trace; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import datadog.trace.agent.test.AbstractInstrumentationTest; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
|
|
||
| /** | ||
| * Verifies that when an {@code @Async} method throws an exception, the span produced by the | ||
| * spring-scheduling instrumentation captures the error and the associated error tags. | ||
| */ | ||
| class SpringAsyncErrorTest extends AbstractInstrumentationTest { | ||
|
|
||
| @Test | ||
| void asyncMethodErrorIsCaptured() { | ||
| AnnotationConfigApplicationContext context = | ||
| new AnnotationConfigApplicationContext(AsyncErrorTaskConfig.class); | ||
| try { | ||
| AsyncErrorTask asyncErrorTask = context.getBean(AsyncErrorTask.class); | ||
|
|
||
| // The exception thrown inside the @Async method propagates back through the returned future. | ||
| assertThrows(Throwable.class, () -> asyncErrorTask.asyncThrow().join()); | ||
|
|
||
| assertTraces( | ||
| trace( | ||
| span() | ||
| .resourceName(name -> "AsyncErrorTask.asyncThrow".contentEquals(name)) | ||
| .error(true) | ||
| .tags( | ||
| defaultTags(), | ||
| error(IllegalStateException.class, AsyncErrorTask.ERROR_MESSAGE)))); | ||
| } finally { | ||
| context.close(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change
latestDepTestnow resolves Boot 4 forspring-boot-starter-data-jpa, but the same suite still inheritsspring-boot-starter-actuator:2.4.0fromtestImplementation(visible in the regenerated lockfile forlatestDepTestCompileClasspath). The latest-dep scheduling tests import and instantiateScheduledTasksEndpoint, so they are still exercising the Boot 2.4 actuator artifact mixed with Boot 4 core/autoconfigure rather than validating the Boot 4 scheduling endpoint; add alatestDepTestImplementationoverride for the actuator starter/artifact alongside the Boot 4 JPA starter.Useful? React with 👍 / 👎.