-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41353 from marko-bekhta/fix/i41315-management-han…
…dler-reload Make sure that management router is reloaded
- Loading branch information
Showing
7 changed files
with
240 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ment/src/test/java/io/quarkus/vertx/http/devmode/management/LiveReloadManagementBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.vertx.http.devmode.management; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
|
||
@Named | ||
@ApplicationScoped | ||
public class LiveReloadManagementBean { | ||
|
||
private final String value = "string1"; | ||
|
||
String string() { | ||
return value; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
.../src/test/java/io/quarkus/vertx/http/devmode/management/LiveReloadManagementEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.quarkus.vertx.http.devmode.management; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
|
||
import io.quarkus.vertx.http.ManagementInterface; | ||
import io.vertx.ext.web.Router; | ||
import io.vertx.ext.web.client.HttpRequest; | ||
import io.vertx.ext.web.client.WebClient; | ||
|
||
// Case 3: import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class LiveReloadManagementEndpoint { | ||
|
||
// Case 3: @Inject | ||
// Case 3: LiveReloadManagementHandlerAsCDIBean handler; | ||
|
||
void managementRoutes(@Observes ManagementInterface mi) { | ||
Router router = mi.router(); | ||
// Case 1: testing name change: | ||
router.route("/manage-1") | ||
.produces("text/plain") | ||
.handler(rc -> rc.response().end(WebClient.class.hashCode() + "-" + HttpRequest.class.hashCode())); | ||
|
||
// Test that a new handler using some CDI bean can be loaded: | ||
// Case 2: router.route("/manage-cdi") | ||
// Case 2: .produces("text/plain") | ||
// Case 2: .handler(new LiveReloadManagementHandler()); | ||
|
||
// Case 3: router.route("/manage-bean-handler") | ||
// Case 3: .produces("text/plain") | ||
// Case 3: .handler(handler); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...t/src/test/java/io/quarkus/vertx/http/devmode/management/LiveReloadManagementHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.quarkus.vertx.http.devmode.management; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class LiveReloadManagementHandler implements Handler<RoutingContext> { | ||
|
||
@Override | ||
public void handle(RoutingContext event) { | ||
LiveReloadManagementBean managementBean = Arc.container().instance(LiveReloadManagementBean.class).get(); | ||
event.response().end(managementBean.string()); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...t/java/io/quarkus/vertx/http/devmode/management/LiveReloadManagementHandlerAsCDIBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.vertx.http.devmode.management; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Named; | ||
|
||
import io.vertx.core.Handler; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
@Named | ||
@ApplicationScoped | ||
public class LiveReloadManagementHandlerAsCDIBean implements Handler<RoutingContext> { | ||
|
||
@Override | ||
public void handle(RoutingContext event) { | ||
event.response().end("I'm a CDI bean handler."); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...ment/src/test/java/io/quarkus/vertx/http/devmode/management/LiveReloadManagementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package io.quarkus.vertx.http.devmode.management; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.awaitility.Awaitility; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class LiveReloadManagementTest { | ||
|
||
private static final String APP_PROPS = """ | ||
quarkus.class-loading.reloadable-artifacts=io.vertx:vertx-web-client | ||
quarkus.management.enabled=true | ||
"""; | ||
|
||
@RegisterExtension | ||
static final QuarkusDevModeTest test = new QuarkusDevModeTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addAsResource(new StringAsset(APP_PROPS), "application.properties") | ||
.addClasses(LiveReloadManagementEndpoint.class)); | ||
|
||
private final String managementPath = "http://localhost:9000"; | ||
|
||
@Test | ||
public void test() { | ||
// 1. We start with a single management endpoint /manage-1 | ||
String firstClassToString = RestAssured.get(managementPath + "/manage-1") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
// 2. We change the path of that endpoint, esentailly testing adding new and removing old one: | ||
test.modifySourceFile(LiveReloadManagementEndpoint.class, s -> s.replace("\"/manage-1\"", "\"/manage-2\"")); | ||
|
||
// 2.1 Wait for the reload to be done, and first make sure that the "new" endpoint is there: | ||
Awaitility.await() | ||
.atMost(5, TimeUnit.SECONDS) | ||
.untilAsserted(() -> { | ||
String secondClassToString = RestAssured.get(managementPath + "/manage-2") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
assertThat(firstClassToString).isNotEqualTo(secondClassToString); | ||
}); | ||
|
||
// 2.2 Since the above check was a success, it means that the app was reloaded and we are sure that | ||
// the /manage-1 is no longer available: | ||
RestAssured.get(managementPath + "/manage-1") | ||
.then() | ||
.statusCode(404); | ||
|
||
// 3. Now we want to add another endpoint that attempts to access a CDI bean | ||
// 4. First let's make sure that it is not there already: | ||
RestAssured.get(managementPath + "/manage-cdi").then().statusCode(404); | ||
|
||
// 5. Add/update all necessary source files: | ||
test.addSourceFile(LiveReloadManagementBean.class); | ||
test.addSourceFile(LiveReloadManagementHandler.class); | ||
test.modifySourceFile(LiveReloadManagementEndpoint.class, s -> s.replace("// Case 2: ", "")); | ||
|
||
// 6. Now wait for the app to get reloaded: | ||
Awaitility.await() | ||
.atMost(5, TimeUnit.SECONDS) | ||
.untilAsserted(() -> { | ||
String response = RestAssured.get(managementPath + "/manage-cdi") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
assertThat(response).isEqualTo("string1"); | ||
}); | ||
|
||
// 7. Update the bean used in the handler: | ||
test.modifySourceFile(LiveReloadManagementBean.class, s -> s.replace("string1", "string2")); | ||
|
||
// 8. Wait for the app to get reloaded and management endpoint should be using the reloaded CDI bean: | ||
Awaitility.await() | ||
.atMost(5, TimeUnit.SECONDS) | ||
.untilAsserted(() -> { | ||
String response = RestAssured.get(managementPath + "/manage-cdi") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
assertThat(response).isEqualTo("string2"); | ||
}); | ||
|
||
// 9. Now let's add yet another handler, this time the handler is injected as a bean. (case 3) | ||
test.addSourceFile(LiveReloadManagementHandlerAsCDIBean.class); | ||
test.modifySourceFile(LiveReloadManagementEndpoint.class, s -> s.replace("// Case 3: ", "")); | ||
|
||
// 10. Now wait for the app to get reloaded: | ||
Awaitility.await() | ||
.atMost(5, TimeUnit.SECONDS) | ||
.untilAsserted(() -> { | ||
String response = RestAssured.get(managementPath + "/manage-bean-handler") | ||
.then() | ||
.statusCode(200) | ||
.extract().body().asString(); | ||
assertThat(response).isEqualTo("I'm a CDI bean handler."); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters