sml.py 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

import taos
import sys
import time
import socket
import os
import threading

from util.log import *
from util.sql import *
from util.cases import *
from util.dnodes import *
from util.common import *
sys.path.append("./7-tmq")
from tmqCommon import *

class TDTestCase:
wmmhello's avatar
wmmhello 已提交
18 19 20
    updatecfgDict = {'clientCfg': {'smlChildTableName': 'dataModelName', 'fqdn': 'localhost'}, 'fqdn': 'localhost'}
    print("===================: ", updatecfgDict)

21
    def init(self, conn, logSql, replicaVar=1):
22
        self.replicaVar = int(replicaVar)
23
        tdLog.debug(f"start to excute {__file__}")
H
Haojun Liao 已提交
24
        tdSql.init(conn.cursor(), True)
25 26
        #tdSql.init(conn.cursor(), logSql)  # output sql.txt file

wmmhello's avatar
wmmhello 已提交
27
    def checkContent(self, dbname="sml_db"):
wmmhello's avatar
wmmhello 已提交
28
        simClientCfg="%s/taos.cfg"%tdDnodes.getSimCfgPath()
29
        buildPath = tdCom.getBuildPath()
wmmhello's avatar
wmmhello 已提交
30 31
        cmdStr = '%s/build/bin/sml_test %s'%(buildPath, simClientCfg)
        print("cmdStr:", cmdStr)
32 33 34
        tdLog.info(cmdStr)
        ret = os.system(cmdStr)
        if ret != 0:
S
Shengliang Guan 已提交
35
            tdLog.info("sml_test ret != 0")
36

37
        tdSql.query(f"select * from ts3303.stb2")
C
cpwu 已提交
38 39
        # tdSql.execute('use sml_db')
        tdSql.query(f"select * from {dbname}.t_b7d815c9222ca64cdf2614c61de8f211")
40 41 42 43 44 45 46 47 48 49 50 51 52 53
        tdSql.checkRows(1)

        tdSql.checkData(0, 0, '2016-01-01 08:00:07.000')
        tdSql.checkData(0, 1, 2000)
        tdSql.checkData(0, 2, 200)
        tdSql.checkData(0, 3, 15)
        tdSql.checkData(0, 4, 24.5208)
        tdSql.checkData(0, 5, 28.09377)
        tdSql.checkData(0, 6, 428)
        tdSql.checkData(0, 7, 0)
        tdSql.checkData(0, 8, 304)
        tdSql.checkData(0, 9, 0)
        tdSql.checkData(0, 10, 25)

C
cpwu 已提交
54
        tdSql.query(f"select * from {dbname}.readings")
55 56
        tdSql.checkRows(9)

C
cpwu 已提交
57
        tdSql.query(f"select distinct tbname from {dbname}.readings")
58 59
        tdSql.checkRows(4)

C
cpwu 已提交
60
        tdSql.query(f"select * from {dbname}.t_0799064f5487946e5d22164a822acfc8 order by _ts")
61 62
        tdSql.checkRows(2)
        tdSql.checkData(0, 3, "kk")
wmmhello's avatar
wmmhello 已提交
63
        tdSql.checkData(1, 3, "")
64 65


C
cpwu 已提交
66
        tdSql.query(f"select distinct tbname from {dbname}.`sys.if.bytes.out`")
67 68
        tdSql.checkRows(2)

C
cpwu 已提交
69
        tdSql.query(f"select * from {dbname}.t_fc70dec6677d4277c5d9799c4da806da order by _ts")
70 71 72 73
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 1.300000000)
        tdSql.checkData(1, 1,13.000000000)

C
cpwu 已提交
74
        tdSql.query(f"select * from {dbname}.`sys.procs.running`")
75 76 77 78
        tdSql.checkRows(1)
        tdSql.checkData(0, 1, 42.000000000)
        tdSql.checkData(0, 2, "web01")

C
cpwu 已提交
79
        tdSql.query(f"select distinct tbname from {dbname}.`sys.cpu.nice`")
wmmhello's avatar
wmmhello 已提交
80
        tdSql.checkRows(3)
81

C
cpwu 已提交
82
        tdSql.query(f"select * from {dbname}.`sys.cpu.nice` order by _ts")
wmmhello's avatar
wmmhello 已提交
83 84 85
        tdSql.checkRows(4)
        tdSql.checkData(0, 1, 13.000000000)
        tdSql.checkData(0, 2, "web01")
wmmhello's avatar
wmmhello 已提交
86 87 88
        tdSql.checkData(0, 3, None)
        tdSql.checkData(0, 4, "lga")

wmmhello's avatar
wmmhello 已提交
89 90 91
        tdSql.checkData(1, 1, 9.000000000)
        tdSql.checkData(1, 2, "web02")
        tdSql.checkData(3, 3, "t1")
wmmhello's avatar
wmmhello 已提交
92
        tdSql.checkData(0, 4, "lga")
93

C
cpwu 已提交
94
        tdSql.query(f"select * from {dbname}.macylr")
wmmhello's avatar
wmmhello 已提交
95
        tdSql.checkRows(2)
wmmhello's avatar
wmmhello 已提交
96

wmmhello's avatar
wmmhello 已提交
97 98 99
        tdSql.query(f"select * from {dbname}.qelhxo")
        tdSql.checkRows(5)

C
cpwu 已提交
100
        tdSql.query(f"desc {dbname}.macylr")
wmmhello's avatar
wmmhello 已提交
101
        tdSql.checkRows(25)
102 103 104 105
        return

    def run(self):
        tdSql.prepare()
wmmhello's avatar
wmmhello 已提交
106
        self.checkContent()
107 108 109 110 111 112 113 114

    def stop(self):
        tdSql.close()
        tdLog.success(f"{__file__} successfully executed")


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