forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
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 quarkusio#45523 from geoand/quarkusio#45482
Fix Mongo health checks
- Loading branch information
Showing
5 changed files
with
68 additions
and
17 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
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
52 changes: 52 additions & 0 deletions
52
...ngodb-client/deployment/src/test/java/io/quarkus/mongodb/NoConnectionHealthCheckTest.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,52 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static io.restassured.RestAssured.when; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.bson.Document; | ||
import org.hamcrest.CoreMatchers; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.MongoClientException; | ||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class NoConnectionHealthCheckTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.overrideConfigKey("quarkus.devservices.enabled", "false") | ||
.overrideConfigKey("quarkus.mongodb.connection-string", "mongodb://localhost:9999") | ||
// timeouts set to the test doesn't take too long to run | ||
.overrideConfigKey("quarkus.mongodb.connect-timeout", "2s") | ||
.overrideConfigKey("quarkus.mongodb.server-selection-timeout", "2s") | ||
.overrideConfigKey("quarkus.mongodb.read-timeout", "2s"); | ||
|
||
@Inject | ||
MongoClient mongo; | ||
|
||
@Order(1) // done to ensure the health check runs before any application code touches the database | ||
@Test | ||
public void healthCheck() { | ||
when().get("/q/health/ready") | ||
.then() | ||
.body("status", CoreMatchers.equalTo("DOWN")); | ||
} | ||
|
||
@Order(2) | ||
@Test | ||
public void tryConnection() { | ||
Assertions.assertThrows(MongoClientException.class, () -> { | ||
mongo.getDatabase("admin").runCommand(new Document("ping", 1)); | ||
}); | ||
} | ||
|
||
} |
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