Skip to content

Commit

Permalink
[CUBRIDQA-1203] support '--+ server-message on' directive also in CCI…
Browse files Browse the repository at this point in the history
… tests (#671)

* removed an unused inner class MutiSqlEx
* minor: replace strncasecmp with startswithCI
* implement '--+ server-message on' directive
. print dbms_output buffer contents
. print error message as well as error code
* minor bugfix
* append a newline character also to the last line of a statement in order to get identical results via JDBC.
* send commit, rollback, savepoint statement to the server rather than using CCI APIs
* restored execution of COMMIT, ROLLBACK, and SAVEPOINT by CCI API
  • Loading branch information
hyunikn authored Jan 15, 2024
1 parent 1c1b63a commit 19b7c83
Show file tree
Hide file tree
Showing 2 changed files with 370 additions and 372 deletions.
230 changes: 1 addition & 229 deletions CTP/sql/src/com/navercorp/cubridqa/cqt/console/bo/ConsoleBO.java
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ private String executeSqlFile(Test test, CaseResult caseResult) {
test.setServerMessage("on");
// TODO: DBMS_OUTPUT.enable ()
Sql enableSql =
new Sql(connId, "CALL enable(20000)", null, true); // TODO: set
new Sql(connId, "CALL enable(50000)", null, true); // TODO: set
// size of
// enable
dao.execute(conn, enableSql, false);
Expand Down Expand Up @@ -1421,234 +1421,6 @@ public ProcessMonitor getProcessMonitor() {
return processMonitor;
}

/**
* this inner class created by anson cheung,it used for execute sql muti-thread
*
* @author Administrator
*/
class MutiSqlEx extends Thread {
private Test test;
private int index;

private CaseResult caseResult;

public void setTest(Test test) {
this.test = test;
}

public void setCaseResult(CaseResult caseResult) {
this.caseResult = caseResult;
}

public CaseResult getCaseResult() {
return caseResult;
}

private ConsoleBO bo;

public void setBo(ConsoleBO bo) {
this.bo = bo;
}

public MutiSqlEx(String name) {
super(name);
}

@Override
public void run() {
List<Connection> ConnList = new ArrayList<Connection>();
if (test == null
|| caseResult == null
|| processMonitor.getCurrentstate() == processMonitor.Status_Stoping
|| processMonitor.getCurrentstate() == processMonitor.Status_Stoping) {
return;
}
String caseFile = caseResult.getCaseFile();
StringBuilder result = new StringBuilder();
List<Sql> sqlList =
SQLParser.parseSqlFile(caseFile, test.getCodeset(), test.isNeedDebugHint());

String dbId = test.getDbId();
String connId = test.getConnId();
CubridConnection cubridConnection =
dao.getCubridConnection(dbId, connId, test.getType());

// check if CQT need check server status when start each file test
// executing
if (test.isNeedCheckServerStatus()) {
checkServerStatus(cubridConnection);
}

// set db charset for test
resetConnection(cubridConnection, test);

if (sqlList == null) {
return;
}
try {
test.setDbId(test.getDbId(caseFile));
long startTime = System.currentTimeMillis();
for (int k = 0; k < sqlList.size(); k++) {
if (processMonitor.getCurrentstate() == processMonitor.Status_Stoping
|| processMonitor.getCurrentstate() == processMonitor.Status_Stoping) {
return;
}
Sql sql = (Sql) sqlList.get(k);
if (sql == null) {
continue;
}

String script = sql.getScript();
// String dbId = test.getDbId();
// String connId = test.getConnId();
String ThreadConnId = connId;
String thisConnId = sql.getConnId();
if (!thisConnId.equals("") && !thisConnId.equals(connId)) {
ThreadConnId = thisConnId;
cubridConnection =
dao.getCubridConnection(dbId, ThreadConnId, index, test.getType());
resetConnection(cubridConnection, test);
}

cubridConnection.isAvlible();
Connection conn = cubridConnection.getConn();
ConnList.add(conn);
boolean isOn = isPropOn(TestUtil.AUTOCOMMIT, script);
boolean isOff = isPropOff(TestUtil.AUTOCOMMIT, script);
boolean isHoldCasOn = isPropOn(TestUtil.HOLDCAS, script);
boolean isHoldCasOff = isPropOff(TestUtil.HOLDCAS, script);
boolean isServerMessageOn = isPropOn(TestUtil.SERVER_MESSAGE, script);
boolean isServerMessageOff = isPropOff(TestUtil.SERVER_MESSAGE, script);

if (isOn) {
conn.setAutoCommit(isOn);
String message = "@" + test.getConnId() + ": autocommit " + isOn;
bo.onMessage("[THREAD:" + index + "]" + message);
} else if (isOff) {
conn.setAutoCommit(!isOff);
String message = "@" + test.getConnId() + ": autocommit " + !isOff;
bo.onMessage("[THREAD:" + index + "]" + message);
} else if (isHoldCasOn) {
try {
String message = "@" + test.getConnId() + ": hold cas " + isHoldCasOn;

Method method =
conn.getClass()
.getMethod("setCASChangeMode", new Class[] {int.class});
method.invoke(
conn, new Object[] {CUBRIDConnection.CAS_CHANGE_MODE_KEEP});

bo.onMessage("--- hold cas -- " + isHoldCasOn);
} catch (Exception e) {
String message =
"Exception: the current version can't support hold cas!";
bo.onMessage(message);
}
} else if (isHoldCasOff) {
try {
String message = "@" + test.getConnId() + ": hold cas " + isHoldCasOff;
Method method =
conn.getClass()
.getMethod("setCASChangeMode", new Class[] {int.class});
method.invoke(
conn, new Object[] {CUBRIDConnection.CAS_CHANGE_MODE_AUTO});
bo.onMessage("--- hold cas -- " + isHoldCasOff);
} catch (Exception e) {
String message =
"Exception: the current version can't support hold cas!";
bo.onMessage(message);
}
} else if (isServerMessageOn) {
try {
String message =
"@"
+ test.getConnId()
+ ": server message "
+ isServerMessageOn;
bo.onMessage(message);

Sql enableSql =
new Sql(
connId,
"CALL DBMS_OUTPUT.enable(20000)",
null,
true); // TODO: set
// size of
// enable
dao.execute(conn, enableSql, false);
} catch (Exception e) {
String message =
"Exception: the current version can't support DBMS_OUTPUT!";
bo.onMessage(message);
}
} else if (isServerMessageOff) {
try {
String message =
"@"
+ test.getConnId()
+ ": server message "
+ isServerMessageOff;
bo.onMessage(message);
Sql disableSql =
new Sql(connId, "CALL DBMS_OUTPUT.disable()", null, true);
dao.execute(conn, disableSql, false);
} catch (Exception e) {
String message =
"Exception: the current version can't support DBMS_OUTPUT!";
bo.onMessage(message);
}
} else {
// System.out.println("--- use default autocommit -- " +
// conn.getAutoCommit());
String message =
"@"
+ test.getDbId()
+ "/"
+ test.getConnId()
+ ":"
+ sql.getScript();
bo.onMessage("[THREAD:" + index + "]" + message);

// System.out.println ("script = " + sql.getScript());

dao.execute(conn, sql, caseResult.isPrintQueryPlan());
result.append("===================================================");
result.append(System.getProperty("line.separator"));
result.append(sql.getResult());
}

cubridConnection.free();
}
long totalTime = System.currentTimeMillis() - startTime;
caseResult.setTotalTime(totalTime);

} catch (Exception e) {

result.append(e.getMessage() + System.getProperty("line.separator"));

e.printStackTrace();
} finally {
caseResult.setResult(result.toString());
caseResult.setSiteRunTimes(test.getSiteRunTimes());
}
for (Connection conn : ConnList) {
try {
conn.commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
}

public int getIndex() {
return index;
}

public void setIndex(int index) {
this.index = index;
}
}

public Test getTest() {
return test;
}
Expand Down
Loading

0 comments on commit 19b7c83

Please sign in to comment.