Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Op bug mod wait lock #150

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified lib/mo-tester-1.0-SNAPSHOT.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/io/mo/db/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
70 changes: 60 additions & 10 deletions src/main/java/io/mo/db/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -125,6 +128,25 @@ public static void run(TestScript script){
execWaitOperation(command);
}
statement.execute(sqlCmd);
Thread.sleep(COMMON.WAIT_TIMEOUT/10);
if(command.isNeedWait()){
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);
Expand Down Expand Up @@ -229,6 +251,8 @@ public static void run(TestScript script){
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}

Expand Down Expand Up @@ -331,6 +355,25 @@ public static boolean genRS(TestScript script){
execWaitOperation(command);
}
statement.execute(sqlCmd);
Thread.sleep(COMMON.WAIT_TIMEOUT/10);
if(command.isNeedWait()){
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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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")) {
Expand All @@ -658,28 +705,31 @@ 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();
else {
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) {
throw new RuntimeException(e);
}
}
}
}).start();
});
waitThread.start();
}

public static void main(String[] args){
Expand Down
Loading