Skip to content

Commit

Permalink
[regression test](framework) add waitFor action (apache#30289) (apach…
Browse files Browse the repository at this point in the history
…e#38852)

pick from master apache#30289

Co-authored-by: Guangdong Liu <[email protected]>
  • Loading branch information
2 people authored and weixingyu12 committed Aug 14, 2024
1 parent b916db0 commit 8adcd99
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.regression.action

import groovy.util.logging.Slf4j
import org.apache.doris.regression.suite.SuiteContext
import org.apache.doris.regression.util.JdbcUtils
import org.junit.Assert

@Slf4j
class WaitForAction implements SuiteAction{
private String sql;
private long time;
SuiteContext context

WaitForAction(SuiteContext context) {
this.context = context
}

void sql(String sql) {
this.sql = sql
}

void sql(Closure<String> sql) {
this.sql = sql.call()
}

void time(long time) {
this.time = time
}

void time(Closure<Long> time) {
this.time = time.call()
}

@Override
void run() {
while (time--) {
log.info("sql is :\n${sql}")
def (result, meta) = JdbcUtils.executeToList(context.getConnection(), sql)
String res = result.get(0).get(9)
if (res == "FINISHED" || res == "CANCELLED") {
Assert.assertEquals("FINISHED", res)
sleep(3000)
break
} else {
Thread.sleep(2000)
if (time < 1) {
log.info("test timeout," + "state:" + res)
Assert.assertEquals("FINISHED",res)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import groovy.json.JsonSlurper
import com.google.common.collect.ImmutableList
import org.apache.doris.regression.Config
import org.apache.doris.regression.action.BenchmarkAction
import org.apache.doris.regression.action.WaitForAction
import org.apache.doris.regression.util.DataUtils
import org.apache.doris.regression.util.OutputUtils
import org.apache.doris.regression.action.CreateMVAction
Expand Down Expand Up @@ -492,6 +493,10 @@ class Suite implements GroovyInterceptable {
runAction(new BenchmarkAction(context), actionSupplier)
}

void waitForSchemaChangeDone(Closure actionSupplier) {
runAction(new WaitForAction(context), actionSupplier)
}

String getBrokerName() {
String brokerName = context.config.otherConfigs.get("brokerName")
return brokerName
Expand Down
4 changes: 3 additions & 1 deletion regression-test/framework/src/main/groovy/suite.gdsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ bindAction("explain", "org.apache.doris.regression.action.ExplainAction")
bindAction("streamLoad", "org.apache.doris.regression.action.StreamLoadAction")
bindAction("httpTest", "org.apache.doris.regression.action.HttpCliAction")
bindAction("benchmark", "org.apache.doris.regression.action.BenchmarkAction")
bindAction("waitForSchemaChangeDone", "org.apache.doris.regression.action.WaitForAction")

// bind qt_xxx and order_qt_xxx methods
contributor([suiteContext]) {
Expand Down Expand Up @@ -79,7 +80,8 @@ contributor([suiteContext]) {
(!enclosingCall("test") &&
!enclosingCall("explain") &&
!enclosingCall("streamLoad") &&
!enclosingCall("httpTest"))) {
!enclosingCall("httpTest") &&
!enclosingCall("waitForSchemaChangeDone"))) {
// bind other suite method and field
def suiteClass = findClass(suiteClassName)
delegatesTo(suiteClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
suite("test_alter_table_column") {
def tbName1 = "alter_table_column_dup"

def getJobState = { tableName ->
def jobStateResult = sql """ SHOW ALTER TABLE COLUMN WHERE IndexName='${tableName}' ORDER BY createtime DESC LIMIT 1 """
return jobStateResult[0][9]
}
sql "DROP TABLE IF EXISTS ${tbName1}"
sql """
CREATE TABLE IF NOT EXISTS ${tbName1} (
Expand All @@ -42,39 +38,21 @@ suite("test_alter_table_column") {
ADD COLUMN value3 VARCHAR(255) AFTER value2,
MODIFY COLUMN value2 INT AFTER value3;
"""
int max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tbName1)
if (res == "FINISHED") {
sleep(3000)
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}

waitForSchemaChangeDone {
sql """SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1"""
time 60
}
Thread.sleep(200)

sql """
ALTER TABLE ${tbName1}
ORDER BY(k1,k2,value1,value2,value3),
DROP COLUMN value3;
"""
max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tbName1)
if (res == "FINISHED") {
sleep(3000)
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}

waitForSchemaChangeDone {
sql """SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName1}' ORDER BY createtime DESC LIMIT 1"""
time 60
}

sql "SHOW ALTER TABLE COLUMN;"
Expand All @@ -99,19 +77,10 @@ suite("test_alter_table_column") {
ADD COLUMN k2 INT KEY AFTER k1,
ADD COLUMN value2 INT SUM AFTER value1;
"""
max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tbName2)
if (res == "FINISHED") {
sleep(3000)
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}

waitForSchemaChangeDone {
sql """SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName2}' ORDER BY createtime DESC LIMIT 1"""
time 60
}

sql "SHOW ALTER TABLE COLUMN"
Expand Down Expand Up @@ -143,21 +112,11 @@ suite("test_alter_table_column") {
ADD COLUMN value3 ARRAY<INT> AFTER value2,
ADD COLUMN value4 ARRAY<INT> NOT NULL DEFAULT '[]' AFTER value3;
"""
max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tbNameAddArray)
if (res == "FINISHED") {
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}

waitForSchemaChangeDone {
sql """SHOW ALTER TABLE COLUMN WHERE IndexName='${tbNameAddArray}' ORDER BY createtime DESC LIMIT 1"""
time 60
}

Thread.sleep(200)
qt_sql "desc ${tbNameAddArray};"
qt_sql "select * from ${tbNameAddArray} order by k1;"
sql "DROP TABLE ${tbNameAddArray} FORCE;"
Expand Down Expand Up @@ -234,20 +193,12 @@ suite("test_alter_table_column") {
check2_doris(res1, res2)

sql "alter table ${tbName3} add column v2 int sum NULL"
max_try_secs = 60
while (max_try_secs--) {
String res = getJobState(tbName3)
if (res == "FINISHED") {
sleep(3000)
break
} else {
Thread.sleep(2000)
if (max_try_secs < 1) {
println "test timeout," + "state:" + res
assertEquals("FINISHED",res)
}
}

waitForSchemaChangeDone {
sql """SHOW ALTER TABLE COLUMN WHERE IndexName='${tbName3}' ORDER BY createtime DESC LIMIT 1"""
time 60
}

def res3 = sql "select * from ${tbName3} order by k1"
def res4 = sql "select k1, k2, k3, null from baseall order by k1"
check2_doris(res3, res4)
Expand Down

0 comments on commit 8adcd99

Please sign in to comment.