show.py 8.0 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
###################################################################
#           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 -*-

J
jiacy-jcy 已提交
14
import re
J
jiacy-jcy 已提交
15 16 17 18
from util.log import *
from util.cases import *
from util.sql import *
from util.common import *
J
jiacy-jcy 已提交
19
from util.sqlset import *
J
jiacy-jcy 已提交
20 21

class TDTestCase:
22
    def init(self, conn, logSql, replicaVar=1):
23
        self.replicaVar = int(replicaVar)
J
jiacy-jcy 已提交
24 25
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor())
J
jiacy-jcy 已提交
26
        self.setsql = TDSetSql()
J
jiacy-jcy 已提交
27 28 29
        self.ins_param_list = ['dnodes','mnodes','qnodes','cluster','functions','users','grants','topics','subscriptions','streams']
        self.perf_param = ['apps','connections','consumers','queries','transactions']
        self.perf_param_list = ['apps','connections','consumers','queries','trans']
J
jiacy-jcy 已提交
30
        self.dbname = "db"
haoranc's avatar
haoranc 已提交
31
        self.vgroups = 4
32 33
        self.stbname = f'`{tdCom.getLongName(5)}`'
        self.tbname = f'`{tdCom.getLongName(3)}`'
J
jiacy-jcy 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47
        self.db_param = {
            "database":f"{self.dbname}",
            "buffer":100,
            "cachemodel":"'none'",
            "cachesize":1,
            "comp":2,
            "maxrows":1000,
            "minrows":200,
            "pages":512,
            "pagesize":16,
            "precision":"'ms'",
            "replica":1,
            "wal_level":1,
            "wal_fsync_period":6000,
48 49 50
            "vgroups":self.vgroups,
            "stt_trigger":1,
            "tsdb_pagesize":16
J
jiacy-jcy 已提交
51
        }
J
jiacy-jcy 已提交
52
    def ins_check(self):
J
jiacy-jcy 已提交
53
        tdSql.prepare()
J
jiacy-jcy 已提交
54
        for param in self.ins_param_list:
J
jiacy-jcy 已提交
55 56
            if param.lower() == 'qnodes':
                tdSql.execute('create qnode on dnode 1')
J
jiacy-jcy 已提交
57 58 59 60 61
            tdSql.query(f'show {param}')
            show_result = tdSql.queryResult
            tdSql.query(f'select * from information_schema.ins_{param}')
            select_result = tdSql.queryResult
            tdSql.checkEqual(show_result,select_result)
J
jiacy-jcy 已提交
62
        tdSql.execute('drop database db')
J
jiacy-jcy 已提交
63
    def perf_check(self):
J
jiacy-jcy 已提交
64
        tdSql.prepare()
J
jiacy-jcy 已提交
65 66 67 68 69 70 71 72 73
        for param in range(len(self.perf_param_list)):
            tdSql.query(f'show {self.perf_param[param]}')
            if len(tdSql.queryResult) != 0:
                show_result = tdSql.queryResult[0][0]
                tdSql.query(f'select * from performance_schema.perf_{self.perf_param_list[param]}')
                select_result = tdSql.queryResult[0][0]
                tdSql.checkEqual(show_result,select_result)
            else :
                continue
J
jiacy-jcy 已提交
74 75 76 77 78 79 80 81 82 83
        tdSql.execute('drop database db')
    def set_stb_sql(self,stbname,column_dict,tag_dict):
        column_sql = ''
        tag_sql = ''
        for k,v in column_dict.items():
            column_sql += f"{k} {v}, "
        for k,v in tag_dict.items():
            tag_sql += f"{k} {v}, "
        create_stb_sql = f'create stable {stbname} ({column_sql[:-2]}) tags ({tag_sql[:-2]})'
        return create_stb_sql
G
Ganlin Zhao 已提交
84

J
jiacy-jcy 已提交
85 86 87 88
    def set_create_database_sql(self,sql_dict):
        create_sql = 'create'
        for key,value in sql_dict.items():
            create_sql += f' {key} {value}'
89
        return create_sql
G
Ganlin Zhao 已提交
90 91 92 93 94 95 96 97

    def show_create_sysdb_sql(self):
        sysdb_list = {'information_schema', 'performance_schema'}
        for db in sysdb_list:
          tdSql.query(f'show create database {db}')
          tdSql.checkEqual(f'{db}',tdSql.queryResult[0][0])
          tdSql.checkEqual(f'CREATE DATABASE `{db}`',tdSql.queryResult[0][1])

J
jiacy-jcy 已提交
98 99
    def show_create_sql(self):
        create_db_sql = self.set_create_database_sql(self.db_param)
100
        print(create_db_sql)
J
jiacy-jcy 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113
        tdSql.execute(create_db_sql)
        tdSql.query(f'show create database {self.dbname}')
        tdSql.checkEqual(self.dbname,tdSql.queryResult[0][0])
        for key,value in self.db_param.items():
            if key == 'database':
                continue
            else:
                param = f'{key} {value}'
                if param in tdSql.queryResult[0][1].lower():
                    tdLog.info(f'show create database check success with {key} {value}')
                    continue
                else:
                    tdLog.exit(f"show create database check failed with {key} {value}")
114 115 116
        tdSql.query('show vnodes 1')
        tdSql.checkRows(self.vgroups)
        tdSql.execute(f'use {self.dbname}')
G
Ganlin Zhao 已提交
117

J
jiacy-jcy 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
        column_dict = {
            '`ts`': 'timestamp',
            '`col1`': 'tinyint',
            '`col2`': 'smallint',
            '`col3`': 'int',
            '`col4`': 'bigint',
            '`col5`': 'tinyint unsigned',
            '`col6`': 'smallint unsigned',
            '`col7`': 'int unsigned',
            '`col8`': 'bigint unsigned',
            '`col9`': 'float',
            '`col10`': 'double',
            '`col11`': 'bool',
            '`col12`': 'varchar(20)',
            '`col13`': 'nchar(20)'
G
Ganlin Zhao 已提交
133

J
jiacy-jcy 已提交
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
        }
        tag_dict = {
            '`t1`': 'tinyint',
            '`t2`': 'smallint',
            '`t3`': 'int',
            '`t4`': 'bigint',
            '`t5`': 'tinyint unsigned',
            '`t6`': 'smallint unsigned',
            '`t7`': 'int unsigned',
            '`t8`': 'bigint unsigned',
            '`t9`': 'float',
            '`t10`': 'double',
            '`t11`': 'bool',
            '`t12`': 'varchar(20)',
            '`t13`': 'nchar(20)',
            '`t14`': 'timestamp'
G
Ganlin Zhao 已提交
150

J
jiacy-jcy 已提交
151
        }
J
jiacy-jcy 已提交
152
        create_table_sql = self.set_stb_sql(self.stbname,column_dict,tag_dict)
J
jiacy-jcy 已提交
153
        tdSql.execute(create_table_sql)
J
jiacy-jcy 已提交
154
        tdSql.query(f'show create stable {self.stbname}')
J
jiacy-jcy 已提交
155 156
        query_result = tdSql.queryResult
        tdSql.checkEqual(query_result[0][1].lower(),create_table_sql)
J
jiacy-jcy 已提交
157
        tdSql.execute(f'create table {self.tbname} using {self.stbname} tags(1,1,1,1,1,1,1,1,1.000000e+00,1.000000e+00,true,"abc","abc123",0)')
J
jiacy-jcy 已提交
158 159 160
        tag_sql = '('
        for tag_keys in tag_dict.keys():
            tag_sql += f'{tag_keys}, '
G
Ganlin Zhao 已提交
161
        tags = f'{tag_sql[:-2]})'
J
jiacy-jcy 已提交
162 163
        sql = f'create table {self.tbname} using {self.stbname} {tags} tags (1, 1, 1, 1, 1, 1, 1, 1, 1.000000e+00, 1.000000e+00, true, "abc", "abc123", 0)'
        tdSql.query(f'show create table {self.tbname}')
J
jiacy-jcy 已提交
164 165
        query_result = tdSql.queryResult
        tdSql.checkEqual(query_result[0][1].lower(),sql)
J
jiacy-jcy 已提交
166
        tdSql.execute(f'drop database {self.dbname}')
J
jiacy-jcy 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    def check_gitinfo(self):
        taosd_gitinfo_sql = ''
        tdSql.query('show dnode 1 variables')
        for i in tdSql.queryResult:
            if i[1].lower() == "gitinfo":
                taosd_gitinfo_sql = f"gitinfo: {i[2]}"
        taos_gitinfo_sql = ''
        tdSql.query('show local variables')
        for i in tdSql.queryResult:
            if i[0].lower() == "gitinfo":
                taos_gitinfo_sql = f"gitinfo: {i[1]}"
        taos_info = os.popen('taos -V').read()
        taos_gitinfo = re.findall("^gitinfo.*",taos_info,re.M)
        tdSql.checkEqual(taos_gitinfo_sql,taos_gitinfo[0])
        taosd_info = os.popen('taosd -V').read()
        taosd_gitinfo = re.findall("^gitinfo.*",taosd_info,re.M)
        tdSql.checkEqual(taosd_gitinfo_sql,taosd_gitinfo[0])
G
Ganlin Zhao 已提交
184

J
jiacy-jcy 已提交
185 186 187 188 189 190 191 192 193 194 195
    def show_base(self):
        for sql in ['dnodes','mnodes','cluster']:
            tdSql.query(f'show {sql}')
            print(tdSql.queryResult)
            tdSql.checkRows(1)
        tdSql.query('show grants')
        grants_info = tdSql.queryResult
        tdSql.query('show licences')
        licences_info = tdSql.queryResult
        tdSql.checkEqual(grants_info,licences_info)

J
jiacy-jcy 已提交
196
    def run(self):
J
update  
jiacy-jcy 已提交
197 198 199 200
        self.check_gitinfo()
        self.show_base()
        self.ins_check()
        self.perf_check()
J
jiacy-jcy 已提交
201
        self.show_create_sql()
G
Ganlin Zhao 已提交
202
        self.show_create_sysdb_sql()
J
jiacy-jcy 已提交
203 204 205 206 207 208 209

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

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