Skip to content

Commit 820d263

Browse files
authored
Merge pull request #2 from dataroaring/test
let framework support sql cases
2 parents af64f72 + 7b92f13 commit 820d263

2 files changed

Lines changed: 63 additions & 47 deletions

File tree

‎regression-test/framework/src/main/groovy/org/apache/doris/regression/RegressionTest.groovy‎

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
17-
1817
package org.apache.doris.regression
1918

2019
import groovy.transform.CompileStatic
@@ -32,6 +31,7 @@ import java.util.stream.Collectors
3231
@Slf4j
3332
@CompileStatic
3433
class RegressionTest {
34+
3535
static ClassLoader classloader
3636
static CompilerConfiguration compileConfig
3737
static GroovyShell shell
@@ -57,70 +57,91 @@ class RegressionTest {
5757

5858
static List<File> findSuiteFiles(String root) {
5959
if (root == null) {
60-
log.warn("Not specify suite path")
60+
log.warn('Not specify suite path')
6161
return new ArrayList<File>()
6262
}
6363
List<File> files = new ArrayList<>()
64+
// 1. generate groovy for sql
6465
new File(root).eachFileRecurse { f ->
65-
if (f.isFile() && f.name.endsWith(".groovy")) {
66+
if (f.isFile() && f.name.endsWith('.sql')) {
67+
genetate_groovy_from_sql(f)
68+
}
69+
}
70+
71+
// 2. collect groovy files.
72+
new File(root).eachFileRecurse { f ->
73+
if (f.isFile() && f.name.endsWith('.groovy')) {
6674
files.add(f)
6775
}
6876
}
6977
return files
7078
}
7179

80+
static void genetate_groovy_from_sql(File f) {
81+
File groovy_file = new File(f.getAbsolutePath() + '.generated.groovy')
82+
groovy_file.delete()
83+
groovy_file.createNewFile()
84+
int separatorIndex = f.name.lastIndexOf('.')
85+
String action_name = f.name.substring(0, separatorIndex)
86+
groovy_file.text = "qt_${action_name} \"\"\"${f.text}\"\"\""
87+
}
88+
7289
static String parseGroup(Config config, File suiteFile) {
7390
String group = new File(config.suitePath).relativePath(suiteFile)
7491
int separatorIndex = group.lastIndexOf(File.separator)
7592
if (separatorIndex == -1) {
76-
return ""
93+
return ''
7794
} else {
7895
return group.substring(0, separatorIndex)
7996
}
8097
}
8198

99+
static void runSuite(Config config, SuiteFile sf, Recorder recorder) {
100+
File file = sf.file
101+
String suiteName = sf.suiteName
102+
String group = sf.group
103+
def suiteConn = config.getConnection()
104+
new SuiteContext(file, suiteConn, config, recorder).withCloseable { context ->
105+
try {
106+
log.info("Run ${suiteName} in $file".toString())
107+
Suite suite = shell.parse(file) as Suite
108+
suite.init(suiteName, group, context)
109+
suite.run()
110+
recorder.onSuccess(new SuiteInfo(file, group, suiteName))
111+
log.info("Run ${suiteName} in ${file.absolutePath} succeed".toString())
112+
} catch (Throwable t) {
113+
recorder.onFailure(new SuiteInfo(file, group, suiteName))
114+
log.error("Run ${suiteName} in ${file.absolutePath} failed".toString(), t)
115+
}
116+
}
117+
}
118+
82119
static Recorder runSuites(Config config) {
83120
def files = findSuiteFiles(config.suitePath)
84121
def recorder = new Recorder()
85122
List<SuiteFile> runScripts = files.stream().map({ file ->
86-
String suiteName = file.name.substring(0, file.name.lastIndexOf("."))
123+
String suiteName = file.name.substring(0, file.name.lastIndexOf('.'))
87124
String group = parseGroup(config, file)
88125
return new SuiteFile(file, suiteName, group)
89126
}).filter({ sf ->
90127
canRun(config, sf.suiteName, sf.group)
91128
}).collect(Collectors.toList())
92129

93-
log.info("Start to run suites")
130+
log.info('Start to run suites')
94131
int totalFile = runScripts.size()
95132
runScripts.eachWithIndex { sf, i ->
96-
File file = sf.file
97-
String suiteName = sf.suiteName
98-
String group = sf.group
99-
def suiteConn = config.getConnection()
100-
new SuiteContext(file, suiteConn, config, recorder).withCloseable { context ->
101-
try {
102-
log.info("[${i + 1}/${totalFile}] Run ${suiteName} in $file".toString())
103-
Suite suite = shell.parse(file) as Suite
104-
suite.init(suiteName, group, context)
105-
suite.run()
106-
recorder.onSuccess(new SuiteInfo(file, group, suiteName))
107-
log.info("Run ${suiteName} in ${file.absolutePath} succeed".toString())
108-
} catch (Throwable t) {
109-
recorder.onFailure(new SuiteInfo(file, group, suiteName))
110-
log.error("Run ${suiteName} in ${file.absolutePath} failed".toString(), t)
111-
}
112-
}
133+
log.info("[${i + 1}/${totalFile}] Run ${sf.suiteName} in ${sf.file}".toString())
134+
runSuite(config, sf, recorder)
113135
}
114136
return recorder
115137
}
116138

117139
static boolean canRun(Config config, String suiteName, String group) {
118-
Set<String> suiteGroups = group.split(",").collect {g -> g.trim()}.toSet()
140+
Set<String> suiteGroups = group.split(',').collect { g -> g.trim() }.toSet()
119141
if (config.suiteWildcard.size() == 0 ||
120142
(suiteName != null && (config.suiteWildcard.any {
121143
suiteWildcard -> Wildcard.match(suiteName, suiteWildcard)
122144
}))) {
123-
124145
if (config.groups == null || config.groups.isEmpty()
125146
|| !config.groups.intersect(suiteGroups).isEmpty()) {
126147
return true
@@ -138,44 +159,45 @@ class RegressionTest {
138159
{
139160
String successList = recorder.successList.collect { info ->
140161
"${info.file.absolutePath}: group=${info.group}, name=${info.suiteName}"
141-
}.join("\n")
162+
}.join('\n')
142163
log.info("successList suites:\n${successList}".toString())
143164
}
144165

145166
// print failure list
146167
if (!recorder.failureList.isEmpty()) {
147168
def failureList = recorder.failureList.collect() { info ->
148169
"${info.file.absolutePath}: group=${info.group}, name=${info.suiteName}"
149-
}.join("\n")
170+
}.join('\n')
150171
log.info("Failure suites:\n${failureList}".toString())
151172
printFailed()
152-
throw new IllegalStateException("Test failed")
173+
throw new IllegalStateException('Test failed')
153174
} else {
154175
printPassed()
155176
}
156177
}
157178

158179
static void printPassed() {
159-
log.info("""All suites success.
160-
| ____ _ ____ ____ _____ ____
161-
|| _ \\ / \\ / ___/ ___|| ____| _ \\
180+
log.info('''All suites success.
181+
| ____ _ ____ ____ _____ ____
182+
|| _ \\ / \\ / ___/ ___|| ____| _ \\
162183
|| |_) / _ \\ \\___ \\___ \\| _| | | | |
163184
|| __/ ___ \\ ___) |__) | |___| |_| |
164-
||_| /_/ \\_\\____/____/|_____|____/
165-
|""".stripMargin())
185+
||_| /_/ \\_\\____/____/|_____|____/
186+
|'''.stripMargin())
166187
}
167188

168189
static void printFailed() {
169-
log.info("""Some suites failed.
170-
| _____ _ ___ _ _____ ____
171-
|| ___/ \\ |_ _| | | ____| _ \\
190+
log.info('''Some suites failed.
191+
| _____ _ ___ _ _____ ____
192+
|| ___/ \\ |_ _| | | ____| _ \\
172193
|| |_ / _ \\ | || | | _| | | | |
173194
|| _/ ___ \\ | || |___| |___| |_| |
174-
||_|/_/ \\_\\___|_____|_____|____/
175-
|""".stripMargin())
195+
||_|/_/ \\_\\___|_____|_____|____/
196+
|'''.stripMargin())
176197
}
177198

178199
static class SuiteFile {
200+
179201
File file
180202
String suiteName
181203
String group
@@ -185,5 +207,7 @@ class RegressionTest {
185207
this.suiteName = suiteName
186208
this.group = group
187209
}
210+
188211
}
212+
189213
}

‎regression-test/suites/tpcds/tpcds.groovy‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,4 @@ for (String table_name in tables) {
7171
assertTrue(json.NumberLoadedRows > 0 && json.LoadBytes > 0)
7272
}
7373
}
74-
}
75-
76-
def baseDir = new File("""${scriptDir}/sql""")
77-
files = baseDir.listFiles().sort{ it.name }
78-
79-
for (String file in files) {
80-
logger.info(file)
81-
qt_tpcds new File(file).text
82-
}
74+
}

0 commit comments

Comments
 (0)