Skip to content

Commit

Permalink
Add resource func (#101)
Browse files Browse the repository at this point in the history
* add func that mo can set resources dir and refer the resource dir by specified var in test script

* delete debug print
  • Loading branch information
aressu1985 authored Aug 31, 2022
1 parent 8a3e58d commit 3696027
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 25 deletions.
37 changes: 36 additions & 1 deletion cases/template.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,39 @@ min(int32) max(int32) max(int32) - 1
select min(int32),max(int32),max(int32)-1 from t1 group by a;
min(int32) max(int32) max(int32) - 1
-1 2147483647 2147483646
drop table t1;
drop table t1;
CREATE TABLE NATION (
N_NATIONKEY INTEGER NOT NULL,
N_NAME VARCHAR(25) NOT NULL,
N_REGIONKEY INTEGER NOT NULL,
N_COMMENT VARCHAR(152),
PRIMARY KEY (N_NATIONKEY)
);
load data infile '$resources/data/nation.tbl' into table nation FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
select * from nation;
n_nationkey n_name n_regionkey n_comment
0 ALGERIA 0 haggle. carefully final deposits detect slyly agai
1 ARGENTINA 1 al foxes promise slyly according to the regular accounts. bold requests alon
2 BRAZIL 1 y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special
3 CANADA 1 eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold
4 EGYPT 4 y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d
5 ETHIOPIA 0 ven packages wake quickly. regu
6 FRANCE 3 refully final requests. regular, ironi
7 GERMANY 3 l platelets. regular accounts x-ray: unusual, regular acco
8 INDIA 2 ss excuses cajole slyly across the packages. deposits print aroun
9 INDONESIA 2 slyly express asymptotes. regular deposits haggle slyly. carefully ironic hockey players sleep blithely. carefull
10 IRAN 4 efully alongside of the slyly final dependencies.
11 IRAQ 4 nic deposits boost atop the quickly final requests? quickly regula
12 JAPAN 2 ously. final, express gifts cajole a
13 JORDAN 4 ic deposits are blithely about the carefully regular pa
14 KENYA 0 pending excuses haggle furiously deposits. pending, express pinto beans wake fluffily past t
15 MOROCCO 0 rns. blithely bold courts among the closely regular packages use furiously bold platelets?
16 MOZAMBIQUE 0 s. ironic, unusual asymptotes wake blithely r
17 PERU 1 platelets. blithely pending dependencies use fluffily across the even pinto beans. carefully silent accoun
18 CHINA 2 c dependencies. furiously express notornis sleep slyly regular accounts. ideas sleep. depos
19 ROMANIA 3 ular asymptotes are about the furious multipliers. express dependencies nag above the ironically ironic account
20 SAUDI ARABIA 4 ts. silent requests haggle. closely express packages sleep across the blithely
21 VIETNAM 2 hely enticingly express accounts. even, final
22 RUSSIA 3 requests against the platelets use never according to the quickly regular pint
23 UNITED KINGDOM 3 eans boost carefully special requests. accounts are. carefull
24 UNITED STATES 1 y final packages. slow foxes cajole quickly. quickly silent platelets breach ironic accounts. unusual pinto be
11 changes: 10 additions & 1 deletion cases/template.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,13 @@ insert into t1 (int32) values (-1),(1234567890),(2147483647);
select * from t1 order by a desc, int32 asc;
select min(int32),max(int32),max(int32)-1 from t1;
select min(int32),max(int32),max(int32)-1 from t1 group by a;
drop table t1;
drop table t1;
CREATE TABLE NATION (
N_NATIONKEY INTEGER NOT NULL,
N_NAME VARCHAR(25) NOT NULL,
N_REGIONKEY INTEGER NOT NULL,
N_COMMENT VARCHAR(152),
PRIMARY KEY (N_NATIONKEY)
);
load data infile '$resources/data/nation.tbl' into table nation FIELDS TERMINATED BY '|' LINES TERMINATED BY '\n';
select * from nation;
Binary file modified lib/mo-tester-1.0-SNAPSHOT.jar
Binary file not shown.
25 changes: 25 additions & 0 deletions resources/data/nation.tbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
0|ALGERIA|0| haggle. carefully final deposits detect slyly agai|
1|ARGENTINA|1|al foxes promise slyly according to the regular accounts. bold requests alon|
2|BRAZIL|1|y alongside of the pending deposits. carefully special packages are about the ironic forges. slyly special |
3|CANADA|1|eas hang ironic, silent packages. slyly regular packages are furiously over the tithes. fluffily bold|
4|EGYPT|4|y above the carefully unusual theodolites. final dugouts are quickly across the furiously regular d|
5|ETHIOPIA|0|ven packages wake quickly. regu|
6|FRANCE|3|refully final requests. regular, ironi|
7|GERMANY|3|l platelets. regular accounts x-ray: unusual, regular acco|
8|INDIA|2|ss excuses cajole slyly across the packages. deposits print aroun|
9|INDONESIA|2| slyly express asymptotes. regular deposits haggle slyly. carefully ironic hockey players sleep blithely. carefull|
10|IRAN|4|efully alongside of the slyly final dependencies. |
11|IRAQ|4|nic deposits boost atop the quickly final requests? quickly regula|
12|JAPAN|2|ously. final, express gifts cajole a|
13|JORDAN|4|ic deposits are blithely about the carefully regular pa|
14|KENYA|0| pending excuses haggle furiously deposits. pending, express pinto beans wake fluffily past t|
15|MOROCCO|0|rns. blithely bold courts among the closely regular packages use furiously bold platelets?|
16|MOZAMBIQUE|0|s. ironic, unusual asymptotes wake blithely r|
17|PERU|1|platelets. blithely pending dependencies use fluffily across the even pinto beans. carefully silent accoun|
18|CHINA|2|c dependencies. furiously express notornis sleep slyly regular accounts. ideas sleep. depos|
19|ROMANIA|3|ular asymptotes are about the furious multipliers. express dependencies nag above the ironically ironic account|
20|SAUDI ARABIA|4|ts. silent requests haggle. closely express packages sleep across the blithely|
21|VIETNAM|2|hely enticingly express accounts. even, final |
22|RUSSIA|3| requests against the platelets use never according to the quickly regular pint|
23|UNITED KINGDOM|3|eans boost carefully special requests. accounts are. carefull|
24|UNITED STATES|1|y final packages. slow foxes cajole quickly. quickly silent platelets breach ironic accounts. unusual pinto be|
9 changes: 7 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [[ $# -eq 0 ]];then
echo "No parameters provided,the mo-tester will run with parameters defined in the run.yml file. "

fi
while getopts ":p:m:t:r:i:e:gnch" opt
while getopts ":p:m:t:r:i:e:s:gnch" opt
do
case $opt in
p)
Expand All @@ -31,6 +31,10 @@ do
EXCLUDE="exclude=${OPTARG}"
echo -e "Script files in the path which name contain one of the : {${OPTARG}} will be not executed"
;;
s)
RESOURCE="resource=${OPTARG}"
echo -e "Script files in the path which name contain one of the : {${OPTARG}} will be not executed"
;;
g)
IGNORE="ignore"
echo -e "SQL commands which is marked with ignore-flag will not be executed"
Expand All @@ -51,6 +55,7 @@ do
echo -e " -r set The success rate that test cases should reach"
echo -e " -i set the including list, and only script files in the path which name contain one of the list will be excuted,if more than one,seperated by ,"
echo -e " -e set the excluding list, and script files in the path which name contain one of the list will not be excuted,if more than one,seperated by ,"
echo -e " -s set the resource path that mo-tester use to store resources, and can be refered to $resources in test file"
echo -e " -g means SQL commands which is marked with [bvt:issue] flag will not be executed,this flag starts with [-- @bvt:issue#{issueNO.}],and ends with [-- @bvt:issue],eg:"
echo -e " -- @bvt:issue#3236"
echo -e " select date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE);"
Expand Down Expand Up @@ -85,7 +90,7 @@ done
java -Xms1024M -Xmx1024M -cp ${libJars} \
-Dconf.yml=${MO_YAML} \
-Drun.yml=${RUN_YAML} \
io.mo.Tester ${PATHC} ${METHOD} ${TYPE} ${RATE} ${INCLUDE} ${EXCLUDE} ${IGNORE} ${NOMETA} ${CHECK}
io.mo.Tester ${PATHC} ${METHOD} ${TYPE} ${RATE} ${INCLUDE} ${EXCLUDE} ${IGNORE} ${NOMETA} ${CHECK} ${RESOURCE}
}

boot
8 changes: 7 additions & 1 deletion src/main/java/io/mo/Tester.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ public static void main(String[] args){
String path = RunConfUtil.getPath();
String method = RunConfUtil.getMethod();
int rate = RunConfUtil.getRate();

COMMON.RESOURCE_PATH = RunConfUtil.getResourcePath();

//parse the paras
if(args != null){
for (String arg : args) {

//get path
if (arg.startsWith("path")) {
path = arg.split("=")[1];
Expand Down Expand Up @@ -59,6 +60,11 @@ public static void main(String[] args){
excludes = arg.split("=")[1].split(",");
}

//get resource path
if (arg.startsWith("resource")) {
COMMON.RESOURCE_PATH = arg.split("=")[1];
}

//get nometa info
if (arg.equalsIgnoreCase("nometa")) {
COMMON.IS_COMPARE_META = false;
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/io/mo/constant/COMMON.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

public class COMMON {

public static String[] RESOURCES_DIR = new String[]{"conf","cases","checkpoints","resources","result"};

public static String T_FILE_SUFFIX = ".sql";

//if IGNORE_MODEL is true,menas all of sql commands that are marked with bvt:issue tag will be not executed
Expand All @@ -30,14 +28,15 @@ public class COMMON {
public static String SORT_KEY_INDEX_FLAG = "-- @sortkey:";

public static String COLUMN_SEPARATOR_FLAG = "-- @separator:";
public static String RESOURCE_PATH_FLAG = "\\$resources";

public static String LOG_DIR = "log";
public static String RESULT_DIR = "result";
public static String CASES_DIR = "cases";
public static String REPORT_DIR = "report";
public static String RESOURCE_DIR = "resources";

public static String LOG_PATH = "log";
public static String RESULT_PATH = "result";
public static String TEST_PATH = "test";
public static String CASES_PATH = "cases";
public static String REPORT_PATH = "report";

public static String RESOURCE_PATH = "./resources";
public static String UPDATE_RESULT_TEMPLATE = "Query OK, {num} row affected";


Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/mo/db/Debugger.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Debugger {

public static void run(TestScript script){

initWriter(COMMON.LOG_PATH+"/","debug.log");
initWriter(COMMON.LOG_DIR +"/","debug.log");
ConnectionManager.reset();
boolean hasResults;
Statement statement;
Expand All @@ -28,7 +28,8 @@ public static void run(TestScript script){
connection = getConnection(command);
try{
statement = connection.createStatement();
statement.execute(command.getCommand());
String sqlCmd = command.getCommand().replaceAll(COMMON.RESOURCE_PATH_FLAG,COMMON.RESOURCE_PATH);
statement.execute(sqlCmd);
ResultSet resultSet = statement.getResultSet();
println("MySQL> "+command.getCommand());
if (resultSet == null) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/mo/db/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import org.apache.log4j.Logger;

import java.io.*;
import java.lang.reflect.Type;
import java.sql.*;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.regex.Pattern;

public class Executor {

Expand Down Expand Up @@ -89,7 +87,8 @@ public static void run(TestScript script){

try {
statement = connection.createStatement();
statement.execute(command.getCommand());
String sqlCmd = command.getCommand().replaceAll(COMMON.RESOURCE_PATH_FLAG,COMMON.RESOURCE_PATH);
statement.execute(sqlCmd);
ResultSet resultSet = statement.getResultSet();
if (resultSet != null) {
RSSet rsSet = new RSSet(resultSet);
Expand Down Expand Up @@ -230,7 +229,8 @@ public static boolean genRS(TestScript script){
connection = getConnection(command);
statement = connection.createStatement();

statement.execute(command.getCommand());
String sqlCmd = command.getCommand().replaceAll("\\$resources",COMMON.RESOURCE_PATH);
statement.execute(sqlCmd);
ResultSet resultSet = statement.getResultSet();
if(resultSet != null){
RSSet rsSet = new RSSet(resultSet);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/mo/result/TestReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class TestReport {
private int rate = 0;

public TestReport(){
File dir = new File(COMMON.REPORT_PATH);
File dir = new File(COMMON.REPORT_DIR);
if(!dir.exists())
dir.mkdir();

Expand All @@ -42,9 +42,9 @@ public void writeTXTReport(){

ArrayList<SqlCommand> e_commands = new ArrayList<SqlCommand>();
try {
BufferedWriter r_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_PATH+"/report.txt"));
BufferedWriter e_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_PATH+"/error.txt"));
BufferedWriter s_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_PATH+"/success.txt"));
BufferedWriter r_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_DIR +"/report.txt"));
BufferedWriter e_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_DIR +"/error.txt"));
BufferedWriter s_writer = new BufferedWriter(new FileWriter(COMMON.REPORT_DIR +"/success.txt"));
r_writer.write(getReportSummaryTXT(totalCmds, successCmds, failedCmds, ignoredCmds, abnormalCmds));
LOG.info(getReportSummaryTXT(totalCmds, successCmds, failedCmds, ignoredCmds, abnormalCmds).trim());

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/mo/util/ResultParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void parse(TestScript script){
rsFilePath = script.getFileName().replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
resFile = new File(rsFilePath);
if(!resFile.exists()){
rsFilePath = script.getFileName().replaceFirst(COMMON.CASES_PATH,COMMON.RESULT_PATH).replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
rsFilePath = script.getFileName().replaceFirst(COMMON.CASES_DIR,COMMON.RESULT_DIR).replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
resFile = new File(rsFilePath);
if(!resFile.exists()){
LOG.warn("The result of the test script file["+rsFilePath+"] does not exists,please check and this test script file will be skipped.");
Expand Down Expand Up @@ -170,7 +170,7 @@ public static void check(TestScript script){
rsFilePath = script.getFileName().replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
resFile = new File(rsFilePath);
if(!resFile.exists()){
rsFilePath = script.getFileName().replaceFirst(COMMON.CASES_PATH,COMMON.RESULT_PATH).replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
rsFilePath = script.getFileName().replaceFirst(COMMON.CASES_DIR,COMMON.RESULT_DIR).replaceAll("\\.[A-Za-z]+",COMMON.R_FILE_SUFFIX);
resFile = new File(rsFilePath);
if(!resFile.exists()){
LOG.warn("The result of the test script file["+rsFilePath+"] does not exists,please check and this test script file will be skipped.");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/io/mo/util/RunConfUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package io.mo.util;

import io.mo.constant.COMMON;

import java.io.File;
import java.util.Map;

public class RunConfUtil {
Expand Down Expand Up @@ -27,6 +30,19 @@ public static int getRate(){
return (int)conf.get("rate");
}

public static String getResourcePath(){
if(conf == null) init();
String path = (String)conf.get("path");
File caseFile = new File(path);
String srcPath = null;
if(caseFile.getAbsolutePath().contains(COMMON.CASES_DIR)) {
srcPath = caseFile.getAbsolutePath();
srcPath = srcPath.replace(COMMON.CASES_DIR,COMMON.RESOURCE_DIR);
srcPath = srcPath.substring(0,srcPath.indexOf(COMMON.RESOURCE_DIR)+COMMON.RESOURCE_DIR.length());
}
return srcPath;
}

public static void main(String[] args){
System.out.println(getPath());
System.out.println(getMethod());
Expand Down

0 comments on commit 3696027

Please sign in to comment.