From fd2f619fee4dd470725455a1e639890386b8cb51 Mon Sep 17 00:00:00 2001 From: charles Date: Thu, 14 Dec 2023 17:15:01 +0800 Subject: [PATCH] add test case for show table distributed command by charles --- tests/parallel_test/cases.task | 1 + .../0-others/test_show_table_distributed.py | 77 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 tests/system-test/0-others/test_show_table_distributed.py diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index d0961830e4..eb77e74f71 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -243,6 +243,7 @@ e ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compress_tsz1.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compress_tsz2.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/view/non_marterial_view/test_view.py +,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/test_show_table_distributed.py ,,n,system-test,python3 ./test.py -f 0-others/compatibility.py ,,n,system-test,python3 ./test.py -f 0-others/tag_index_basic.py ,,n,system-test,python3 ./test.py -f 0-others/udfpy_main.py diff --git a/tests/system-test/0-others/test_show_table_distributed.py b/tests/system-test/0-others/test_show_table_distributed.py new file mode 100644 index 0000000000..c414f8ba88 --- /dev/null +++ b/tests/system-test/0-others/test_show_table_distributed.py @@ -0,0 +1,77 @@ +from itertools import product +import taos +import random +import time +from taos.tmq import * +from util.cases import * +from util.common import * +from util.log import * +from util.sql import * +from util.sqlset import * + + +class TDTestCase: + """This test case is used to veirfy show table distributed command""" + + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + # init the tdsql + tdSql.init(conn.cursor()) + self.dbname = "distributed_db" + self.stname = "st" + self.ctnum = 1 + self.row_num = 99 + + # create database + tdSql.execute(f'create database if not exists {self.dbname};') + tdSql.execute(f'use {self.dbname};') + # create super table + tdSql.execute(f'create table {self.dbname}.{self.stname} (ts timestamp, id int, temperature float) tags (name binary(20));') + # create child table + for i in range(self.ctnum): + tdSql.execute(f'create table ct_{str(i+1)} using {self.stname} tags ("name{str(i+1)}");') + # insert data + sql = f"insert into ct_{str(i+1)} values " + for j in range(self.row_num): + sql += f"(now+{j+1}s, {j+1}, {random.uniform(15, 30)}) " + sql += ";" + tdSql.execute(sql) + tdLog.debug("init finished") + + def checkRes(self, queryRes): + mem_rows_num = 0 + stt_rows_num = 0 + for item in queryRes: + if "Inmem_Rows=" in item[0]: + mem_rows_num = int(item[0].split("=")[1].split(" ")[0].replace("[", "").replace("]", "")) + tdLog.debug("mem_rows_num: %s" % mem_rows_num) + if "Stt_Rows=" in item[0]: + stt_rows_num = int(item[0].split("=")[2].replace("[", "").replace("]", "")) + tdLog.debug("stt_rows_num: %s" % stt_rows_num) + return mem_rows_num, stt_rows_num + + def run(self): + tdSql.query(f"show table distributed {self.stname};") + tdLog.debug(tdSql.queryResult) + mem_rows_num, stt_rows_num = self.checkRes(tdSql.queryResult) + tdLog.debug("mem_rows_num: %s, stt_rows_num: %s" % (mem_rows_num, stt_rows_num)) + assert(99 == mem_rows_num and 0 == stt_rows_num) + + tdSql.execute(f"flush database {self.dbname};") + time.sleep(1) + tdSql.query(f"show table distributed {self.stname};") + tdLog.debug(tdSql.queryResult) + mem_rows_num, stt_rows_num = self.checkRes(tdSql.queryResult) + tdLog.debug("mem_rows_num: %s, stt_rows_num: %s" % (mem_rows_num, stt_rows_num)) + assert(0 == mem_rows_num and 99 == stt_rows_num) + + def stop(self): + # remove the user + tdSql.execute(f'drop database {self.dbname};') + # close the connection + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase())