-
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 #4549 from cescoffier/features/health-check-blocking
Call the health check method on the worker pool
- Loading branch information
Showing
6 changed files
with
164 additions
and
35 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
77 changes: 77 additions & 0 deletions
77
...health/deployment/src/test/java/io/quarkus/smallrye/health/test/DispatchedThreadTest.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,77 @@ | ||
package io.quarkus.smallrye.health.test; | ||
|
||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.hamcrest.Matchers.stringContainsInOrder; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
import org.eclipse.microprofile.health.Readiness; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class DispatchedThreadTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(LivenessHealthCheckCapturingThread.class, ReadinessHealthCheckCapturingThread.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); | ||
|
||
@Test | ||
public void check() { | ||
RestAssured.when().get("/health/live").then() | ||
.body("status", is("UP"), | ||
"checks.status", contains("UP"), | ||
"checks.name", contains("my-liveness-check"), | ||
"checks.data.thread[0]", stringContainsInOrder("worker"), | ||
"checks.data.thread[0]", not(stringContainsInOrder("loop")), | ||
"checks.data.request[0]", is(true)); | ||
|
||
RestAssured.when().get("/health/ready").then() | ||
.body("status", is("UP"), | ||
"checks.status", contains("UP"), | ||
"checks.name", contains("my-readiness-check"), | ||
"checks.data.thread[0]", stringContainsInOrder("worker"), | ||
"checks.data.thread[0]", not(stringContainsInOrder("loop")), | ||
"checks.data.request[0]", is(true)); | ||
} | ||
|
||
@ApplicationScoped | ||
@Liveness | ||
public static class LivenessHealthCheckCapturingThread implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.named("my-liveness-check") | ||
.up() | ||
.withData("thread", Thread.currentThread().getName()) | ||
.withData("request", Arc.container().requestContext().isActive()) | ||
.build(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@Readiness | ||
public static class ReadinessHealthCheckCapturingThread implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
return HealthCheckResponse.named("my-readiness-check") | ||
.up() | ||
.withData("thread", Thread.currentThread().getName()) | ||
.withData("request", Arc.container().requestContext().isActive()) | ||
.build(); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...e-health/runtime/src/main/java/io/quarkus/smallrye/health/runtime/RequestScopeHelper.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,25 @@ | ||
package io.quarkus.smallrye.health.runtime; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ManagedContext; | ||
|
||
public class RequestScopeHelper { | ||
|
||
/** | ||
* Activates the request scope is not yet activated. | ||
* | ||
* @return {@code true} if activated by this method, {@code false} if already activated. | ||
*/ | ||
static boolean activeRequestScope() { | ||
ManagedContext context = Arc.container().requestContext(); | ||
if (!context.isActive()) { | ||
context.activate(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private RequestScopeHelper() { | ||
// avoid direct instantiation | ||
} | ||
} |
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
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