diff --git a/db-async-common/src/main/scala/com/github/mauricio/async/db/Configuration.scala b/db-async-common/src/main/scala/com/github/mauricio/async/db/Configuration.scala index 70497e08..b9d3041f 100644 --- a/db-async-common/src/main/scala/com/github/mauricio/async/db/Configuration.scala +++ b/db-async-common/src/main/scala/com/github/mauricio/async/db/Configuration.scala @@ -22,6 +22,7 @@ import scala.{None, Option, Int} import io.netty.util.CharsetUtil import io.netty.buffer.AbstractByteBufAllocator import io.netty.buffer.PooledByteBufAllocator +import scala.concurrent.duration._ object Configuration { val DefaultCharset = CharsetUtil.UTF_8 @@ -52,5 +53,7 @@ case class Configuration(username: String, database: Option[String] = None, charset: Charset = Configuration.DefaultCharset, maximumMessageSize: Int = 16777216, - allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT + allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT, + connectTimeout: Duration = 5.seconds, + testTimeout: Duration = 5.seconds ) diff --git a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/pool/MySQLConnectionFactory.scala b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/pool/MySQLConnectionFactory.scala index 94aadfd8..83791366 100644 --- a/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/pool/MySQLConnectionFactory.scala +++ b/mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/pool/MySQLConnectionFactory.scala @@ -50,7 +50,7 @@ class MySQLConnectionFactory( configuration : Configuration ) extends ObjectFact */ def create: MySQLConnection = { val connection = new MySQLConnection(configuration) - Await.result(connection.connect, 5.seconds ) + Await.result(connection.connect, configuration.connectTimeout ) connection } @@ -121,7 +121,7 @@ class MySQLConnectionFactory( configuration : Configuration ) extends ObjectFact */ override def test(item: MySQLConnection): Try[MySQLConnection] = { Try { - Await.result(item.sendQuery("SELECT 0"), 5.seconds) + Await.result(item.sendQuery("SELECT 0"), configuration.testTimeout) item } } diff --git a/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/pool/PostgreSQLConnectionFactory.scala b/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/pool/PostgreSQLConnectionFactory.scala index de06a671..62bcfd1a 100644 --- a/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/pool/PostgreSQLConnectionFactory.scala +++ b/postgresql-async/src/main/scala/com/github/mauricio/async/db/postgresql/pool/PostgreSQLConnectionFactory.scala @@ -50,7 +50,7 @@ class PostgreSQLConnectionFactory( def create: PostgreSQLConnection = { val connection = new PostgreSQLConnection(configuration, group = group, executionContext = executionContext) - Await.result(connection.connect, 5.seconds) + Await.result(connection.connect, configuration.connectTimeout) connection } @@ -87,7 +87,7 @@ class PostgreSQLConnectionFactory( override def test(item: PostgreSQLConnection): Try[PostgreSQLConnection] = { val result : Try[PostgreSQLConnection] = Try({ - Await.result( item.sendQuery("SELECT 0"), 5.seconds ) + Await.result( item.sendQuery("SELECT 0"), configuration.testTimeout ) item })