8000 Merge pull request #90 from fwbrasil/factory-timeouts · mauricio/postgresql-async@5ac1ebb · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Dec 3, 2019. It is now read-only.

Commit 5ac1ebb

Browse files
committed
Merge pull request #90 from fwbrasil/factory-timeouts
Connection factory timeouts
2 parents 0b1d0e0 + f8d3138 commit 5ac1ebb

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

db-async-common/src/main/scala/com/github/mauricio/async/db/Configuration.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import scala.{None, Option, Int}
2222
import io.netty.util.CharsetUtil
2323
import io.netty.buffer.AbstractByteBufAllocator
2424
import io.netty.buffer.PooledByteBufAllocator
25+
import scala.concurrent.duration._
2526

2627
object Configuration {
2728
val DefaultCharset = CharsetUtil.UTF_8
@@ -52,5 +53,7 @@ case class Configuration(username: String,
5253
database: Option[String] = None,
5354
charset: Charset = Configuration.DefaultCharset,
5455
maximumMessageSize: Int = 16777216,
55-
allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT
56+
allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT,
57+
connectTimeout: Duration = 5.seconds,
58+
testTimeout: Duration = 5.seconds
5659
)

mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/pool/MySQLConnectionFactory.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class MySQLConnectionFactory( configuration : Configuration ) extends ObjectFact
5050
*/
5151
def create: MySQLConnection = {
5252
val connection = new MySQLConnection(configuration)
53-
Await.result(connection.connect, 5.seconds )
53+
Await.result(connection.connect, configuration.connectTimeout )
5454

5555
connection
5656
}
@@ -121,7 +121,7 @@ class MySQLConnectionFactory( configuration : Configuration ) extends ObjectFact
121121
*/
122122
override def test(item: MySQLConnection): Try[MySQLConnection] = {
123123
Try {
124-
Await.result(item.sendQuery("SELECT 0"), 5.seconds)
124+
Await.result(item.sendQuery("SELECT 0"), configuration.testTimeout)
125125
item
126126
}
127127
}

postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/pool/PostgreSQLConnectionFactory.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class PostgreSQLConnectionFactory(
5050

5151
def create: PostgreSQLConnection = {
5252
val connection = new PostgreSQLConnection(configuration, group = group, executionContext = executionContext)
53-
Await.result(connection.connect, 5.seconds)
53+
Await.result(connection.connect, configuration.connectTimeout)
5454

5555
connection
5656
}
@@ -87,7 +87,7 @@ class PostgreSQLConnectionFactory(
8787

8888
override def test(item: PostgreSQLConnection): Try[PostgreSQLConnection] = {
8989
val result : Try[PostgreSQLConnection] = Try({
90-
Await.result( item.sendQuery("SELECT 0"), 5.seconds )
90+
Await.result( item.sendQuery("SELECT 0"), configuration.testTimeout )
9191
item
9292
})
9393

0 commit comments

Comments
 (0)
0