From 9c76d807cb4a7f742d2d1e108f87ea1a3bc4bd3c Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Wed, 22 Nov 2023 13:10:18 +0100 Subject: [PATCH 1/2] Micronaut CRaC JDBC Guide --- guides/distribution-base/hellocontroller.adoc | 7 +- .../java/example/micronaut/Application.java | 22 +++ .../micronaut/HelloWorldController.java | 26 ++++ .../main/java/example/micronaut/Message.java | 11 ++ .../example/micronaut/MessageRepository.java | 9 ++ .../micronaut/ServerStartupEventListener.java | 21 +++ .../micronaut/CheckpointTestUtils.java | 32 +++++ .../micronaut/HelloWorldControllerTest.java | 38 +++++ guides/micronaut-crac-data-jdbc/metadata.json | 15 ++ .../micronaut-crac-data-jdbc.adoc | 133 ++++++++++++++++++ .../main/resources/application-dev.properties | 3 + .../src/main/resources/application.properties | 12 ++ .../micronaut-crac-helloworld.adoc | 8 +- .../micronaut-dynamodb.adoc | 6 +- ...c-eagerly-initialize-singletons-intro.adoc | 1 + ...on-crac-eagerly-initialize-singletons.adoc | 7 + ...nvironment-application-dev-properties.adoc | 6 + src/docs/common/snippets/common-dev-env.adoc | 2 +- .../common/snippets/common-docker-crac.adoc | 2 +- .../common/snippets/common-docker-run.adoc | 4 + .../common-helloworld-controller-intro.adoc | 6 + .../snippets/common-helloworld-curl.adoc | 11 ++ .../snippets/common-mapped-entity-intro.adoc | 1 + 23 files changed, 364 insertions(+), 19 deletions(-) create mode 100644 guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Application.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/HelloWorldController.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Message.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/MessageRepository.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/CheckpointTestUtils.java create mode 100644 guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java create mode 100644 guides/micronaut-crac-data-jdbc/metadata.json create mode 100644 guides/micronaut-crac-data-jdbc/micronaut-crac-data-jdbc.adoc create mode 100644 guides/micronaut-crac-data-jdbc/src/main/resources/application-dev.properties create mode 100644 guides/micronaut-crac-data-jdbc/src/main/resources/application.properties create mode 100644 src/docs/common/snippets/common-crac-eagerly-initialize-singletons-intro.adoc create mode 100644 src/docs/common/snippets/common-crac-eagerly-initialize-singletons.adoc create mode 100644 src/docs/common/snippets/common-default-dev-environment-application-dev-properties.adoc create mode 100644 src/docs/common/snippets/common-docker-run.adoc create mode 100644 src/docs/common/snippets/common-helloworld-controller-intro.adoc create mode 100644 src/docs/common/snippets/common-helloworld-curl.adoc create mode 100644 src/docs/common/snippets/common-mapped-entity-intro.adoc diff --git a/guides/distribution-base/hellocontroller.adoc b/guides/distribution-base/hellocontroller.adoc index 25382b3940..ccc5ca26fb 100644 --- a/guides/distribution-base/hellocontroller.adoc +++ b/guides/distribution-base/hellocontroller.adoc @@ -1,11 +1,6 @@ == Controller -Add a controller which responds with the JSON payload in the root route. - -[source,json] ----- -{"message":"Hello World"} ----- +common:helloworld-controller-intro.adoc[] source:HelloController[] diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Application.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Application.java new file mode 100644 index 0000000000..2b0e68c1bf --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Application.java @@ -0,0 +1,22 @@ +package example.micronaut; + +import io.micronaut.context.env.Environment; +import io.micronaut.core.annotation.NonNull; +import io.micronaut.context.ApplicationContextBuilder; +import io.micronaut.context.ApplicationContextConfigurer; +import io.micronaut.context.annotation.ContextConfigurer; +import io.micronaut.runtime.Micronaut; + +public class Application { + + @ContextConfigurer + public static class Configurer implements ApplicationContextConfigurer { + @Override + public void configure(@NonNull ApplicationContextBuilder builder) { + builder.eagerInitSingletons(true).defaultEnvironments(Environment.DEVELOPMENT); + } + } + public static void main(String[] args) { + Micronaut.run(Application.class, args); + } +} \ No newline at end of file diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/HelloWorldController.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/HelloWorldController.java new file mode 100644 index 0000000000..c58d5a4e32 --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/HelloWorldController.java @@ -0,0 +1,26 @@ +package example.micronaut; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; + +import java.util.Collections; +import java.util.Map; + +@Controller // <1> +class HelloWorldController { + + private final MessageRepository messageRepository; + + HelloWorldController(MessageRepository messageRepository) { // <2> + this.messageRepository = messageRepository; + } + + @Get // <3> + Map index() { + return messageRepository.findAll() + .stream().map(entity -> + Collections.singletonMap("message", entity.message())) + .findFirst() + .orElseGet(Collections::emptyMap); + } +} diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Message.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Message.java new file mode 100644 index 0000000000..1806e97d3d --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/Message.java @@ -0,0 +1,11 @@ +package example.micronaut; + +import io.micronaut.core.annotation.Nullable; +import io.micronaut.data.annotation.GeneratedValue; +import io.micronaut.data.annotation.Id; +import io.micronaut.data.annotation.MappedEntity; + +@MappedEntity // <1> +public record Message(@Nullable @Id @GeneratedValue Long id, // <2> + String message) { +} diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/MessageRepository.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/MessageRepository.java new file mode 100644 index 0000000000..573efe642b --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/MessageRepository.java @@ -0,0 +1,9 @@ +package example.micronaut; + +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.CrudRepository; + +@JdbcRepository(dialect = Dialect.POSTGRES) // <1> +public interface MessageRepository extends CrudRepository { // <2> +} diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java new file mode 100644 index 0000000000..8eb04d886a --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java @@ -0,0 +1,21 @@ +package example.micronaut; + +import io.micronaut.context.event.ApplicationEventListener; +import io.micronaut.runtime.server.event.ServerStartupEvent; +import jakarta.inject.Singleton; + +@Singleton // <1> +public class ServerStartupEventListener implements ApplicationEventListener { // <2> + private final MessageRepository messageRepository; + + public ServerStartupEventListener(MessageRepository messageRepository) { // <3> + this.messageRepository = messageRepository; + } + + @Override + public void onApplicationEvent(ServerStartupEvent event) { // <4> + if (messageRepository.count() == 0) { + messageRepository.save(new Message(null, "Hello World")); + } + } +} diff --git a/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/CheckpointTestUtils.java b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/CheckpointTestUtils.java new file mode 100644 index 0000000000..57f86d0b98 --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/CheckpointTestUtils.java @@ -0,0 +1,32 @@ +package example.micronaut; + +import io.micronaut.context.ApplicationContext; +import io.micronaut.crac.test.CheckpointSimulator; +import io.micronaut.http.client.BlockingHttpClient; +import io.micronaut.http.client.HttpClient; +import io.micronaut.runtime.server.EmbeddedServer; +import java.util.function.Function; + +public class CheckpointTestUtils { + + public static void test(Function testScenario) { + try (EmbeddedServer server = ApplicationContext.run(EmbeddedServer.class)) { + CheckpointSimulator checkpointSimulator = + server.getApplicationContext().getBean(CheckpointSimulator.class); + testApp(server, testScenario); + + checkpointSimulator.runBeforeCheckpoint(); + server.stop(); + checkpointSimulator.runAfterRestore(); + server.start(); + testApp(server, testScenario); + } + } + + public static Object testApp(EmbeddedServer embeddedServer, Function clientConsumer) { + try (HttpClient httpClient = embeddedServer.getApplicationContext().createBean(HttpClient.class, embeddedServer.getURL())) { + BlockingHttpClient client = httpClient.toBlocking(); + return clientConsumer.apply(client); + } + } +} diff --git a/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java new file mode 100644 index 0000000000..6508ed57dd --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java @@ -0,0 +1,38 @@ +package example.micronaut; + +import io.micronaut.context.ApplicationContext; +import io.micronaut.context.env.Environment; +import io.micronaut.core.type.Argument; +import io.micronaut.crac.test.CheckpointSimulator; +import io.micronaut.http.HttpRequest; +import io.micronaut.http.HttpResponse; +import io.micronaut.http.HttpStatus; +import io.micronaut.http.client.BlockingHttpClient; +import io.micronaut.http.client.HttpClient; +import io.micronaut.runtime.server.EmbeddedServer; +import org.junit.jupiter.api.Test; + +import java.util.Collections; +import java.util.Map; +import java.util.Optional; +import java.util.function.Consumer; +import java.util.function.Function; + +import static org.junit.jupiter.api.Assertions.*; + +class HelloWorldControllerTest { + + @Test + void emulateCheckpoint() { + CheckpointTestUtils.test(this::testHelloWorld); + } + + private Void testHelloWorld(BlockingHttpClient client) { + HttpResponse> response = client.exchange(HttpRequest.GET("/"), Argument.mapOf(String.class, String.class)); + assertEquals(HttpStatus.OK, response.getStatus()); + Optional> bodyOptional = response.getBody(); + assertTrue(bodyOptional.isPresent()); + assertEquals(Collections.singletonMap("message", "Hello World"), bodyOptional.get()); + return null; + } +} \ No newline at end of file diff --git a/guides/micronaut-crac-data-jdbc/metadata.json b/guides/micronaut-crac-data-jdbc/metadata.json new file mode 100644 index 0000000000..d21dfd9309 --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/metadata.json @@ -0,0 +1,15 @@ +{ + "title": "Micronaut CRaC and Micronaut Data JDBC", + "intro": "Learn how to use CRaC with Micronaut Data JDBC and Hikari", + "authors": ["Sergio del Amo"], + "tags": ["endpoint-info"], + "categories": ["CRaC"], + "publicationDate": "2023-11-22", + "languages": ["java"], + "apps": [ + { + "name": "default", + "features": ["crac", "data-jdbc", "postgres"] + } + ] +} diff --git a/guides/micronaut-crac-data-jdbc/micronaut-crac-data-jdbc.adoc b/guides/micronaut-crac-data-jdbc/micronaut-crac-data-jdbc.adoc new file mode 100644 index 0000000000..f12c3d439b --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/micronaut-crac-data-jdbc.adoc @@ -0,0 +1,133 @@ +common:header-top.adoc[] + +common:crac.adoc[] + +common:requirements-testcontainers.adoc[] + +common:gettingStarted.adoc[] + +common:completesolution.adoc[] + +common:create-app-features.adoc[] + +common:data-jdbc-postgresql-configuration.adoc[] + +:leveloffset: +1 + +== Micronaut CRaC Dependency + +Add the Micronaut CRaC dependency: + +dependency:micronaut-crac[groupId=io.micronaut.crac] + +It has a transitive dependency to https://github.com/CRaC/org.crac[org.crac:crac]. + +== Configuration Allow Pool Suspension + +To use Hikari Datasources with Micronaut CRaC you need to allow suspension. + +resource:application.properties[tag=allow-pool-suspension] + +When a checkpoint is taken, the pool is suspended and the connections are closed. When the checkpoint is restored, the pool is resumed and the connections are re-established. + +== Entity + +common:mapped-entity-intro.adoc[] + +source:Message[] + +callout:mapped-entity[1] +callout:mapped-entity-id[2] + +== Repository + +common:jdbc-repository-intro.adoc[] + +source:MessageRepository[] + +callout:jdbcrepository[1] +callout:crudrepository[2] + +== ServerStartupEvent Event Listener + +Save a message on startup: + +source:ServerStartupEventListener[] +callout:singleton[1] +callout:application-event-listener-startup-event[2] +callout:constructor-di[number=3,arg0=MessageRepository] +callout:server-startup-event.adoc[4] + +== Controller + +common:helloworld-controller-intro.adoc[] + +Create a controller that uses the repository: + +source:HelloWorldController[] + +callout:controller[number=1,arg0=/] +callout:constructor-di[number=2,arg0=MessageRepository] +callout:get-generic[3] + +== Test + +To simplify testing, we create a utility class that allows you to run a test scenario before and after the checkpoint. + +test:CheckpointTestUtils[] + +You could write a test for the previous controller: + +test:HelloWorldControllerTest[] + +:leveloffset: -1 + +== Testing + +:leveloffset: +1 + +common:test-resources-postgres.adoc[] + +common:testApp.adoc[] + +:leveloffset: -1 + +== Running the Application + +:leveloffset: +1 + +== Run PostgreSQL with Docker + +common:run-postgres-with-docker.adoc[] + +common:dev-env.adoc[] + +common:crac-eagerly-initialize-singletons-intro.adoc[] + +common:default-dev-environment-application-dev-properties.adoc[] + +The above configuration allows the application, which we will run as a Docker image, to connect to the PostgreSQL instance, which we run as a Docker image as well. + +common:docker-crac.adoc[] + +== Run the Application with Docker + +The Docker Image entry point is the CRaC checkpoint, you can run it with: + +common:docker-run.adoc[] + +common:helloworld-curl.adoc[] + +:leveloffset: -1 + +== Conclusion + +As you have seen in this guide, you can use Micronaut CRaC today with Netty runtime, Micronaut Data JDBC, and Hikari connection pool. +You don't need to write any custom code. + +common:next.adoc[] + +Learn more about: + +* https://micronaut-projects.github.io/micronaut-crac/latest/guide/[Micronaut CRaC (Coordinated Restore at checkpoint)] +* https://docs.azul.com/core/crac/crac-introduction[CRaC Introduction] \ No newline at end of file diff --git a/guides/micronaut-crac-data-jdbc/src/main/resources/application-dev.properties b/guides/micronaut-crac-data-jdbc/src/main/resources/application-dev.properties new file mode 100644 index 0000000000..966566c8e0 --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/src/main/resources/application-dev.properties @@ -0,0 +1,3 @@ +datasources.default.username=dbuser +datasources.default.password=theSecretPassword +datasources.default.url=jdbc:postgresql://host.docker.internal:5432/postgres \ No newline at end of file diff --git a/guides/micronaut-crac-data-jdbc/src/main/resources/application.properties b/guides/micronaut-crac-data-jdbc/src/main/resources/application.properties new file mode 100644 index 0000000000..08fd089589 --- /dev/null +++ b/guides/micronaut-crac-data-jdbc/src/main/resources/application.properties @@ -0,0 +1,12 @@ +micronaut.application.name=micronautguide +#tag::allow-pool-suspension[] +datasources.default.allow-pool-suspension=true +#end::allow-pool-suspension[] +#tag::datasource[] +# <1> +datasources.default.db-type=postgres +datasources.default.schema-generate=CREATE_DROP +# <2> +datasources.default.dialect=POSTGRES +datasources.default.driver-class-name=org.postgresql.Driver +#end::datasource[] \ No newline at end of file diff --git a/guides/micronaut-crac-helloworld/micronaut-crac-helloworld.adoc b/guides/micronaut-crac-helloworld/micronaut-crac-helloworld.adoc index 2f0f110161..c254f310ae 100644 --- a/guides/micronaut-crac-helloworld/micronaut-crac-helloworld.adoc +++ b/guides/micronaut-crac-helloworld/micronaut-crac-helloworld.adoc @@ -79,13 +79,9 @@ The following test verifies the `TimeController` is offloaded prior to a checkpo test:TimeControllerTest[] -== Eagerly initialize Singletons +common-crac-eagerly-initialize-singletons.adoc[] -When you use CRaC, you should use https://docs.micronaut.io/latest/guide/#eagerInit[eager initialization] to ensure the application is fully loaded before the checkpoint is taken. - -Modify your application class: - -source:Application[] +== Test Eager Initializion of Singletons You can test eager initialization: diff --git a/guides/micronaut-dynamodb/micronaut-dynamodb.adoc b/guides/micronaut-dynamodb/micronaut-dynamodb.adoc index 250aaed3aa..8f226ab622 100644 --- a/guides/micronaut-dynamodb/micronaut-dynamodb.adoc +++ b/guides/micronaut-dynamodb/micronaut-dynamodb.adoc @@ -134,11 +134,7 @@ resource:application.yml[tag=testresources] This will start DynamoDB in a container via TestContainers, and inject the properties into your application. -==== Dev default environment - -Modify `Application` to use `dev` as a https://docs.micronaut.io/latest/guide/index.html#_default_environment[default environment]. - -source:Application[] +common:dev-env.adoc[] ==== Dev Bootstrap diff --git a/src/docs/common/snippets/common-crac-eagerly-initialize-singletons-intro.adoc b/src/docs/common/snippets/common-crac-eagerly-initialize-singletons-intro.adoc new file mode 100644 index 0000000000..c664480e1e --- /dev/null +++ b/src/docs/common/snippets/common-crac-eagerly-initialize-singletons-intro.adoc @@ -0,0 +1 @@ +When you use CRaC, you should use https://docs.micronaut.io/latest/guide/#eagerInit[eager initialization] to ensure the application is fully loaded before the checkpoint is taken. diff --git a/src/docs/common/snippets/common-crac-eagerly-initialize-singletons.adoc b/src/docs/common/snippets/common-crac-eagerly-initialize-singletons.adoc new file mode 100644 index 0000000000..b3ee514c0f --- /dev/null +++ b/src/docs/common/snippets/common-crac-eagerly-initialize-singletons.adoc @@ -0,0 +1,7 @@ +== Eagerly initialize Singletons + +common-crac-eagerly-initialize-singletons-intro.adoc[] + +Modify your application class: + +source:Application[] \ No newline at end of file diff --git a/src/docs/common/snippets/common-default-dev-environment-application-dev-properties.adoc b/src/docs/common/snippets/common-default-dev-environment-application-dev-properties.adoc new file mode 100644 index 0000000000..1835685b99 --- /dev/null +++ b/src/docs/common/snippets/common-default-dev-environment-application-dev-properties.adoc @@ -0,0 +1,6 @@ +== Development Environment Configuration + +Create `src/main/resources/application-dev.properties`. +The Micronaut framework applies this configuration file only for the `dev` environment. + +resource:application-dev.properties[] \ No newline at end of file diff --git a/src/docs/common/snippets/common-dev-env.adoc b/src/docs/common/snippets/common-dev-env.adoc index 96d972064e..09cd94d0ee 100644 --- a/src/docs/common/snippets/common-dev-env.adoc +++ b/src/docs/common/snippets/common-dev-env.adoc @@ -1,4 +1,4 @@ -=== Dev default environment +== `Dev` Default environment Modify `Application` to use `dev` as a https://docs.micronaut.io/latest/guide/index.html#_default_environment[default environment]. diff --git a/src/docs/common/snippets/common-docker-crac.adoc b/src/docs/common/snippets/common-docker-crac.adoc index 47e646b0e2..77cb6a95b0 100644 --- a/src/docs/common/snippets/common-docker-crac.adoc +++ b/src/docs/common/snippets/common-docker-crac.adoc @@ -11,7 +11,7 @@ Generate a Docker Image containing a CRaC enabled JDK and a pre-warmed, checkpoi ... Successfully built ba78619b8d86 -Successfully tagged micronautguide:latest +Successfully tagged default:latest Created image with ID 'ba78619b8d86'. BUILD SUCCESSFUL in 1m 41s diff --git a/src/docs/common/snippets/common-docker-run.adoc b/src/docs/common/snippets/common-docker-run.adoc new file mode 100644 index 0000000000..d42b7fd4dc --- /dev/null +++ b/src/docs/common/snippets/common-docker-run.adoc @@ -0,0 +1,4 @@ +[source,bash] +---- +docker run -d --rm -p 8080:8080 --privileged default:latest +---- \ No newline at end of file diff --git a/src/docs/common/snippets/common-helloworld-controller-intro.adoc b/src/docs/common/snippets/common-helloworld-controller-intro.adoc new file mode 100644 index 0000000000..67a83c3884 --- /dev/null +++ b/src/docs/common/snippets/common-helloworld-controller-intro.adoc @@ -0,0 +1,6 @@ +Add a controller which responds with the JSON payload in the root route. + +[source,json] +---- +{"message":"Hello World"} +---- \ No newline at end of file diff --git a/src/docs/common/snippets/common-helloworld-curl.adoc b/src/docs/common/snippets/common-helloworld-curl.adoc new file mode 100644 index 0000000000..9896774901 --- /dev/null +++ b/src/docs/common/snippets/common-helloworld-curl.adoc @@ -0,0 +1,11 @@ +You can execute the endpoint: + +[source, bash] +---- +curl localhost:8080 +---- + +[source] +---- +{"message": "Hello World"} +---- \ No newline at end of file diff --git a/src/docs/common/snippets/common-mapped-entity-intro.adoc b/src/docs/common/snippets/common-mapped-entity-intro.adoc new file mode 100644 index 0000000000..800495a27b --- /dev/null +++ b/src/docs/common/snippets/common-mapped-entity-intro.adoc @@ -0,0 +1 @@ +Define a class annotated with https://micronaut-projects.github.io/micronaut-data/latest/api/io/micronaut/data/annotation/MappedEntity.html[@MappedEntity]. Instances of the class represent a single row retrieved from the database in a query. \ No newline at end of file From ae1aa64b8dc5baa7e37a49db18438292cbce3f65 Mon Sep 17 00:00:00 2001 From: Tim Yates Date: Wed, 22 Nov 2023 13:17:40 +0000 Subject: [PATCH 2/2] Whitespace and imports --- .../example/micronaut/ServerStartupEventListener.java | 1 + .../example/micronaut/HelloWorldControllerTest.java | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java index 8eb04d886a..e5c520aa25 100644 --- a/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java +++ b/guides/micronaut-crac-data-jdbc/java/src/main/java/example/micronaut/ServerStartupEventListener.java @@ -6,6 +6,7 @@ @Singleton // <1> public class ServerStartupEventListener implements ApplicationEventListener { // <2> + private final MessageRepository messageRepository; public ServerStartupEventListener(MessageRepository messageRepository) { // <3> diff --git a/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java index 6508ed57dd..e6da1e4079 100644 --- a/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java +++ b/guides/micronaut-crac-data-jdbc/java/src/test/java/example/micronaut/HelloWorldControllerTest.java @@ -1,24 +1,18 @@ package example.micronaut; -import io.micronaut.context.ApplicationContext; -import io.micronaut.context.env.Environment; import io.micronaut.core.type.Argument; -import io.micronaut.crac.test.CheckpointSimulator; import io.micronaut.http.HttpRequest; import io.micronaut.http.HttpResponse; import io.micronaut.http.HttpStatus; import io.micronaut.http.client.BlockingHttpClient; -import io.micronaut.http.client.HttpClient; -import io.micronaut.runtime.server.EmbeddedServer; import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.Map; import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Function; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; class HelloWorldControllerTest {