Skip to content

Commit

Permalink
Merge pull request quarkusio#39030 from Ladicek/fault-tolerance-hot-r…
Browse files Browse the repository at this point in the history
…eload-test

Fault Tolerance: add simple test for hot reload
  • Loading branch information
geoand authored Feb 27, 2024
2 parents c4e0aca + e865c3c commit 82c4d96
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions extensions/smallrye-fault-tolerance/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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());
});
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}

0 comments on commit 82c4d96

Please sign in to comment.