Skip to content

Commit 2657283

Browse files
Merge pull request #473 from cloudsufi/mysql-fix-conn-args
[PLUGIN-1728]Fix for connection arguments not getting updated.
2 parents e076c4c + 4d8bc97 commit 2657283

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

cloudsql-mysql-plugin/src/main/java/io/cdap/plugin/cloudsql/mysql/CloudSQLMySQLConnectorConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ public String getConnectionString() {
105105
@Override
106106
public Properties getConnectionArgumentsProperties() {
107107
Properties properties = super.getConnectionArgumentsProperties();
108-
properties.put(JDBC_PROPERTY_CONNECT_TIMEOUT_MILLIS, "20000");
109-
properties.put(JDBC_PROPERTY_SOCKET_TIMEOUT_MILLIS, "20000");
108+
properties.putIfAbsent(JDBC_PROPERTY_CONNECT_TIMEOUT_MILLIS, "20000");
109+
properties.putIfAbsent(JDBC_PROPERTY_SOCKET_TIMEOUT_MILLIS, "20000");
110110
return properties;
111111
}
112112

113113
@Override
114114
public boolean canConnect() {
115115
return super.canConnect() && !containsMacro(CloudSQLUtil.CONNECTION_NAME) &&
116-
!containsMacro(ConnectionConfig.PORT) && !containsMacro(ConnectionConfig.DATABASE);
116+
!containsMacro(ConnectionConfig.PORT) && !containsMacro(ConnectionConfig.DATABASE);
117117
}
118118
}

mysql-plugin/src/main/java/io/cdap/plugin/mysql/MysqlConnectorConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ public int getDefaultPort() {
5757
public Properties getConnectionArgumentsProperties() {
5858
Properties prop = super.getConnectionArgumentsProperties();
5959
// the unit below is milli-second
60-
prop.put(JDBC_PROPERTY_CONNECT_TIMEOUT, "20000");
61-
prop.put(JDBC_PROPERTY_SOCKET_TIMEOUT, "20000");
62-
prop.put(JDBC_REWRITE_BATCHED_STATEMENTS, "true");
60+
prop.putIfAbsent(JDBC_PROPERTY_CONNECT_TIMEOUT, "20000");
61+
prop.putIfAbsent(JDBC_PROPERTY_SOCKET_TIMEOUT, "20000");
62+
prop.putIfAbsent(JDBC_REWRITE_BATCHED_STATEMENTS, "true");
6363
// MySQL property to ensure that TINYINT(1) type data is not converted to MySQL Bit/Boolean type in the ResultSet.
6464
prop.putIfAbsent(MYSQL_TINYINT1_IS_BIT, "false");
6565
return prop;

mysql-plugin/src/test/java/io/cdap/plugin/mysql/MysqlFailedConnectionTest.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,26 @@ public void test() throws ClassNotFoundException, IOException {
3131
new MysqlConnectorConfig("localhost", 3306, "username", "password", "jdbc", ""));
3232

3333
super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string: " +
34-
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
35-
"rewriteBatchedStatements=true, " +
36-
"connectTimeout=20000, tinyInt1isBit=false, " +
37-
"socketTimeout=20000}. Error: " +
38-
"ConnectException: Connection refused (Connection refused).");
34+
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
35+
"rewriteBatchedStatements=true, " +
36+
"connectTimeout=20000, tinyInt1isBit=false, " +
37+
"socketTimeout=20000}. Error: " +
38+
"ConnectException: Connection refused (Connection refused).");
3939
}
40+
41+
@Test
42+
public void testWithUpdatedConnectionArguments() throws ClassNotFoundException, IOException {
43+
44+
MysqlConnector connector = new MysqlConnector(
45+
new MysqlConnectorConfig("localhost", 3306, "username", "password", "jdbc",
46+
"connectTimeout=30000;socketTimeout=30000"));
47+
48+
super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string: " +
49+
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
50+
"rewriteBatchedStatements=true, " +
51+
"connectTimeout=30000, tinyInt1isBit=false, " +
52+
"socketTimeout=30000}. Error: " +
53+
"ConnectException: Connection refused (Connection refused).");
54+
}
55+
4056
}

0 commit comments

Comments
 (0)