2024-06-10 11:45:24 +02:00
2024-05-20 14:44:54 +02:00
2023-12-12 14:07:19 +01:00
2023-11-24 15:39:37 +01:00
2024-06-10 11:45:24 +02:00
2024-05-23 16:13:39 +02:00
2023-12-12 11:28:55 +01:00
2023-09-04 10:28:29 +02:00
2024-05-23 16:23:16 +02:00
2023-06-27 12:48:52 +02:00
2024-05-23 16:13:39 +02:00
2024-05-23 16:13:39 +02:00
2023-06-27 12:48:52 +02:00
2024-06-10 11:42:59 +02:00
2024-01-24 10:20:49 +01:00

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
= Spring Lifecycle Smoke Tests

image:https://img.shields.io/badge/3.2.x-status-blue["Status", link="https://github.com/spring-projects/spring-lifecycle-smoke-tests/blob/main/STATUS.adoc"]

A suite of tests and documentation for Spring Boot applications using a custom lifecycle to perform a training run with
https://docs.spring.io/spring-framework/reference/integration/cds.html[CDS] or
https://docs.spring.io/spring-framework/reference/integration/checkpoint-restore.html[JVM Checkpoint Restore].

== Training run configuration

The training run of your application may require custom configuration, to prevent early database interaction for example,
see related documentation depending on the dependencies used:

- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-jpa/README.adoc[Spring Data JPA]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-jdbc/README.adoc[Spring Data JDBC]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-r2dbc/README.adoc[Spring Data R2DBC]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-mongodb/README.adoc[Spring Data MongoDB]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-mongodb-reactive/README.adoc[Spring Data MongoDB Reactive]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/data/data-redis/README.adoc[Spring Data Redis]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/batch/batch/README.adoc[Spring Batch]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/boot/flyway/README.adoc[Flyway]
- https://github.com/sdeleuze/spring-lifecycle-smoke-tests/blob/main/boot/liquibase/README.adoc[Liquibase]

== Tests

There are two types of tests: unit tests and application tests.

Unit tests can be run using the `test` task.

The `appTest` task tests the application running on the JVM. The `checkpointRestoreAppTest` (also available with the shorter `cRAT` task name) task tests the application running on the JVM after a checkpoint/restore.

=== Prerequisites

==== Linux or Windows via WSL2

- Docker to run external services such as database servers.
- For CRaC, a CRaC enabled JDK such as https://bell-sw.com/pages/downloads/?package=jdk-crac[the one provided by Bellsoft].

> NOTE: If using SDKMan then run `sdk env install`.

==== Mac

- https://www.docker.com/products/docker-desktop/[Docker Desktop] (Colima + QEMU does not support CRaC JDK in a reliable way)
- Use `./run-dev-container.sh` before running Gradle commands.

=== Contributing

Please read and follow the link:CONTRIBUTING.adoc[contributing guide].

=== How to

==== Run all of a project's smoke tests

[source,]
----
./gradlew :<name of the group>:<name of the smoke test>:build
----

for example

[source,]
----
./gradlew :framework:webmvc-tomcat:build
----

==== Run a specific type of tests for a project

[source,]
----
./gradlew :<name of the group>:<name of the smoke test>:<test task name>
----

Valid test task names are:

1. `appTest`  tests the application running on the JVM
2. `checkpointRestoreAppTest` (also available with the shorter `cRAT` task name)  tests the application running on the JVM after a checkpoint/restore
3. `test`  executes the unit tests on the JVM

for example

[source,]
----
./gradlew :framework:webmvc-tomcat:appTest
----

==== Add a new smoke test

1. Create a new directory for your smoke test in the appropriate group
2. Include the directory in `settings.gradle` (new groups only)
3. Run `./gradlew updateInfrastructure` to add the smoke test to the status page and CI pipeline

==== Test against local changes

===== Your project uses Gradle

[source,]
----
./gradlew :<name of the group>:<name of the smoke test>:build --include-build /path/to/your/project
----

Gradle https://docs.gradle.org/current/userguide/composite_builds.html#command_line_composite[will then substitute the dependency] with your provided version.

_Hint: You can use `--include-build` multiple times._

===== Your project uses Maven or --include-build does not work

First, install the snapshots into your local Maven cache.
You can now consume those snapshots using `-PfromMavenLocal` which takes an
optional comma-separated list of group IDs:

[source,]
----
./gradlew :framework:webmvc-tomcat:build -PfromMavenLocal=org.springframework
----

The preceding example will run the `webmvc-tomcat` smoke test, resolving Spring Framework from your local Maven cache.

You can also just specify:
[source,]
----
./gradlew :framework:webmvc-tomcat:build -PfromMavenLocal
----

Here all the dependencies will be resolved from your local Maven cache.

==== Override a dependency version

As the test doesn't use the Spring Dependency Management Plugin, you can't use the `ext['...'] = '...'` method.

Instead, use https://docs.gradle.org/current/userguide/dependency_constraints.html[Gradle dependency constraints].
Say, for example, you want to update the version of Spring Session JDBC to `3.0.0-SNAPSHOT`:

[source,]
----
dependencies {
    // ...
    constraints {
        implementation('org.springframework.session:spring-session-jdbc:3.0.0-SNAPSHOT')
    }
}
----

This works for direct and transitive dependencies.

==== Use a custom event to trigger the checkpoint

By default, `org.springframework.boot.context.event.ApplicationReadyEvent` is used to trigger the checkpoint when the
application is ready. It is possible to specify another event to trigger the checkpoint with the following Gradle
configuration:

[source,]
----
crSmokeTest {
    checkpointEvent = "com.example.MyCustomEvent"
}
----
Description
No description provided
Readme 655 KiB
Languages
Java 97.2%
Shell 2.6%
Dockerfile 0.2%