Skip to content

Commit

Permalink
[misc] test for failover improvement for reliability
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jul 5, 2024
1 parent 279b903 commit 308cbb5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/test/java/org/mariadb/jdbc/integration/MultiHostTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,13 @@ public void masterFailover() throws Exception {

String url =
mDefUrl.replaceAll(
"//([^/]*)/",
"//([^/]*)/" + database,
String.format(
"//address=(host=localhost)(port=9999)(type=master),address=(host=localhost)(port=%s)(type=master),address=(host=%s)(port=%s)(type=master)/",
proxy.getLocalPort(), hostAddress.host, hostAddress.port));
"//address=(host=localhost)(port=9999)(type=master),address=(host=localhost)(port=%s)(type=master),address=(host=%s)(port=%s)(type=master)/"
+ database,
proxy.getLocalPort(),
hostAddress.host,
hostAddress.port));
url = url.replaceAll("jdbc:mariadb:", "jdbc:mariadb:sequential:");
if (conf.sslMode() == SslMode.VERIFY_FULL) {
url = url.replaceAll("sslMode=verify-full", "sslMode=verify-ca");
Expand Down Expand Up @@ -281,7 +284,7 @@ public void masterFailover() throws Exception {
stmt.execute("START TRANSACTION");
stmt.execute("SET @con=1");

proxy.restart(100);
proxy.restart(100, true);
try {
ResultSet rs = stmt.executeQuery("SELECT @con");
if (rs.next()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public TcpProxy(String host, int remoteport) throws IOException {
}

public void stop() {
socket.kill();
socket.kill(false);
}

public void setDelay(int delay) {
Expand All @@ -46,7 +46,11 @@ public void removeDelay() {
* @param sleepTime sleep time in milliseconds
*/
public void restart(long sleepTime) {
socket.kill();
restart(sleepTime, false);
}

public void restart(long sleepTime, boolean rst) {
socket.kill(rst);
logger.trace("host proxy port " + socket.getLocalport() + " for " + host + " started");
Executors.newSingleThreadScheduledExecutor().schedule(socket, sleepTime, TimeUnit.MILLISECONDS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ public void setDelay(int delay) {
}

/** Kill proxy. */
public void kill() {
public void kill(boolean rst) {
stop = true;
try {
if (server != null) {
if (rst) server.setSoLinger(true, 0);
server.close();
}
} catch (IOException e) {
// eat Exception
}
try {
if (client != null) {
if (rst) client.setSoLinger(true, 0);
client.close();
}
} catch (IOException e) {
Expand Down

0 comments on commit 308cbb5

Please sign in to comment.