-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #12073 from xstefank/well-endpoint
Add wellness health handling
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
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
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
48 changes: 48 additions & 0 deletions
48
...lth/deployment/src/test/java/io/quarkus/smallrye/health/test/WellnessHealthCheckTest.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,48 @@ | ||
package io.quarkus.smallrye.health.test; | ||
|
||
import static io.restassured.RestAssured.when; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.parsing.Parser; | ||
import io.smallrye.health.api.Wellness; | ||
|
||
public class WellnessHealthCheckTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(WellnessHC.class)); | ||
|
||
@Test | ||
public void testWellness() { | ||
try { | ||
RestAssured.defaultParser = Parser.JSON; | ||
when().get("/health/well").then() | ||
.body("status", is("UP"), | ||
"checks.status", contains("UP"), | ||
"checks.name", contains(WellnessHC.class.getName())); | ||
} finally { | ||
RestAssured.reset(); | ||
} | ||
} | ||
|
||
@Wellness | ||
static class WellnessHC implements HealthCheck { | ||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.up(WellnessHC.class.getName()); | ||
} | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...lth/runtime/src/main/java/io/quarkus/smallrye/health/runtime/SmallRyeWellnessHandler.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,13 @@ | ||
package io.quarkus.smallrye.health.runtime; | ||
|
||
import io.smallrye.health.SmallRyeHealth; | ||
import io.smallrye.health.SmallRyeHealthReporter; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class SmallRyeWellnessHandler extends SmallRyeHealthHandlerBase { | ||
|
||
@Override | ||
protected SmallRyeHealth getHealth(SmallRyeHealthReporter reporter, RoutingContext routingContext) { | ||
return reporter.getWellness(); | ||
} | ||
} |