-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update HibernateModule to allow skipping Hibernate and JDBC
HealthChecks. GitOrigin-RevId: 622685271e477b7a9dceecaf9644d8aee622c051
- Loading branch information
1 parent
d22212a
commit 2e2ea45
Showing
4 changed files
with
98 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
49 changes: 49 additions & 0 deletions
49
misk-hibernate/src/test/kotlin/misk/hibernate/DisabledHealthCheckTest.kt
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,49 @@ | ||
package misk.hibernate | ||
|
||
import com.google.inject.Provider | ||
import jakarta.inject.Inject | ||
import misk.healthchecks.HealthCheck | ||
import misk.jdbc.SchemaMigratorService | ||
import misk.testing.MiskTest | ||
import misk.testing.MiskTestModule | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import wisp.logging.getLogger | ||
import wisp.time.FakeClock | ||
import java.sql.Timestamp | ||
|
||
@MiskTest(startService = true) | ||
class DisabledHealthCheckTest { | ||
@MiskTestModule | ||
val module = MoviesTestModule(installHealthChecks = false) | ||
|
||
@Inject @Movies private lateinit var sessionFactoryService: Provider<SessionFactoryService> | ||
@Inject private lateinit var fakeClock: FakeClock | ||
@Inject private lateinit var healthChecks: List<HealthCheck> | ||
|
||
@Test | ||
fun isNotInjected() { | ||
assertThat(healthChecks).noneMatch { it is HibernateHealthCheck } | ||
assertThat(healthChecks).noneMatch { it is SchemaMigratorService } | ||
} | ||
|
||
@Test | ||
fun isStillConnectedToDb() { | ||
val databaseInstant = try { | ||
val sessionFactory = sessionFactoryService.get().sessionFactory | ||
sessionFactory.openSession().use { session -> | ||
session.createNativeQuery("SELECT NOW()").uniqueResult() as Timestamp | ||
}.toInstant() | ||
} catch (e: Exception) { | ||
logger.error(e) { "error performing hibernate health check" } | ||
null | ||
} | ||
|
||
assertThat(databaseInstant).isNotNull() | ||
assertThat(databaseInstant).isAfterOrEqualTo(fakeClock.instant()) | ||
} | ||
|
||
companion object { | ||
val logger = getLogger<DisabledHealthCheckTest>() | ||
} | ||
} |
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