You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2024/01/25 05:25:40 UTC

(doris) 25/37: [regression test](framework) add waitFor action (#30289)

This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 49f879f8fdab3727ae8d5d09295fbeb7117f0b46
Author: Guangdong Liu <li...@gmail.com>
AuthorDate: Wed Jan 24 23:21:15 2024 +0800

    [regression test](framework) add waitFor action (#30289)
---
 .../doris/regression/action/WaitForAction.groovy   | 70 +++++++++++++++
 .../org/apache/doris/regression/suite/Suite.groovy |  5 ++
 .../framework/src/main/groovy/suite.gdsl           |  4 +-
 .../test_alter_table_column.groovy                 | 99 +++++-----------------
 4 files changed, 101 insertions(+), 77 deletions(-)

diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/WaitForAction.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/WaitForAction.groovy
new file mode 100644
index 00000000000..90732ec0c53
--- /dev/null
+++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/action/WaitForAction.groovy
@@ -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)
+                }
+            }
+        }
+    }
+}
diff --git a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
index 41a99abe7a7..9f38ab5ed0c 100644
--- a/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
+++ b/regression-test/framework/src/main/groovy/org/apache/doris/regression/suite/Suite.groovy
@@ -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
@@ -474,6 +475,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
diff --git a/regression-test/framework/src/main/groovy/suite.gdsl b/regression-test/framework/src/main/groovy/suite.gdsl
index da55904de87..aec43ab51a1 100644
--- a/regression-test/framework/src/main/groovy/suite.gdsl
+++ b/regression-test/framework/src/main/groovy/suite.gdsl
@@ -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]) {
@@ -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)
diff --git a/regression-test/suites/schema_change_p0/test_alter_table_column.groovy b/regression-test/suites/schema_change_p0/test_alter_table_column.groovy
index 4ac796f19ea..713b9cd3b28 100644
--- a/regression-test/suites/schema_change_p0/test_alter_table_column.groovy
+++ b/regression-test/suites/schema_change_p0/test_alter_table_column.groovy
@@ -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} (
@@ -42,41 +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" || res == "CANCELLED") {
-            assertEquals("FINISHED", res)
-            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" || res == "CANCELLED") {
-            assertEquals("FINISHED", res)
-            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;"
@@ -101,20 +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" || res == "CANCELLED") {
-            assertEquals("FINISHED", res)
-            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"
@@ -146,22 +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" || res == "CANCELLED") {
-            assertEquals("FINISHED", res)
-            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;"
@@ -238,21 +193,13 @@ 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" || res == "CANCELLED") {
-            assertEquals("FINISHED", res)
-            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)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org