-
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 #41815 from xstefank/context-health-mdc-i41746
Create new vertx context for blocking health checks
- Loading branch information
Showing
3 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
.../test/java/io/quarkus/smallrye/health/test/BlockingChecksVertxContextDuplicationTest.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,65 @@ | ||
package io.quarkus.smallrye.health.test; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.eclipse.microprofile.health.HealthCheck; | ||
import org.eclipse.microprofile.health.HealthCheckResponse; | ||
import org.eclipse.microprofile.health.Liveness; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.junit.jupiter.api.Assertions; | ||
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.vertx.core.Context; | ||
import io.vertx.core.Vertx; | ||
|
||
class BlockingChecksVertxContextDuplicationTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(ContextCaptureCheck1.class, ContextCaptureCheck2.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); | ||
|
||
@Test | ||
void testBlockingChecksPropagateVertxContext() { | ||
try { | ||
RestAssured.defaultParser = Parser.JSON; | ||
RestAssured.when().get("/q/health").then() | ||
.body("status", is("UP"), | ||
"checks.size()", is(2)); | ||
|
||
Assertions.assertNotEquals(ContextCaptureCheck1.capturedContext, ContextCaptureCheck2.capturedContext, | ||
"Expected different contexts to be propagated into different blocking health checks"); | ||
} finally { | ||
RestAssured.reset(); | ||
} | ||
} | ||
|
||
@Liveness | ||
public static class ContextCaptureCheck1 implements HealthCheck { | ||
|
||
public static Context capturedContext = null; | ||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
capturedContext = Vertx.currentContext(); | ||
return HealthCheckResponse.up("ContextCaptureCheck1"); | ||
} | ||
} | ||
|
||
@Liveness | ||
public static class ContextCaptureCheck2 implements HealthCheck { | ||
|
||
public static Context capturedContext = null; | ||
|
||
@Override | ||
public HealthCheckResponse call() { | ||
capturedContext = Vertx.currentContext(); | ||
return HealthCheckResponse.up("ContextCaptureCheck2"); | ||
} | ||
} | ||
} |
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