taoshellCheckCase.py 8.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
###################################################################
#           Copyright (c) 2016 by TAOS Technologies, Inc.
#                     All rights reserved.
#
#  This file is proprietary and confidential to TAOS Technologies.
#  No part of this file may be reproduced, stored, transmitted,
#  disclosed or used in any form or by any means other than as
#  expressly provided by the written permission from Jianhui Tao
#
###################################################################

# -*- coding: utf-8 -*-

import sys, shutil
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
import subprocess


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

    def getBuildPath(self) -> str:
        selfPath = os.path.dirname(os.path.realpath(__file__))

        if ("community" in selfPath):
            projPath = selfPath[:selfPath.find("community")]
        else:
            projPath = selfPath[:selfPath.find("tests")]

        for root, dirs, files in os.walk(projPath):
            if ("taosd" in files):
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
                    buildPath = root[:len(root) - len("/debug/build/bin")]
                    break
        return buildPath

    def check_coredump(self, res_log):
        build_path = self.getBuildPath() + "/debug/build/bin"
        cmd = build_path + "/" + "taos -d test -k 1  > res.txt 2>&1"
        print(res_log)
        out = subprocess.check_output(cmd, shell=True).decode("utf-8")
        print(out)

    def execute_cmd(self,cmd):
        out = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE).stderr.read().decode("utf-8")
        
        if out.find("error:") >=0:
            print(cmd)
            print(out)
        
            

    def run(self):
        tdSql.prepare()
        build_path = self.getBuildPath() + "/debug/build/bin"
        tdLog.info("====== check tables use taos -d  -k  ========")

        tdSql.execute("drop database if exists test")
        tdSql.execute("drop database if exists dumptest")
        tdSql.execute("create database if not exists test")
        # self.check_coredump("====== only create database test ==== ")

        tdSql.execute("use test")
        tdSql.execute("create stable st (ts timestamp , id int , val double , str binary(20) ) tags (ind int)")
        tdSql.execute("create table tb1 using st tags(1)")
        self.check_coredump("======= only create one table =======")

        tdSql.execute("create table tb2 using st tags(2)")
        tdSql.execute("create table tb3 using st tags(3)")
        # self.check_coredump("======= only create three table =======")

        tdSql.execute("create table tb4 using st tags(4)")
        tdSql.execute("create table tb5 using st tags(5)")
        self.check_coredump("======= only create five table =======")

        start_time = 1604298064000
        rows = 10
        tb_nums = 5
        tdLog.info("====== start insert rows ========")

        for i in range(1, tb_nums + 1):
            for j in range(rows):
                start_time += 10
                tdSql.execute(
                    "insert into tb%d values(%d, %d,%f,%s) " % (i, start_time, j, float(j), "'str" + str(j) + "'"))
        tdSql.query("select count(*) from st")
        tdSql.checkData(0, 0, 50)

        for i in range(1, tb_nums + 1):
            tdSql.execute("select * from test.tb%s" % (str(i)))

        tdLog.info("====== check taos -D filedir  ========")

        if not os.path.exists("./dumpdata"):
            os.mkdir("./dumpdata")
        else:
            shutil.rmtree("./dumpdata")
            os.mkdir("./dumpdata")

        os.system(build_path + "/" + "taosdump -D test -o ./dumpdata")
        sleep(2)
        os.system("cd ./dumpdata && mv dbs.sql tables.sql")
        os.system('sed -i "s/test/dumptest/g" `grep test -rl ./dumpdata`')
        os.system(build_path + "/" + "taos -D ./dumpdata")
        tdSql.query("select count(*) from dumptest.st")
        tdSql.checkData(0, 0, 50)

        tdLog.info("========test other file name about tables.sql========")
        os.system("rm -rf ./dumpdata/*")
        os.system(build_path + "/" + "taosdump -D test -o ./dumpdata")
        sleep(2)
        os.system("cd ./dumpdata && mv dbs.sql table.sql")
        os.system('sed -i "s/test/tt/g" `grep test -rl ./dumpdata`')
        os.system(build_path + "/" + "taos -D ./dumpdata")

        tdLog.info("====== check taos shell params  ========")

        tdLog.info("====== step 1 : insert data with some unicode ========")

        sqls = ["drop database if exists dbst",
                "create database dbst",
                "use dbst",
                "create stable dbst.st (ts timestamp , id int , val double , str binary(200) ,char nchar(200) ) tags (ind int)",
                "create table dbst.tb1 using dbst.st tags(1)",
                "create table dbst.tb2 using dbst.st tags(2)",
                "insert into dbst.tb1 values('2021-07-14T10:40:00.006+0800' , 1 , 1.0 , 'binary_1','中文-1') ",
                "insert into dbst.tb1 values('2021-07-14T10:40:00.006Z' , 1 , 1.0 , 'binary\\'1','中文?-1')",
                "insert into dbst.tb1 values('2021-07-14 10:40:00.000',1,1.0,'!@#¥%……&*', '中文12&%#@!*')",
                "insert into dbst.tb1 values(now ,1,1.0,'(){}[];./?&*\n', '中文&%#@!*34')",
                "insert into dbst.tb1 values(now ,1,1.0,'\\t\\0', '中文_\\t\\0')",
                # "insert into dbst.tb1 values(now ,1,1.0,'\t\"', '中文_\t\\')", 
                "CREATE STABLE dbst.stb (TS TIMESTAMP , ID INT , VAL DOUBLE , STR BINARY(200) ,CHAR NCHAR(200) ) TAGS (IND INT)",
                "CREATE TABLE dbst.tbb1 USING dbst.STB TAGS(1)",
                "CREATE TABLE dbst.tbb2 USING dbst.STB TAGS(2)",
                "INSERT INTO dbst.TBB1 VALUES('2021-07-14T10:40:00.006+0800' , 1 , 1.0 , 'BINARY_1','中文-1')",
                "INSERT INTO dbst.TBB1 VALUES('2021-07-14T10:40:00.006Z' , 1 , 1.0 , 'BINARY1','中文?-1')",
                "INSERT INTO dbst.TBB1 VALUES('2021-07-14 10:40:00.000',1,1.0,'!@#¥%……&*', '中文12&%#@!*');"]
        for sql in sqls:
            cmd = build_path + "/" + "taos -s \""+sql+"\"" 
            self.execute_cmd(cmd)
     
               
            
        basic_code = ['!' ,'#', '$', '%', '&', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1',
                      '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A',
                     'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q', 'R',
                     'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\',']' ,'^', '_', '`', 'a', 'b', 'c',
                    'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r','s', 't', 'u',
                     'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~']
        for code in basic_code:
            if not code=='\\':
                cmd = build_path + "/" + "taos -s \" insert into dbst.tb2 values(now ,2,2.0,'"+code+"','汉字"+code+"\')\"" 
            else:
                cmd =  build_path + "/" + "taos -s \" insert into dbst.tb2 values(now ,2,2.0," +r'"\\"'+",'中文"+r'\\'+ "')\""

            self.execute_cmd(cmd)
            
            
          
        tdLog.info("====== step 2 : query result of results ========")

        querys = ["select count(*) from dbst.tb2",
        "show dbst.tables",
        "show dbst.tables like tb_",
        "show dbst.tables like 't%'",
        "select * from dbst.stb",
        "select avg(val),max(id),min(id) from dbst.st ",
        "select last_row(*) from dbst.st",
        "select * from dbst.st where ts >'2021-07-14T10:40:00.006+0800' and ind = 1 ",
        "select max(val) from dbst.st where ts >'2021-07-14T10:40:00.006+0800' group by tbname",
        "select count(*) from dbst.st interval(1s) group by tbname",
        "show queries ",
        "show connections",
        "show functions",
        "select * from dbst.tb2 where str like 'a'",
        "select bottom(id, 3) from dbst.st; ",
        "select _block_dist() from dbst.st;",
        "select 5 from dbst.tb1;",
        "select id , val from dbst.st",
        "describe dbst.st",
        "alter stable dbst.st modify column str binary(205);" ]

        for query in querys:
            cmd = build_path + "/" + "taos -s \""+query+"\""
            self.execute_cmd(cmd)

    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())