Skip to content

Commit 483de7a

Browse files
committed
[misc] test stability improvement - localSocket
1 parent aac7d68 commit 483de7a

File tree

1 file changed

+23
-39
lines changed

1 file changed

+23
-39
lines changed

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,8 @@ public void localSocket() throws Exception {
942942
// eat
943943
}
944944
boolean useOldNotation =
945-
(!isMariaDBServer() || !minVersion(10, 2, 0))
946-
&& (isMariaDBServer() || !minVersion(8, 0, 0));
945+
(!isMariaDBServer() || !minVersion(10, 2, 0))
946+
&& (isMariaDBServer() || !minVersion(8, 0, 0));
947947
if (useOldNotation) {
948948
stmt.execute("CREATE USER testSocket IDENTIFIED BY 'heyPassw!µ20§rd'");
949949
stmt.execute("GRANT SELECT on *.* to testSocket IDENTIFIED BY 'heyPassw!µ20§rd'");
@@ -953,54 +953,38 @@ public void localSocket() throws Exception {
953953
}
954954
stmt.execute("FLUSH PRIVILEGES");
955955

956-
try (java.sql.Connection connection =
957-
DriverManager.getConnection(
956+
String url =
958957
String.format(
959-
"jdbc:mariadb:///%s?user=testSocket&password=heyPassw!µ20§rd&localSocket=%s&tcpAbortiveClose&tcpKeepAlive",
960-
sharedConn.getCatalog(), path))) {
961-
connection.setNetworkTimeout(null, 300);
962-
rs = connection.createStatement().executeQuery("select 1");
963-
assertTrue(rs.next());
964-
}
958+
"jdbc:mariadb:///%s?user=testSocket&password=heyPassw!µ20§rd&localSocket=%s&tcpAbortiveClose&tcpKeepAlive",
959+
sharedConn.getCatalog(), path);
965960

966-
// host format
967-
try (java.sql.Connection connection =
968-
DriverManager.getConnection(
969-
String.format(
970-
"jdbc:mariadb://address=(localSocket=%s)/%s?user=testSocket&password=heyPassw!µ20§rd&tcpAbortiveClose&tcpKeepAlive",
971-
path, sharedConn.getCatalog()))) {
961+
try (java.sql.Connection connection = DriverManager.getConnection(url)) {
972962
connection.setNetworkTimeout(null, 300);
973963
rs = connection.createStatement().executeQuery("select 1");
974964
assertTrue(rs.next());
975965
}
966+
976967
Common.assertThrowsContains(
977-
SQLException.class,
978-
() ->
979-
DriverManager.getConnection(
980-
"jdbc:mariadb:///"
981-
+ sharedConn.getCatalog()
982-
+ "?user=testSocket&password=heyPassw!µ20§rd&localSocket=/wrongPath"),
983-
"Socket fail to connect to address=(localSocket=/wrongPath)");
984-
Common.assertThrowsContains(
985-
SQLException.class,
986-
() ->
987-
DriverManager.getConnection(
988-
"jdbc:mariadb://address=(localSocket=/wrongPath)/"
989-
+ sharedConn.getCatalog()
990-
+ "?user=testSocket&password=heyPassw!µ20§rd"),
991-
"Socket fail to connect to address=(localSocket=/wrongPath)");
968+
SQLException.class,
969+
() ->
970+
DriverManager.getConnection(
971+
"jdbc:mariadb:///"
972+
+ sharedConn.getCatalog()
973+
+ "?user=testSocket&password=heyPassw!µ20§rd&localSocket=/wrongPath"),
974+
"Socket fail to connect to host");
975+
992976
if (haveSsl()) {
993977
String serverCertPath = SslTest.retrieveCertificatePath();
994978
if (serverCertPath != null) {
995979
try (Connection con =
996-
DriverManager.getConnection(
997-
"jdbc:mariadb:///"
998-
+ sharedConn.getCatalog()
999-
+ "?sslMode=verify-full&user=testSocket&password=heyPassw!µ20§rd"
1000-
+ "&serverSslCert="
1001-
+ serverCertPath
1002-
+ "&localSocket="
1003-
+ path)) {
980+
DriverManager.getConnection(
981+
"jdbc:mariadb:///"
982+
+ sharedConn.getCatalog()
983+
+ "?sslMode=verify-full&user=testSocket&password=heyPassw!µ20§rd"
984+
+ "&serverSslCert="
985+
+ serverCertPath
986+
+ "&localSocket="
987+
+ path)) {
1004988
rs = con.createStatement().executeQuery("select 1");
1005989
assertTrue(rs.next());
1006990
}

0 commit comments

Comments
 (0)