From e865c3c305331fba5638f5c89601da5dcf0ddc29 Mon Sep 17 00:00:00 2001 From: Ladislav Thon Date: Tue, 27 Feb 2024 14:15:51 +0100 Subject: [PATCH] Fault Tolerance: add simple test for hot reload --- .../deployment/pom.xml | 10 +++++++ .../test/hotreload/HotReloadBean.java | 21 +++++++++++++++ .../test/hotreload/HotReloadRoute.java | 15 +++++++++++ .../test/hotreload/HotReloadTest.java | 26 +++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadBean.java create mode 100644 extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadRoute.java create mode 100644 extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadTest.java diff --git a/extensions/smallrye-fault-tolerance/deployment/pom.xml b/extensions/smallrye-fault-tolerance/deployment/pom.xml index 61a82927cc3f2..805401858b75c 100644 --- a/extensions/smallrye-fault-tolerance/deployment/pom.xml +++ b/extensions/smallrye-fault-tolerance/deployment/pom.xml @@ -43,6 +43,16 @@ assertj-core test + + io.rest-assured + rest-assured + test + + + io.quarkus + quarkus-vertx-http-deployment + test + diff --git a/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadBean.java b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadBean.java new file mode 100644 index 0000000000000..c0dcd2bf1e3c8 --- /dev/null +++ b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadBean.java @@ -0,0 +1,21 @@ +package io.quarkus.smallrye.faulttolerance.test.hotreload; + +import jakarta.enterprise.context.ApplicationScoped; + +import org.eclipse.microprofile.faulttolerance.Fallback; + +@ApplicationScoped +public class HotReloadBean { + @Fallback(fallbackMethod = "fallback1") + public String hello() { + throw new RuntimeException(); + } + + public String fallback1() { + return "fallback1"; + } + + public String fallback2() { + return "fallback2"; + } +} diff --git a/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadRoute.java b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadRoute.java new file mode 100644 index 0000000000000..e0f96dac48713 --- /dev/null +++ b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadRoute.java @@ -0,0 +1,15 @@ +package io.quarkus.smallrye.faulttolerance.test.hotreload; + +import jakarta.enterprise.event.Observes; +import jakarta.inject.Singleton; + +import io.vertx.ext.web.Router; + +@Singleton +public class HotReloadRoute { + public void route(@Observes Router router, HotReloadBean bean) { + router.get("/").handler(ctx -> { + ctx.response().setStatusCode(200).end(bean.hello()); + }); + } +} diff --git a/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadTest.java b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadTest.java new file mode 100644 index 0000000000000..a4c8c93109ca0 --- /dev/null +++ b/extensions/smallrye-fault-tolerance/deployment/src/test/java/io/quarkus/smallrye/faulttolerance/test/hotreload/HotReloadTest.java @@ -0,0 +1,26 @@ +package io.quarkus.smallrye.faulttolerance.test.hotreload; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.CoreMatchers.is; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.test.QuarkusDevModeTest; + +public class HotReloadTest { + @RegisterExtension + final static QuarkusDevModeTest test = new QuarkusDevModeTest() + .withApplicationRoot(jar -> jar.addClasses(HotReloadBean.class, HotReloadRoute.class)); + + @Test + public void test() { + when().get("/").then().statusCode(200).body(is("fallback1")); + + test.modifySourceFile("HotReloadBean.java", src -> { + return src.replace("fallbackMethod = \"fallback1\"", "fallbackMethod = \"fallback2\""); + }); + + when().get("/").then().statusCode(200).body(is("fallback2")); + } +}