8000 [r2dbc-mysql] Using MySQL default port when not specified by davin111 · Pull Request #394 · jasync-sql/jasync-sql · GitHub
[go: up one dir, main page]

Skip to content

[r2dbc-mysql] Using MySQL default port when not specified #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2023
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. 8000
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)
}
}
0