Skip to content
Merged
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
5 changes: 3 additions & 2 deletions r2dbc-mysql/src/main/java/MysqlConnectionFactoryProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
*/
const val MYSQL_DRIVER = "mysql"

const val MYSQL_DEFAULT_PORT = 3306

var CLIENT_FOUND_ROWS: Boolean by ClientFoundRowsDelegate()

init {
Expand Down Expand Up @@ -63,7 +65,7 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
override fun create(connectionFactoryOptions: ConnectionFactoryOptions): JasyncConnectionFactory {
val configuration = Configuration(
host = connectionFactoryOptions.getValue(HOST) as String? ?: throw IllegalArgumentException("HOST is missing"),
port = connectionFactoryOptions.getValue(PORT) as Int? ?: throw IllegalArgumentException("PORT is missing"),
port = connectionFactoryOptions.getValue(PORT) as Int? ?: MYSQL_DEFAULT_PORT,
username = connectionFactoryOptions.getValue(USER) as String? ?: throw IllegalArgumentException("USER is missing"),
password = connectionFactoryOptions.getValue(PASSWORD)?.toString(),
database = connectionFactoryOptions.getValue(DATABASE) as String?,
Expand All @@ -80,7 +82,6 @@ class MysqlConnectionFactoryProvider : ConnectionFactoryProvider {
return when {
driver == null || driver != MYSQL_DRIVER -> false
!connectionFactoryOptions.hasOption(HOST) -> false
!connectionFactoryOptions.hasOption(PORT) -> false
!connectionFactoryOptions.hasOption(USER) -> false
else -> true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,34 @@ class MysqlConnectionFactoryProviderTest {

@Test
fun shouldCreateMysqlConnectionWithMysqlSSLConfigurationFactory() {

val options =
ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:443/")
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:443/")

// when
val result = provider.create(options)

// then
assertEquals(SSLConfiguration(), result.mySQLConnectionFactory.configuration.ssl)
}

@Test
fun shouldUseDefaultPortWhenPortIsNotSpecified() {
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host/")

// when
val result = provider.create(options)

// then
assertEquals(3306, result.mySQLConnectionFactory.configuration.port)
}

@Test
fun shouldUseSpecifiedPort() {
val options = ConnectionFactoryOptions.parse("r2dbc:mysql://user@host:3307/")

// when
val result = provider.create(options)

// then
assertEquals(3307, result.mySQLConnectionFactory.configuration.port)
}
}