diff --git a/lib/mo-tester-1.0-SNAPSHOT.jar b/lib/mo-tester-1.0-SNAPSHOT.jar index 72c91dd6b..edcbb88f2 100644 Binary files a/lib/mo-tester-1.0-SNAPSHOT.jar and b/lib/mo-tester-1.0-SNAPSHOT.jar differ diff --git a/run.yml b/run.yml index 507c1240f..03cbf4893 100755 --- a/run.yml +++ b/run.yml @@ -17,4 +17,4 @@ builtindb: mo_catalog,mo_task,information_schema,mysql,system_metrics,system,que outfiles: json/export_1.csv,json/export_2.csv,into_outfile,into_outfile_2 #wait timeout -waittime: 5000 \ No newline at end of file +waittime: 2000 \ No newline at end of file diff --git a/src/main/java/io/mo/db/ConnectionManager.java b/src/main/java/io/mo/db/ConnectionManager.java index 734dc03ee..4ce4fb327 100755 --- a/src/main/java/io/mo/db/ConnectionManager.java +++ b/src/main/java/io/mo/db/ConnectionManager.java @@ -64,7 +64,7 @@ public static Connection getConnection(int index, String userName, String pwd){ Class.forName(driver); if (connections[index] == null || connections[index].isClosed()) { connections[index] = DriverManager.getConnection(jdbcURL, userName, pwd); - LOG.info("New conneciton from mo with[user="+userName+", pwd="+pwd+"] has been initialized."); + LOG.debug("New conneciton from mo with[user="+userName+", pwd="+pwd+"] has been initialized."); return connections[index]; } return connections[index]; diff --git a/src/main/java/io/mo/db/Executor.java b/src/main/java/io/mo/db/Executor.java index d4b1cc71b..07edd952e 100755 --- a/src/main/java/io/mo/db/Executor.java +++ b/src/main/java/io/mo/db/Executor.java @@ -18,6 +18,7 @@ public class Executor { private static final Logger LOG = Logger.getLogger(Executor.class.getName()); + private static Thread waitThread = null; /** * run test file function */ @@ -78,7 +79,7 @@ public static void run(TestScript script){ //if the the command is marked to ignore flag and the IGNORE_MODEL = true //skip the command directly if (COMMON.IGNORE_MODEL && command.isIgnore()) { - LOG.warn("Ignored sql command: [issue#" + command.getIssueNo() + "][" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "]"); + LOG.debug("Ignored sql command: [issue#" + command.getIssueNo() + "][" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "]"); script.addIgnoredCmd(command); command.getTestResult().setResult(RESULT.RESULT_TYPE_IGNORED); command.getTestResult().setErrorCode(RESULT.ERROR_CASE_IGNORE_CODE); @@ -108,7 +109,9 @@ public static void run(TestScript script){ } if(last_commit_id != command.getConn_id()){ - LOG.info(String.format("Connection id had been turned from %d to %d",last_commit_id,command.getConn_id())); + LOG.debug(String.format("[%s][row:%d][%s]Connection id had been turned from %d to %d", + command.getScriptFile(),command.getPosition(),command.getCommand(), + last_commit_id,command.getConn_id())); syncCommit(connection); } @@ -125,6 +128,25 @@ public static void run(TestScript script){ execWaitOperation(command); } statement.execute(sqlCmd); + if(command.isNeedWait()){ + Thread.sleep(COMMON.WAIT_TIMEOUT/10); + if(waitThread != null && waitThread.isAlive()){ + try { + LOG.error(String.format("Command[%s][row:%d] has been executed before connection[id=%d] commit.\nBut still need to wait for connection[id=%d] being committed", + command.getCommand(),command.getPosition(),command.getWaitConnId(),command.getWaitConnId())); + waitThread.join(); + script.addFailedCmd(command); + command.getTestResult().setErrorCode(RESULT.ERROR_CHECK_FAILED_CODE); + command.getTestResult().setErrorDesc(RESULT.ERROR_CHECK_FAILED_DESC); + command.getTestResult().setResult(RESULT.RESULT_TYPE_FAILED); + LOG.error("[" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "] was executed failed, con[id=" + + command.getConn_id()+", user=" +command.getConn_user()+", pwd="+command.getConn_pswd()+"]."); + continue; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } ResultSet resultSet = statement.getResultSet(); if (resultSet != null) { RSSet rsSet = new RSSet(resultSet); @@ -229,6 +251,8 @@ public static void run(TestScript script){ } catch (SQLException ex) { throw new RuntimeException(ex); } + } catch (InterruptedException e) { + throw new RuntimeException(e); } } @@ -331,6 +355,25 @@ public static boolean genRS(TestScript script){ execWaitOperation(command); } statement.execute(sqlCmd); + if(command.isNeedWait()){ + Thread.sleep(COMMON.WAIT_TIMEOUT/10); + if(waitThread != null && waitThread.isAlive()){ + try { + LOG.error(String.format("Command[%s][row:%d] has been executed before connection[id=%d] commit.\nBut still need to wait for connection[id=%d] being committed", + command.getCommand(),command.getPosition(),command.getWaitConnId(),command.getWaitConnId())); + waitThread.join(); + script.addFailedCmd(command); + command.getTestResult().setErrorCode(RESULT.ERROR_CHECK_FAILED_CODE); + command.getTestResult().setErrorDesc(RESULT.ERROR_CHECK_FAILED_DESC); + command.getTestResult().setResult(RESULT.RESULT_TYPE_FAILED); + LOG.error("[" + script.getFileName() + "][row:" + command.getPosition() + "][" + command.getCommand().trim() + "] was executed failed, con[id=" + + command.getConn_id()+", user=" +command.getConn_user()+", pwd="+command.getConn_pswd()+"]."); + continue; + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } ResultSet resultSet = statement.getResultSet(); if(resultSet != null){ RSSet rsSet = new RSSet(resultSet); @@ -385,6 +428,8 @@ public static boolean genRS(TestScript script){ if(j < commands.size() -1) rs_writer.newLine(); + } catch (InterruptedException e) { + throw new RuntimeException(e); } } rs_writer.newLine(); @@ -606,7 +651,7 @@ public static void syncCommit(Connection connection){ try { Statement statement = connection.createStatement(); statement.execute("select mo_ctl('cn','synccommit','')"); - LOG.info("select mo_ctl('cn','synccommit','') successfully."); + LOG.debug("select mo_ctl('cn','synccommit','') successfully."); } catch (SQLException e) { LOG.error("select mo_ctl('cn','synccommit','') failed. cause: " + e.getMessage()); } @@ -644,11 +689,13 @@ public static void executeSysCmd(String cmd){ } public static void execWaitOperation(SqlCommand command){ - new Thread(new Runnable() { + waitThread = new Thread(new Runnable() { @Override public void run() { if (command.isNeedWait()) { try { + LOG.info(String.format("Command[%s][row:%d] needs to wait connection[id:%d] %s", + command.getCommand(),command.getPosition(),command.getWaitConnId(),command.getWaitOperation())); Thread.sleep(COMMON.WAIT_TIMEOUT); Connection conn = ConnectionManager.getConnection(command.getWaitConnId()); if(command.getWaitOperation().equalsIgnoreCase("commit")) { @@ -658,10 +705,11 @@ public void run() { Statement statement = conn.createStatement(); statement.execute("commit"); } - - LOG.info(String.format("Connection[id=%d] has committed automatically.",command.getWaitConnId())); + + LOG.info(String.format("Connection[id=%d] has committed automatically,for command[%s][row:%d]", + command.getWaitConnId(),command.getCommand(),command.getPosition())); } - + if(command.getWaitOperation().equalsIgnoreCase("rollback")) { if(!conn.getAutoCommit()) conn.rollback(); @@ -669,9 +717,10 @@ public void run() { Statement statement = conn.createStatement(); statement.execute("rollback"); } - LOG.info(String.format("Connection[id=%d] has rollback automatically.",command.getWaitConnId())); + LOG.info(String.format("Connection[id=%d] has rollback automatically,for command[%s][row:%d]", + command.getWaitConnId(),command.getCommand(),command.getPosition())); } - + } catch (InterruptedException e) { throw new RuntimeException(e); } catch (SQLException e) { @@ -679,7 +728,8 @@ public void run() { } } } - }).start(); + }); + waitThread.start(); } public static void main(String[] args){ diff --git a/src/main/java/io/mo/result/StmtResult.java b/src/main/java/io/mo/result/StmtResult.java index 0c2a9310a..6c1f7f575 100644 --- a/src/main/java/io/mo/result/StmtResult.java +++ b/src/main/java/io/mo/result/StmtResult.java @@ -110,7 +110,10 @@ public boolean equals(StmtResult stmtResult){ } public boolean regularMatch(StmtResult stmtResult){ - + if(stmtResult.errorMessage == null || stmtResult.errorMessage.equalsIgnoreCase("")){ + LOG.error("NULL or EMPTY can not regularly match the expected result"); + return false; + } if(stmtResult.errorMessage.matches(this.errorMessage)) return true; else {