Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[CONJ-335] regression : Pool connection may fail to connect with good…
… user
  • Loading branch information
rusher committed Aug 23, 2016
1 parent 65c815c commit ff7b1db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
15 changes: 6 additions & 9 deletions src/main/java/org/mariadb/jdbc/UrlParser.java
Expand Up @@ -207,7 +207,7 @@ private static void parseInternal(UrlParser urlParser, String url, Properties pr
additionalParameters = null;
}

urlParser = defineUrlParserParameters(urlParser, properties, hostAddressesString, additionalParameters);
defineUrlParserParameters(urlParser, properties, hostAddressesString, additionalParameters);
setDefaultHostAddressType(urlParser);

} catch (IllegalArgumentException i) {
Expand All @@ -223,9 +223,8 @@ private static void parseInternal(UrlParser urlParser, String url, Properties pr
* @param properties properties
* @param hostAddressesString string that holds all the host addresses
* @param additionalParameters string that holds all parameters defined for the connection
* @return UrlParser instance
*/
private static UrlParser defineUrlParserParameters(UrlParser urlParser, Properties properties, String hostAddressesString,
private static void defineUrlParserParameters(UrlParser urlParser, Properties properties, String hostAddressesString,
String additionalParameters) {

if (additionalParameters != null) {
Expand All @@ -239,23 +238,21 @@ private static UrlParser defineUrlParserParameters(UrlParser urlParser, Properti
String options2 = (matcher.group(3) != null) ? matcher.group(3).substring(1) : "";

urlParser.database = (db1 != null) ? db1 : db2;
urlParser.options = (!options1.equals(""))
? DefaultOptions.parse(urlParser.haMode, options1, properties) : DefaultOptions.parse(urlParser.haMode, options2, properties);
urlParser.options = DefaultOptions.parse(urlParser.haMode, (!options1.equals("")) ? options1 : options2,
properties, urlParser.options);

} else {
urlParser.database = null;
urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties);
urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties, urlParser.options);
}
} else {
urlParser.database = null;
urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties);
urlParser.options = DefaultOptions.parse(urlParser.haMode, "", properties, urlParser.options);
}
LoggerFactory.init(urlParser.options.log
|| urlParser.options.profileSql
|| urlParser.options.slowQueryThresholdNanos != null);
urlParser.addresses = HostAddress.parse(hostAddressesString, urlParser.haMode);

return urlParser;
}

private static void setHaMode(UrlParser urlParser,String url, int separator) {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/mariadb/jdbc/internal/util/Options.java
Expand Up @@ -127,7 +127,6 @@ public String toString() {
return "Options{"
+ "user='" + user + '\''
+ ", assureReadOnly=" + assureReadOnly
+ ", password='" + password + '\''
+ ", trustServerCertificate=" + trustServerCertificate
+ ", serverSslCert='" + serverSslCert + '\''
+ ", useFractionalSeconds=" + useFractionalSeconds
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/org/mariadb/jdbc/ParserTest.java
Expand Up @@ -2,13 +2,16 @@

import org.junit.BeforeClass;
import org.junit.Test;
import org.mariadb.jdbc.internal.util.DefaultOptions;
import org.mariadb.jdbc.internal.util.Options;
import org.mariadb.jdbc.internal.util.constant.HaMode;

import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Properties;

import static org.junit.Assert.*;
Expand All @@ -24,6 +27,23 @@ public static void initClass() throws SQLException {
createTable("table2", "id2 int auto_increment primary key");
}

@Test
public void poolVerification() throws Exception {
ArrayList<HostAddress> hostAddresses = new ArrayList<>();
hostAddresses.add(new HostAddress(hostname, port));
UrlParser urlParser = new UrlParser(database, hostAddresses, DefaultOptions.defaultValues(HaMode.NONE), HaMode.NONE);
urlParser.setUsername("USER");
urlParser.setPassword("PWD");
urlParser.parseUrl("jdbc:mariadb://localhost:3306/db");
assertEquals("USER", urlParser.getUsername());
assertEquals("PWD", urlParser.getPassword());

MariaDbDataSource datasource = new MariaDbDataSource();
datasource.setUser("USER");
datasource.setPassword("PWD");
datasource.setUrl("jdbc:mariadb://localhost:3306/db");
}


@Test
public void addProperties() throws Exception {
Expand Down

0 comments on commit ff7b1db

Please sign in to comment.