@@ -47,18 +47,13 @@ public void failoverReadonlyToMaster() throws Exception {
4747 @ Test
4848 public void ensureReadOnlyOnReplica () throws Exception {
4949 // mariadb1.example.com, mariadb2.example.com and mariadb3.example.com DNS alias must be defined
50- Assumptions .assumeTrue (
51- !isWindows ()
52- && !"maxscale" .equals (System .getenv ("srv" ))
53- && !"skysql" .equals (System .getenv ("srv" ))
54- && !"skysql-ha" .equals (System .getenv ("srv" ))
55- && !isXpand ());
50+ Assumptions .assumeFalse ("maxscale" .equals (System .getenv ("srv" )));
5651
5752 Configuration conf = Configuration .parse (mDefUrl );
5853 HostAddress hostAddress = conf .addresses ().get (0 );
5954 String url =
6055 mDefUrl .replaceAll (
61- "//([^/]* )/" ,
56+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
6257 String .format (
6358 "//mariadb1.example.com:%s,mariadb2.example.com:%s,mariadb3.example.com:%s/" ,
6459 hostAddress .port , hostAddress .port , hostAddress .port ));
@@ -74,7 +69,7 @@ public void ensureReadOnlyOnReplica() throws Exception {
7469 (Connection )
7570 DriverManager .getConnection (
7671 url + "&waitReconnectTimeout=30&deniedListTimeout=300" )) {
77- assertTrue (con .__test_host ().contains ("primary " ));
72+ assertFalse (con .__test_host ().contains ("replica " ));
7873 con .setReadOnly (true );
7974 assertTrue (con .__test_host ().contains ("replica" ));
8075 if (con .__test_host ().contains ("mariadb2" )) {
@@ -103,16 +98,16 @@ public void readOnly() throws SQLException {
10398 && !isXpand ());
10499 try (Connection con = createProxyConKeep ("&waitReconnectTimeout=300&deniedListTimeout=300" )) {
105100 Statement stmt = con .createStatement ();
106- stmt .execute ("DROP TABLE IF EXISTS testReadOnly" );
107- stmt .execute ("CREATE TABLE testReadOnly(id int)" );
101+ stmt .executeUpdate ("DROP TABLE IF EXISTS testReadOnly" );
102+ stmt .executeUpdate ("CREATE TABLE testReadOnly(id int)" );
108103 con .setAutoCommit (false );
109104 con .setReadOnly (true );
110105 Common .assertThrowsContains (
111106 SQLException .class ,
112107 () -> stmt .execute ("INSERT INTO testReadOnly values (2)" ),
113108 "Cannot execute statement in a READ ONLY transaction" );
114109 con .setReadOnly (false );
115- stmt .execute ("DROP TABLE testReadOnly" );
110+ stmt .executeUpdate ("DROP TABLE testReadOnly" );
116111 }
117112 }
118113
@@ -122,7 +117,7 @@ public void syncState() throws Exception {
122117 !"skysql" .equals (System .getenv ("srv" )) && !"skysql-ha" .equals (System .getenv ("srv" )));
123118 try (Connection con = createProxyConKeep ("" )) {
124119 Statement stmt = con .createStatement ();
125- stmt .execute ("CREATE DATABASE IF NOT EXISTS sync" );
120+ stmt .executeUpdate ("CREATE DATABASE IF NOT EXISTS sync" );
126121 con .setCatalog ("sync" );
127122 con .setTransactionIsolation (java .sql .Connection .TRANSACTION_SERIALIZABLE );
128123 con .setReadOnly (true );
@@ -170,7 +165,7 @@ public void closedConnectionMulti() throws Exception {
170165 HostAddress hostAddress = conf .addresses ().get (0 );
171166 String url =
172167 mDefUrl .replaceAll (
173- "//([^/]* )/" ,
168+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
174169 String .format (
175170 "//address=(host=localhost)(port=9999)(type=master),address=(host=%s)(port=%s)(type=master)/" ,
176171 hostAddress .host , hostAddress .port ));
@@ -188,7 +183,7 @@ public void closedConnectionMulti() throws Exception {
188183
189184 url =
190185 mDefUrl .replaceAll (
191- "//([^/]* )/" ,
186+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
192187 String .format (
193188 "//%s:%s,%s,%s/" ,
194189 hostAddress .host , hostAddress .port , hostAddress .host , hostAddress .port ));
@@ -250,7 +245,7 @@ public void masterFailover() throws Exception {
250245
251246 String url =
252247 mDefUrl .replaceAll (
253- "//([^/]* )/" + database ,
248+ "//(" + hostname + "|" + hostname + ":" + port + " )/" + database ,
254249 String .format (
255250 "//address=(host=localhost)(port=9999)(type=master),address=(host=localhost)(port=%s)(type=master),address=(host=%s)(port=%s)(type=master)/"
256251 + database ,
@@ -266,10 +261,10 @@ public void masterFailover() throws Exception {
266261 (Connection )
267262 DriverManager .getConnection (
268263 url
269- + "&deniedListTimeout=300&retriesAllDown=4&connectTimeout=20 &deniedListTimeout=20 " )) {
264+ + "&deniedListTimeout=300&retriesAllDown=4&connectTimeout=50 &deniedListTimeout=50 " )) {
270265 Statement stmt = con .createStatement ();
271266 stmt .execute ("SET @con=1" );
272- proxy .restart (50 );
267+ proxy .restart (100 );
273268 con .isValid (1000 );
274269 }
275270
@@ -279,7 +274,7 @@ public void masterFailover() throws Exception {
279274 (Connection )
280275 DriverManager .getConnection (
281276 url
282- + "&waitReconnectTimeout=300&retriesAllDown=10&connectTimeout=20 &deniedListTimeout=20 &socketTimeout=100" )) {
277+ + "&waitReconnectTimeout=300&retriesAllDown=10&connectTimeout=50 &deniedListTimeout=50 &socketTimeout=100" )) {
283278 Statement stmt = con .createStatement ();
284279 stmt .execute ("START TRANSACTION" );
285280 stmt .execute ("SET @con=1" );
@@ -289,8 +284,7 @@ public void masterFailover() throws Exception {
289284 ResultSet rs = stmt .executeQuery ("SELECT @con" );
290285 if (rs .next ()) {
291286 System .out .println ("Resultset res:" + rs .getString (1 ));
292- }
293- fail ("must have thrown exception" );
287+ } else fail ("must have thrown exception" );
294288 } catch (SQLTransientConnectionException e ) {
295289 assertTrue (e .getMessage ().contains ("In progress transaction was lost" ));
296290 }
@@ -301,7 +295,7 @@ public void masterFailover() throws Exception {
301295 try (Connection con =
302296 (Connection )
303297 DriverManager .getConnection (
304- url + "&retriesAllDown=4&connectTimeout=20 &deniedListTimeout=20 " )) {
298+ url + "&retriesAllDown=4&connectTimeout=50 &deniedListTimeout=50 " )) {
305299 Statement stmt = con .createStatement ();
306300 con .setAutoCommit (false );
307301 stmt .execute ("START TRANSACTION" );
@@ -322,7 +316,7 @@ public void masterFailover() throws Exception {
322316 (Connection )
323317 DriverManager .getConnection (
324318 url
325- + "&transactionReplay=true&waitReconnectTimeout=300&deniedListTimeout=300&retriesAllDown=4&connectTimeout=20 " )) {
319+ + "&transactionReplay=true&waitReconnectTimeout=300&deniedListTimeout=300&retriesAllDown=4&connectTimeout=50 " )) {
326320 Statement stmt = con .createStatement ();
327321 stmt .execute ("DROP TABLE IF EXISTS testReplay" );
328322 stmt .execute ("CREATE TABLE testReplay(id INT)" );
@@ -374,7 +368,7 @@ public void masterStreamingFailover() throws Exception {
374368
375369 String url =
376370 mDefUrl .replaceAll (
377- "//([^/]* )/" ,
371+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
378372 String .format (
379373 "//address=(host=localhost)(port=%s)(type=master)/" , proxy .getLocalPort ()));
380374 url = url .replaceAll ("jdbc:mariadb:" , "jdbc:mariadb:sequential:" );
@@ -441,7 +435,7 @@ public void masterReplicationFailover() throws Exception {
441435
442436 String url =
443437 mDefUrl .replaceAll (
444- "//([^/]* )/" ,
438+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
445439 String .format (
446440 "//localhost:%s,%s:%s/" , proxy .getLocalPort (), hostAddress .host , hostAddress .port ));
447441 url = url .replaceAll ("jdbc:mariadb:" , "jdbc:mariadb:replication:" );
@@ -503,7 +497,7 @@ public void masterReplicationStreamingFailover() throws Exception {
503497
504498 String url =
505499 mDefUrl .replaceAll (
506- "//([^/]* )/" ,
500+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
507501 String .format (
508502 "//address=(host=localhost)(port=%s)(type=primary),address=(host=%s)(port=%s)(type=replica)/" ,
509503 proxy .getLocalPort (), hostAddress .host , hostAddress .port ));
@@ -567,7 +561,7 @@ public Connection createProxyConKeep(String opts) throws SQLException {
567561
568562 String url =
569563 mDefUrl .replaceAll (
570- "//([^/]* )/" ,
564+ "//(" + hostname + "|" + hostname + ":" + port + " )/" ,
571565 String .format (
572566 "//%s:%s,localhost:%s/" , hostAddress .host , hostAddress .port , proxy .getLocalPort ()));
573567 url = url .replaceAll ("jdbc:mariadb:" , "jdbc:mariadb:replication:" );
0 commit comments