Add scheduling sample
This commit is contained in:
1
framework/scheduled/README.adoc
Normal file
1
framework/scheduled/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
Tests if `@Scheduled` is working
|
||||
17
framework/scheduled/build.gradle
Normal file
17
framework/scheduled/build.gradle
Normal file
@@ -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")
|
||||
}
|
||||
@@ -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()"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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()");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user