Skip to content

Commit

Permalink
Merge pull request #11805 from gheine/main
Browse files Browse the repository at this point in the history
Support setting of hikari keepaliveTime
  • Loading branch information
mkurz committed May 12, 2023
2 parents c851b15 + 2c7eac5 commit d3543c8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
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

0 comments on commit d3543c8

Please sign in to comment.