diff --git a/framework/scheduled/README.adoc b/framework/scheduled/README.adoc new file mode 100644 index 0000000..4318870 --- /dev/null +++ b/framework/scheduled/README.adoc @@ -0,0 +1 @@ +Tests if `@Scheduled` is working diff --git a/framework/scheduled/build.gradle b/framework/scheduled/build.gradle new file mode 100644 index 0000000..047655a --- /dev/null +++ b/framework/scheduled/build.gradle @@ -0,0 +1,17 @@ +plugins { + id "java" + id "org.springframework.boot" + id "org.springframework.cr.smoke-test" +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter") + implementation("org.crac:crac:$cracVersion") + implementation(project(":cr-listener")) + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + appTestImplementation(project(":cr-smoke-test-support")) + appTestImplementation("org.awaitility:awaitility:4.2.0") +} diff --git a/framework/scheduled/src/appTest/java/com/example/scheduled/ScheduledApplicationAotTests.java b/framework/scheduled/src/appTest/java/com/example/scheduled/ScheduledApplicationAotTests.java new file mode 100644 index 0000000..fc1d537 --- /dev/null +++ b/framework/scheduled/src/appTest/java/com/example/scheduled/ScheduledApplicationAotTests.java @@ -0,0 +1,37 @@ +package com.example.scheduled; + +import java.time.Duration; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import org.springframework.cr.smoketest.support.assertj.AssertableOutput; +import org.springframework.cr.smoketest.support.junit.ApplicationTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@ApplicationTest +class ScheduledApplicationAotTests { + + @Test + void fixedRateShouldBeCalled(AssertableOutput output) { + Awaitility.await() + .atMost(Duration.ofSeconds(10)) + .untilAsserted(() -> assertThat(output).hasLineContaining("fixedRate()")); + } + + @Test + void fixedDelayShouldBeCalled(AssertableOutput output) { + Awaitility.await() + .atMost(Duration.ofSeconds(10)) + .untilAsserted(() -> assertThat(output).hasLineContaining("fixedDelay()")); + } + + @Test + void cronShouldBeCalled(AssertableOutput output) { + Awaitility.await() + .atMost(Duration.ofSeconds(10)) + .untilAsserted(() -> assertThat(output).hasLineContaining("cron()")); + } + +} diff --git a/framework/scheduled/src/main/java/com/example/scheduled/Bean.java b/framework/scheduled/src/main/java/com/example/scheduled/Bean.java new file mode 100644 index 0000000..31059c7 --- /dev/null +++ b/framework/scheduled/src/main/java/com/example/scheduled/Bean.java @@ -0,0 +1,24 @@ +package com.example.scheduled; + +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +@Component +class Bean { + + @Scheduled(fixedRate = 1000) + void fixedRate() { + System.out.println("fixedRate()"); + } + + @Scheduled(fixedDelay = 1000) + void fixedDelay() { + System.out.println("fixedDelay()"); + } + + @Scheduled(cron = "*/2 * * * * *") + void cron() { + System.out.println("cron()"); + } + +} diff --git a/framework/scheduled/src/main/java/com/example/scheduled/ScheduledApplication.java b/framework/scheduled/src/main/java/com/example/scheduled/ScheduledApplication.java new file mode 100644 index 0000000..476b937 --- /dev/null +++ b/framework/scheduled/src/main/java/com/example/scheduled/ScheduledApplication.java @@ -0,0 +1,16 @@ +package com.example.scheduled; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.scheduling.annotation.EnableScheduling; + +@SpringBootApplication +@EnableScheduling +public class ScheduledApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(ScheduledApplication.class, args); + Thread.currentThread().join(); + } + +} diff --git a/framework/scheduled/src/main/resources/application.properties b/framework/scheduled/src/main/resources/application.properties new file mode 100644 index 0000000..e69de29