Skip to content

Commit

Permalink
Merge pull request #473 from cloudsufi/mysql-fix-conn-args
Browse files Browse the repository at this point in the history
[PLUGIN-1728]Fix for connection arguments not getting updated.
  • Loading branch information
vikasrathee-cs authored Dec 27, 2023
2 parents e076c4c + 4d8bc97 commit 2657283
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ public String getConnectionString() {
@Override
public Properties getConnectionArgumentsProperties() {
Properties properties = super.getConnectionArgumentsProperties();
properties.put(JDBC_PROPERTY_CONNECT_TIMEOUT_MILLIS, "20000");
properties.put(JDBC_PROPERTY_SOCKET_TIMEOUT_MILLIS, "20000");
properties.putIfAbsent(JDBC_PROPERTY_CONNECT_TIMEOUT_MILLIS, "20000");
properties.putIfAbsent(JDBC_PROPERTY_SOCKET_TIMEOUT_MILLIS, "20000");
return properties;
}

@Override
public boolean canConnect() {
return super.canConnect() && !containsMacro(CloudSQLUtil.CONNECTION_NAME) &&
!containsMacro(ConnectionConfig.PORT) && !containsMacro(ConnectionConfig.DATABASE);
!containsMacro(ConnectionConfig.PORT) && !containsMacro(ConnectionConfig.DATABASE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public int getDefaultPort() {
public Properties getConnectionArgumentsProperties() {
Properties prop = super.getConnectionArgumentsProperties();
// the unit below is milli-second
prop.put(JDBC_PROPERTY_CONNECT_TIMEOUT, "20000");
prop.put(JDBC_PROPERTY_SOCKET_TIMEOUT, "20000");
prop.put(JDBC_REWRITE_BATCHED_STATEMENTS, "true");
prop.putIfAbsent(JDBC_PROPERTY_CONNECT_TIMEOUT, "20000");
prop.putIfAbsent(JDBC_PROPERTY_SOCKET_TIMEOUT, "20000");
prop.putIfAbsent(JDBC_REWRITE_BATCHED_STATEMENTS, "true");
// MySQL property to ensure that TINYINT(1) type data is not converted to MySQL Bit/Boolean type in the ResultSet.
prop.putIfAbsent(MYSQL_TINYINT1_IS_BIT, "false");
return prop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,26 @@ public void test() throws ClassNotFoundException, IOException {
new MysqlConnectorConfig("localhost", 3306, "username", "password", "jdbc", ""));

super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
"rewriteBatchedStatements=true, " +
"connectTimeout=20000, tinyInt1isBit=false, " +
"socketTimeout=20000}. Error: " +
"ConnectException: Connection refused (Connection refused).");
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
"rewriteBatchedStatements=true, " +
"connectTimeout=20000, tinyInt1isBit=false, " +
"socketTimeout=20000}. Error: " +
"ConnectException: Connection refused (Connection refused).");
}

@Test
public void testWithUpdatedConnectionArguments() throws ClassNotFoundException, IOException {

MysqlConnector connector = new MysqlConnector(
new MysqlConnectorConfig("localhost", 3306, "username", "password", "jdbc",
"connectTimeout=30000;socketTimeout=30000"));

super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string: " +
"jdbc:mysql://localhost:3306 and arguments: {user=username, " +
"rewriteBatchedStatements=true, " +
"connectTimeout=30000, tinyInt1isBit=false, " +
"socketTimeout=30000}. Error: " +
"ConnectException: Connection refused (Connection refused).");
}

}

0 comments on commit 2657283

Please sign in to comment.