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

[2.8.x] Support setting of hikari keepaliveTime (backport #11805) by @gheine #11809

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -119,6 +119,7 @@ private[db] class HikariCPConfig(dbConfig: DatabaseConfig, configuration: Config
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 @@ -56,6 +56,10 @@ class HikariCPConfigSpec extends Specification {
new HikariCPConfig(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(dbConfig, reference).toHikariConfig.getMaxLifetime must beEqualTo(30.minutes.toMillis)
}
Expand Down Expand Up @@ -113,6 +117,11 @@ class HikariCPConfigSpec extends Specification {
new HikariCPConfig(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(dbConfig, config).toHikariConfig.getMaxLifetime must beEqualTo(15.minutes.toMillis)
Expand Down
Loading