File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
test/java/com/github/jasync/r2dbc/mysql Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -77,8 +77,8 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
77
77
password = connectionFactoryOptions.getValue(PASSWORD )?.toString(),
78
78
database = connectionFactoryOptions.getValue(DATABASE ) as String? ,
79
79
applicationName = connectionFactoryOptions.getValue(APPLICATION_NAME ) as String? ,
80
- connectionTimeout = ( connectionFactoryOptions.getValue(CONNECT_TIMEOUT ) as Duration ? )?.toMillis()?.toInt() ? : 5000 ,
81
- queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT ) as Duration ? ,
80
+ connectionTimeout = connectionFactoryOptions.getValue(CONNECT_TIMEOUT )?.parseDuration( )?.toMillis()?.toInt() ? : 5000 ,
81
+ queryTimeout = connectionFactoryOptions.getValue(STATEMENT_TIMEOUT )?.parseDuration() ,
82
82
ssl = MysqlSSLConfigurationFactory .create(connectionFactoryOptions),
83
83
rsaPublicKey = (connectionFactoryOptions.getValue(SERVER_RSA_PUBLIC_KEY_FILE ) as String? )?.let { Paths .get(it) }
84
84
)
@@ -97,3 +97,15 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
97
97
98
98
override fun getDriver (): String = MYSQL_DRIVER
99
99
}
100
+
101
+ private fun Any.parseDuration (): Duration {
102
+ return when (this ) {
103
+ is Duration -> {
104
+ this
105
+ }
106
+ is String -> {
107
+ Duration .parse(this )
108
+ }
109
+ else -> throw Exception (" cant parse $this to Duration" )
110
+ }
111
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import com.github.jasync.sql.db.SSLConfiguration
4
4
import io.r2dbc.spi.ConnectionFactoryOptions
5
5
import org.junit.Assert.assertEquals
6
6
import org.junit.Test
7
+ import java.time.Duration
7
8
8
9
class MysqlConnectionFactoryProviderTest {
9
10
@@ -63,4 +64,15 @@ class MysqlConnectionFactoryProviderTest {
63
64
// then
64
65
assertEquals(" rsa.pem" , result.mySQLConnectionFactory.configuration.rsaPublicKey.toString())
65
66
}
67
+
68
+ @Test
69
+ fun shouldUseTimeoutAsString () {
70
+ val options = ConnectionFactoryOptions .parse(" r2dbc:mysql://user@host/db?connectTimeout=PT3S" )
71
+
72
+ // when
73
+ val result = provider.create(options)
74
+
75
+ // then
76
+ assertEquals(Duration .parse(" PT3S" ).toMillis().toInt(), result.mySQLConnectionFactory.configuration.connectionTimeout)
77
+ }
66
78
}
You can’t perform that action at this time.
0 commit comments