Skip to content

Commit

Permalink
add tag to support not checking designated columns
Browse files Browse the repository at this point in the history
  • Loading branch information
aressu1985 committed Nov 12, 2023
1 parent 41a2934 commit 6686c16
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 5 deletions.
Binary file modified lib/mo-tester-1.0-SNAPSHOT.jar
Binary file not shown.
10 changes: 9 additions & 1 deletion src/main/java/io/mo/cases/SqlCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class SqlCommand {
private ArrayList<Integer> sortKeyIndexs = new ArrayList<>();

private ArrayList<String> syscmds = new ArrayList<>();

private ArrayList<Integer> ignoreColumns = new ArrayList<>();

private TestResult testResult;
private StmtResult expResult;
Expand Down Expand Up @@ -293,5 +295,11 @@ public void setWaitOperation(String waitOperation) {
this.waitOperation = waitOperation;
}


public ArrayList<Integer> getIgnoreColumns(){
return this.ignoreColumns;
}

public void addIgnoreColumn(int id){
this.ignoreColumns.add(id);
}
}
2 changes: 2 additions & 0 deletions src/main/java/io/mo/constant/COMMON.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class COMMON {

//if result is type of error, and not unique, can use this flag to regular match
public static String REGULAR_MATCH_FLAG = "-- @pattern";

public static String IGNORE_COLUMN_FLAG = "-- @ignore:";

public static String LOG_DIR = "log";
public static String RESULT_DIR = "result";
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/mo/db/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ public static void run(TestScript script){
}
ResultSet resultSet = statement.getResultSet();
if (resultSet != null) {
RSSet rsSet = new RSSet(resultSet);
RSSet rsSet = new RSSet(resultSet,command);
StmtResult actResult = new StmtResult(rsSet);
command.setActResult(actResult);
command.getTestResult().setActResult(actResult.toString());

StmtResult expResult = command.getExpResult();
expResult.setCommand(command);
expResult.setType(RESULT.STMT_RESULT_TYPE_SET);
expResult.setRsSet(ResultParser.convertToRSSet(expResult.getOrginalRSText(), command.getSeparator()));
command.getTestResult().setExpResult(expResult.toString());

} else {
StmtResult actResult = new StmtResult();
actResult.setType(RESULT.STMT_RESULT_TYPE_NONE);
Expand Down Expand Up @@ -382,7 +384,7 @@ public static boolean genRS(TestScript script){
}
ResultSet resultSet = statement.getResultSet();
if(resultSet != null){
RSSet rsSet = new RSSet(resultSet);
RSSet rsSet = new RSSet(resultSet,command);
StmtResult actResult = new StmtResult(rsSet);
actResult.setCommand(command);
rs_writer.write(command.getCommand().trim());
Expand Down Expand Up @@ -502,7 +504,7 @@ public static void genRSForOnlyNotMatch(TestScript script){
statement.execute(sqlCmd);
ResultSet resultSet = statement.getResultSet();
if (resultSet != null) {
RSSet rsSet = new RSSet(resultSet);
RSSet rsSet = new RSSet(resultSet,command);
StmtResult actResult = new StmtResult(rsSet);
command.setActResult(actResult);
command.getTestResult().setActResult(actResult.toString());
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/mo/result/RSCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ public class RSCell<T> {
private int precision = 0; //column value precision,remain attr
private static Logger LOG = Logger.getLogger(RSCell.class.getName());

public boolean isNeedcheck() {
return needcheck;
}

public void setNeedcheck(boolean needcheck) {
this.needcheck = needcheck;
}

private boolean needcheck = true;

public T getValue() {
return value;
}
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/io/mo/result/RSRow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.mo.result;

import io.mo.cases.SqlCommand;
import io.mo.constant.RESULT;
import org.apache.log4j.Logger;

Expand All @@ -12,6 +13,17 @@ public class RSRow {
private String separator = RESULT.COLUMN_SEPARATOR_SPACE;

private int index = 0;//the row index in the RSSet

public SqlCommand getCommand() {
return command;
}

public void setCommand(SqlCommand command) {
this.command = command;
}

private SqlCommand command;

private static Logger LOG = Logger.getLogger(RSRow.class.getName());

public RSRow(int colCount){
Expand Down Expand Up @@ -59,8 +71,14 @@ public boolean equals(RSRow rsRow){

//Or,compare each values
for(int i = 0; i < cells.size(); i++){

RSCell ct = cells.get(i);

RSCell cc = rsRow.getRowValues().get(i);

if(!ct.isNeedcheck() || !cc.isNeedcheck()) {
continue;
}
if(!ct.equals(cc)){
LOG.error("The value of [row:" + index + ",column:" + i + "] does not equal with each other,one is ["+ct.toString()+"],but the other is ["+cc.toString()+"]");
return false;
Expand Down
35 changes: 34 additions & 1 deletion src/main/java/io/mo/result/RSSet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.mo.result;

import io.mo.cases.SqlCommand;
import io.mo.constant.COMMON;
import io.mo.constant.RESULT;
import org.apache.log4j.Logger;
Expand All @@ -21,13 +22,26 @@ public class RSSet {

private String separator = RESULT.COLUMN_SEPARATOR_SPACE;

private ArrayList<Integer> ignoreColumns = new ArrayList<>();

public SqlCommand getCommand() {
return command;
}

public void setCommand(SqlCommand command) {
this.command = command;
}

private SqlCommand command;

private static Logger LOG = Logger.getLogger(RSSet.class.getName());

public RSSet(){

}

public RSSet(ResultSet resultSet){
public RSSet(ResultSet resultSet,SqlCommand command){
this.command = command;
ResultSetMetaData md = null;
StringBuffer result = new StringBuffer();
try {
Expand All @@ -44,6 +58,16 @@ public RSSet(ResultSet resultSet){
RSRow rsRow = new RSRow(cols);
for(int j = 0; j < cols; ++j) {
RSCell rsCell = new RSCell<String>();
if(this.command!=null && this.command.getIgnoreColumns().size() != 0){
if(this.command.getIgnoreColumns().contains(new Integer(j))){
LOG.debug(String.format("[%s][row:%d][%s] The column[%d] does not need to be check.",
command.getScriptFile(),
command.getPosition(),
command.getCommand(),
j));
rsCell.setNeedcheck(false);
}
}
String value = resultSet.getString(j + 1);
if(value == null)
value = "null";
Expand Down Expand Up @@ -150,6 +174,7 @@ public boolean equals(RSSet set){
}

for(int i = 0; i < rows.size();i++){

if(!this.rows.get(i).equals(set.getRows().get(i))){
return false;
}
Expand All @@ -172,6 +197,14 @@ public void setSeparator(String separator) {
}
}

public ArrayList<Integer> getIgnoreColumns(){
return this.ignoreColumns;
}

public void addIgnoreColumn(int id){
this.ignoreColumns.add(id);
}

public String toString(){
if(this.abnormalError != null)
return abnormalError;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/mo/result/StmtResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.log4j.Logger;
import org.apache.xmlbeans.impl.xb.xsdschema.PatternDocument;

import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -28,6 +29,7 @@ public class StmtResult {

private static Logger LOG = Logger.getLogger(StmtResult.class.getName());


public StmtResult(String errorMessage){
this.type = RESULT.STMT_RESULT_TYPE_ERROR;
this.errorMessage = errorMessage;
Expand All @@ -36,6 +38,7 @@ public StmtResult(String errorMessage){
public StmtResult(RSSet rsSet){
this.rsSet = rsSet;
if(this.command != null) {
this.rsSet.setCommand(command);
if (command.getSeparator().equals("both") || command.getSeparator().equals("space"))
this.rsSet.setSeparator(RESULT.COLUMN_SEPARATOR_SPACE);
else
Expand Down Expand Up @@ -149,6 +152,7 @@ public void setRsSet(RSSet rsSet) {

this.rsSet = rsSet;
if(this.command != null) {
this.rsSet.setCommand(this.command);
if (command.getSeparator().equals("both") || command.getSeparator().equals("space"))
this.rsSet.setSeparator(RESULT.COLUMN_SEPARATOR_SPACE);
else
Expand Down Expand Up @@ -177,6 +181,7 @@ public SqlCommand getCommand() {
public void setCommand(SqlCommand command) {
this.command = command;
if(this.rsSet != null) {
this.rsSet.setCommand(command);
if (command.getSeparator().equals("both") || command.getSeparator().equals("space"))
this.rsSet.setSeparator(RESULT.COLUMN_SEPARATOR_SPACE);
else
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/io/mo/util/ScriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ public static void parseScript(String path){
command.setRegularMatch(true);
}

if(trimmedLine.startsWith(COMMON.IGNORE_COLUMN_FLAG)){
String ignores = trimmedLine.substring(COMMON.IGNORE_COLUMN_FLAG.length());
if(ignores != null || !ignores.equalsIgnoreCase("")){
String[] ignore_ids = ignores.split(",");
for(int i = 0; i < ignore_ids.length;i++){
command.addIgnoreColumn(Integer.parseInt(ignore_ids[i]));
}
}
}

//if line is mark to set wait paras
if(trimmedLine.startsWith(COMMON.WAIT_FLAG)){
String[] items = trimmedLine.split(":");
Expand Down

0 comments on commit 6686c16

Please sign in to comment.