Reflect grouping in directory structure
This commit is contained in:
1
cloud/cloud-task/README.adoc
Normal file
1
cloud/cloud-task/README.adoc
Normal file
@@ -0,0 +1 @@
|
||||
Tests if Spring Cloud Task works
|
||||
27
cloud/cloud-task/build.gradle
Normal file
27
cloud/cloud-task/build.gradle
Normal file
@@ -0,0 +1,27 @@
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.springframework.boot'
|
||||
id 'org.springframework.aot.smoke-test'
|
||||
id 'org.graalvm.buildtools.native'
|
||||
}
|
||||
|
||||
ext {
|
||||
set('springCloudVersion', "2022.0.0-SNAPSHOT")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
|
||||
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"))
|
||||
implementation("org.springframework.boot:spring-boot-starter")
|
||||
implementation("org.springframework.cloud:spring-cloud-starter-task")
|
||||
runtimeOnly("com.h2database:h2")
|
||||
|
||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||
|
||||
appTestImplementation(project(":aot-smoke-test-support"))
|
||||
appTestImplementation("org.awaitility:awaitility:4.2.0")
|
||||
}
|
||||
|
||||
aotSmokeTest {
|
||||
webApplication = true
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.cloud.task;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.smoketest.support.assertj.AssertableOutput;
|
||||
import org.springframework.aot.smoketest.support.junit.ApplicationTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ApplicationTest
|
||||
class CloudTaskApplicationAotTests {
|
||||
|
||||
@Test
|
||||
void expectedLoggingIsProduced(AssertableOutput output) {
|
||||
Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted(() -> {
|
||||
assertThat(output).hasSingleLineContaining("Before task: cloudtask").hasSingleLineContaining("Task ran!")
|
||||
.hasSingleLineContaining("After task: cloudtask");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.cloud.task;
|
||||
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.task.configuration.EnableTask;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTask
|
||||
public class CloudTaskApplication {
|
||||
|
||||
@Bean
|
||||
public ApplicationRunner successfulTask() {
|
||||
return args -> System.out.println("Task ran!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
SpringApplication.run(CloudTaskApplication.class, args);
|
||||
Thread.currentThread().join(); // To be able to measure memory consumption
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.example.cloud.task;
|
||||
|
||||
import org.springframework.cloud.task.listener.annotation.AfterTask;
|
||||
import org.springframework.cloud.task.listener.annotation.BeforeTask;
|
||||
import org.springframework.cloud.task.listener.annotation.FailedTask;
|
||||
import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Listener {
|
||||
|
||||
@BeforeTask
|
||||
public void beforeTask(TaskExecution taskExecution) {
|
||||
System.out.printf("Before task: %s%n", taskExecution.getTaskName());
|
||||
}
|
||||
|
||||
@AfterTask
|
||||
public void afterTask(TaskExecution taskExecution) {
|
||||
System.out.printf("After task: %s%n", taskExecution.getTaskName());
|
||||
}
|
||||
|
||||
@FailedTask
|
||||
public void failedTask(TaskExecution taskExecution, Throwable throwable) {
|
||||
System.out.printf("Failed task: %s: %s%n", taskExecution.getTaskName(), throwable);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
logging.level.org.springframework.cloud.task=DEBUG
|
||||
spring.application.name=cloudtask
|
||||
Reference in New Issue
Block a user