Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting of hikari keepaliveTime #11805

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions persistence/play-jdbc/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ play {
# The idle timeout
idleTimeout = 10 minutes

# If non null, controls how frequently HikariCP will attempt to keep a connection alive
keepaliveTime = null

# The max lifetime of a connection
maxLifetime = 30 minutes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private[db] class HikariCPConfig private (
hikariConfig.setAutoCommit(config.get[Boolean]("autoCommit"))
hikariConfig.setConnectionTimeout(toMillis(config.get[Duration]("connectionTimeout")))
hikariConfig.setIdleTimeout(toMillis(config.get[Duration]("idleTimeout")))
config.get[Option[Duration]]("keepaliveTime").foreach(duration => hikariConfig.setKeepaliveTime(toMillis(duration)))
hikariConfig.setMaxLifetime(toMillis(config.get[Duration]("maxLifetime")))
config.get[Option[String]]("connectionTestQuery").foreach(hikariConfig.setConnectionTestQuery)
config.get[Option[Int]]("minimumIdle").foreach(hikariConfig.setMinimumIdle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class HikariCPConfigSpec extends Specification {
new HikariCPConfig("foo", dbConfig, reference).toHikariConfig.getIdleTimeout must beEqualTo(10.minutes.toMillis)
}

"keepaliveTime to 0" in new Configs {
new HikariCPConfig("foo", dbConfig, reference).toHikariConfig.getKeepaliveTime must beEqualTo(0L)
}

"maxLifetime to 30 minutes" in new Configs {
new HikariCPConfig("foo", dbConfig, reference).toHikariConfig.getMaxLifetime must beEqualTo(30.minutes.toMillis)
}
Expand Down Expand Up @@ -126,6 +130,11 @@ class HikariCPConfigSpec extends Specification {
new HikariCPConfig("foo", dbConfig, config).toHikariConfig.getIdleTimeout must beEqualTo(5.minutes.toMillis)
}

"keepaliveTime" in new Configs {
val config = from("hikaricp.keepaliveTime" -> "5 minutes")
new HikariCPConfig("foo", dbConfig, config).toHikariConfig.getKeepaliveTime must beEqualTo(5.minutes.toMillis)
}

"maxLifetime" in new Configs {
val config = from("hikaricp.maxLifetime" -> "15 minutes")
new HikariCPConfig("foo", dbConfig, config).toHikariConfig.getMaxLifetime must beEqualTo(15.minutes.toMillis)
Expand Down