Skip to content

Commit

Permalink
add reconnect timeout config
Browse files Browse the repository at this point in the history
  • Loading branch information
aressu1985 committed Jan 29, 2024
1 parent bc5908f commit 13aab79
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
Binary file modified lib/mo-tester-1.0-SNAPSHOT.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions mo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ jdbc:
useLocalSessionState: "true"
zeroDateTimeBehavior: "CONVERT_TO_NULL"
failoverReadOnly: "false"
initialTimeout: 60
autoReconnect: "true"
maxReconnects: 4
serverTimezone: "Asia/Shanghai"
socketTimeout: 120000

#users
user:
name: "dump"
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/mo/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ public static boolean isInclude(String name){

public static void cleanDatabases(){
Connection connection = ConnectionManager.getConnection();
if(connection == null){
LOG.error("Failed to clean databases,please check the error,the program will exit.");
System.exit(1);
}
String dropDB = "DROP DATABASE IF EXISTS `%s`";
String[] dbs = RunConfUtil.getBuiltinDb();
try {
Expand Down
28 changes: 15 additions & 13 deletions src/main/java/io/mo/db/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static Connection getConnection(int index){
if(!server_up) return null;

//get db connection,if failed,retry 3 times 10 s interval
for(int i = 0; i < 3; i++) {
//for(int i = 0; i < 3; i++) {
try {
Class.forName(driver);
if (connections[index] == null || connections[index].isClosed()) {
Expand All @@ -43,7 +43,8 @@ public static Connection getConnection(int index){
}
return connections[index];
} catch (SQLException e) {
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], and will wait 10 seconds and retry...");
//LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], and will wait 10 seconds and retry...");
LOG.error(e.getMessage());
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Expand All @@ -52,9 +53,9 @@ public static Connection getConnection(int index){
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}

LOG.error("The mo-tester still can not get valid conneciton from mo, the following cases wil not be executed!");
//}
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], the following cases wil not be executed!");
server_up = false;
return null;
}
Expand All @@ -64,7 +65,7 @@ public static Connection getConnection(int index, String userName, String pwd){
if(!server_up) return null;

//get db connection,if failed,retry 3 times 10 s interval
for(int i = 0; i < 3; i++) {
//for(int i = 0; i < 3; i++) {
try {
Class.forName(driver);
if (connections[index] == null || connections[index].isClosed()) {
Expand All @@ -74,7 +75,8 @@ public static Connection getConnection(int index, String userName, String pwd){
}
return connections[index];
} catch (SQLException e) {
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], and will wait 10 seconds and retry...");
//LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], and will wait 10 seconds and retry...");
LOG.error(e.getMessage());
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Expand All @@ -83,9 +85,9 @@ public static Connection getConnection(int index, String userName, String pwd){
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//}

LOG.error("The mo-tester still can not get valid conneciton from mo, the following cases wil not be executed!");
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], the following cases wil not be executed!");
server_up = false;
return null;
}
Expand All @@ -95,15 +97,15 @@ public static Connection getConnectionForSys(){
if(!server_up) return null;

//get db connection,if failed,retry 3 times 10 s interval
for(int i = 0; i < 3; i++) {
//for(int i = 0; i < 3; i++) {
try {
Class.forName(driver);
if (sysconn == null || sysconn.isClosed()) {
sysconn = DriverManager.getConnection(jdbcURL, sysuser, syspass);
}
return sysconn;
} catch (SQLException e) {
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"] for sys user, and will wait 10 seconds and retry...");
//LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"] for sys user, and will wait 10 seconds and retry...");
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
Expand All @@ -112,9 +114,9 @@ public static Connection getConnectionForSys(){
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//}

LOG.error("The mo-tester still can not get valid conneciton from mo for sys user, the following cases wil not be executed!");
LOG.error("The mo-tester can not get valid conneciton from mo with[user="+userName+", pwd="+pwd+"], the following cases wil not be executed!");
server_up = false;
return null;
}
Expand Down

0 comments on commit 13aab79

Please sign in to comment.