-
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.
Unblock SmallRye Health exposed routes
- Loading branch information
Showing
14 changed files
with
149 additions
and
70 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
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
105 changes: 105 additions & 0 deletions
105
...lth/deployment/src/test/java/io/quarkus/smallrye/health/test/BlockingNonBlockingTest.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,105 @@ | ||
package io.quarkus.smallrye.health.test; | ||
|
||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.event.Observes; | ||
import jakarta.inject.Inject; | ||
|
||
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.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.runtime.StartupEvent; | ||
import io.quarkus.test.InMemoryLogHandler; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.restassured.parsing.Parser; | ||
import io.smallrye.common.annotation.Blocking; | ||
import io.smallrye.health.SmallRyeHealthReporter; | ||
|
||
public class BlockingNonBlockingTest { | ||
|
||
private static final java.util.logging.Logger rootLogger = java.util.logging.LogManager.getLogManager() | ||
.getLogger("io.vertx.core"); | ||
private static final InMemoryLogHandler inMemoryLogHandler = new InMemoryLogHandler( | ||
record -> record.getLevel().intValue() >= Level.WARNING.intValue()); | ||
|
||
@BeforeEach | ||
public void setLogHandler() { | ||
inMemoryLogHandler.getRecords().clear(); | ||
rootLogger.addHandler(inMemoryLogHandler); | ||
} | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar | ||
.addClasses(BlockingHealthCheck.class, StartupBean.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); | ||
|
||
@Test | ||
public void testRegisterHealthOnBlockingThreadStep1() { | ||
// wait for the initial startup health call to finish | ||
try { | ||
Thread.sleep(5000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
try { | ||
RestAssured.defaultParser = Parser.JSON; | ||
// repeat the call a few times since the block isn't always logged | ||
for (int i = 0; i < 3; i++) { | ||
RestAssured.when().get("/q/health").then() | ||
.body("status", is("UP"), | ||
"checks.status", contains("UP"), | ||
"checks.name", contains("blocking")); | ||
} | ||
} finally { | ||
RestAssured.reset(); | ||
} | ||
|
||
if (!inMemoryLogHandler.getRecords().isEmpty()) { | ||
LogRecord logRecord = inMemoryLogHandler.getRecords().get(0); | ||
assertEquals(Level.WARNING, logRecord.getLevel()); | ||
assertFalse(logRecord.getMessage().contains("has been blocked for"), | ||
"The blocking health check ran on eventloop thread"); | ||
} | ||
} | ||
|
||
@Liveness | ||
static final class BlockingHealthCheck implements HealthCheck { | ||
@Override | ||
public HealthCheckResponse call() { | ||
// block for 3s which is more than allowed default blocking duration of eventloop (2s) | ||
try { | ||
Thread.sleep(3000); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return HealthCheckResponse.up("blocking"); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
static final class StartupBean { | ||
|
||
@Inject | ||
SmallRyeHealthReporter smallRyeHealthReporter; | ||
|
||
@Blocking | ||
public void startup(@Observes StartupEvent event) { | ||
smallRyeHealthReporter.getHealth(); | ||
} | ||
} | ||
} |
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
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
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