tmq_taosx.py 9.0 KB
Newer Older
wmmhello's avatar
wmmhello 已提交
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:
18
    def init(self, conn, logSql, replicaVar=1):
19
        self.replicaVar = int(replicaVar)
wmmhello's avatar
wmmhello 已提交
20 21 22 23
        tdLog.debug(f"start to excute {__file__}")
        tdSql.init(conn.cursor())
        #tdSql.init(conn.cursor(), logSql)  # output sql.txt file

24 25 26
    def checkJson(self, cfgPath, name):
        srcFile = '%s/../log/%s.source'%(cfgPath, name)
        dstFile = '%s/../log/%s.result'%(cfgPath, name)
wmmhello's avatar
wmmhello 已提交
27 28 29 30 31 32 33 34
        tdLog.info("compare file: %s, %s"%(srcFile, dstFile))

        consumeFile = open(srcFile, mode='r')
        queryFile = open(dstFile, mode='r')

        while True:
            dst = queryFile.readline()
            src = consumeFile.readline()
35
            if src:
wmmhello's avatar
wmmhello 已提交
36
                if dst != src:
37
                    tdLog.exit("compare error: %s != %s"%(src, dst))
wmmhello's avatar
wmmhello 已提交
38 39
            else:
                break
40 41
        return

42
    def checkDropData(self, drop):
43 44
        tdSql.execute('use db_taosx')
        tdSql.query("show tables")
45 46 47 48
        if drop:
            tdSql.checkRows(10)
        else:
            tdSql.checkRows(15)
49 50 51 52 53 54 55
        tdSql.query("select * from jt order by i")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(1, 1, 11)
        tdSql.checkData(0, 2, '{"k1":1,"k2":"hello"}')
        tdSql.checkData(1, 2, None)

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
        tdSql.query("select * from sttb order by ts")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 13)
        tdSql.checkData(1, 1, 16)
        tdSql.checkData(0, 2, 22)
        tdSql.checkData(1, 2, 25)
        tdSql.checkData(0, 5, "sttb3")
        tdSql.checkData(1, 5, "sttb4")

        tdSql.query("select * from stt order by ts")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(1, 1, 21)
        tdSql.checkData(0, 2, 2)
        tdSql.checkData(1, 2, 21)
        tdSql.checkData(0, 5, "stt3")
        tdSql.checkData(1, 5, "stt4")

74 75
        tdSql.execute('use abc1')
        tdSql.query("show tables")
76 77 78 79
        if drop:
            tdSql.checkRows(10)
        else:
            tdSql.checkRows(15)
80 81 82 83 84 85
        tdSql.query("select * from jt order by i")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(1, 1, 11)
        tdSql.checkData(0, 2, '{"k1":1,"k2":"hello"}')
        tdSql.checkData(1, 2, None)
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

        tdSql.query("select * from sttb order by ts")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 13)
        tdSql.checkData(1, 1, 16)
        tdSql.checkData(0, 2, 22)
        tdSql.checkData(1, 2, 25)
        tdSql.checkData(0, 5, "sttb3")
        tdSql.checkData(1, 5, "sttb4")

        tdSql.query("select * from stt order by ts")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(1, 1, 21)
        tdSql.checkData(0, 2, 2)
        tdSql.checkData(1, 2, 21)
        tdSql.checkData(0, 5, "stt3")
        tdSql.checkData(1, 5, "stt4")

        return

    def checkDataTable(self):
        tdSql.execute('use db_taosx')
        tdSql.query("select * from meters_summary")
        tdSql.checkRows(1)
        tdSql.checkData(0, 1, 120)
        tdSql.checkData(0, 2, 1)
        tdSql.checkData(0, 3, "San Francisco")

        tdSql.execute('use abc1')
        tdSql.query("select * from meters_summary")
        tdSql.checkRows(1)
        tdSql.checkData(0, 1, 120)
        tdSql.checkData(0, 2, 1)
        tdSql.checkData(0, 3, "San Francisco")

122
        return
wmmhello's avatar
wmmhello 已提交
123

124
    def checkData(self):
wmmhello's avatar
wmmhello 已提交
125
        tdSql.execute('use db_taosx')
126
        tdSql.query("select * from ct3 order by c1 desc")
wmmhello's avatar
wmmhello 已提交
127 128 129 130 131 132
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 51)
        tdSql.checkData(0, 4, 940)
        tdSql.checkData(1, 1, 23)
        tdSql.checkData(1, 4, None)

wmmhello's avatar
wmmhello 已提交
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
        tdSql.query("select * from st1 order by ts")
        tdSql.checkRows(8)
        tdSql.checkData(0, 1, 1)
        tdSql.checkData(1, 1, 3)
        tdSql.checkData(4, 1, 4)
        tdSql.checkData(6, 1, 23)

        tdSql.checkData(0, 2, 2)
        tdSql.checkData(1, 2, 4)
        tdSql.checkData(4, 2, 3)
        tdSql.checkData(6, 2, 32)

        tdSql.checkData(0, 3, 'a')
        tdSql.checkData(1, 3, 'b')
        tdSql.checkData(4, 3, 'hwj')
        tdSql.checkData(6, 3, 's21ds')

        tdSql.checkData(0, 4, None)
        tdSql.checkData(1, 4, None)
        tdSql.checkData(5, 4, 940)
        tdSql.checkData(6, 4, None)

        tdSql.checkData(0, 5, 1000)
        tdSql.checkData(1, 5, 2000)
        tdSql.checkData(4, 5, 1000)
        tdSql.checkData(6, 5, 5000)

        tdSql.checkData(0, 6, 'ttt')
        tdSql.checkData(1, 6, None)
        tdSql.checkData(4, 6, 'ttt')
        tdSql.checkData(6, 6, None)

        tdSql.checkData(0, 7, True)
        tdSql.checkData(1, 7, None)
        tdSql.checkData(4, 7, True)
        tdSql.checkData(6, 7, None)

        tdSql.checkData(0, 8, None)
        tdSql.checkData(1, 8, None)
        tdSql.checkData(4, 8, None)
        tdSql.checkData(6, 8, None)

        tdSql.query("select * from ct1")
        tdSql.checkRows(4)

        tdSql.query("select * from ct2")
        tdSql.checkRows(0)

        tdSql.query("select * from ct0 order by c1")
        tdSql.checkRows(2)
        tdSql.checkData(0, 3, "a")
        tdSql.checkData(1, 4, None)

        tdSql.query("select * from n1 order by cc3 desc")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, "eeee")
        tdSql.checkData(1, 2, 940)

        tdSql.query("select * from jt order by i desc")
        tdSql.checkRows(2)
        tdSql.checkData(0, 1, 11)
        tdSql.checkData(0, 2, None)
        tdSql.checkData(1, 1, 1)
        tdSql.checkData(1, 2, '{"k1":1,"k2":"hello"}')
197 198 199 200 201

        tdSql.query("select * from information_schema.ins_tables where table_name = 'stt4'")
        uid1 = tdSql.getData(0, 5)
        uid2 = tdSql.getData(1, 5)
        tdSql.checkNotEqual(uid1, uid2)
wmmhello's avatar
wmmhello 已提交
202 203
        return

204
    def checkWal1Vgroup(self):
wmmhello's avatar
wmmhello 已提交
205 206
        buildPath = tdCom.getBuildPath()
        cfgPath = tdCom.getClientCfgPath()
207
        cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1'%(buildPath, cfgPath)
wmmhello's avatar
wmmhello 已提交
208 209 210
        tdLog.info(cmdStr)
        os.system(cmdStr)

211 212
        self.checkJson(cfgPath, "tmq_taosx_tmp")
        self.checkData()
213 214 215 216 217 218 219 220 221 222 223 224 225
        self.checkDropData(False)

        return

    def checkWal1VgroupTable(self):
        buildPath = tdCom.getBuildPath()
        cfgPath = tdCom.getClientCfgPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1 -t'%(buildPath, cfgPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)

        self.checkJson(cfgPath, "tmq_taosx_tmp")
        self.checkDataTable()
wmmhello's avatar
wmmhello 已提交
226

227
        return
wmmhello's avatar
wmmhello 已提交
228

229 230 231 232 233
    def checkWalMultiVgroups(self):
        buildPath = tdCom.getBuildPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -sv 3 -dv 5'%(buildPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)
wmmhello's avatar
wmmhello 已提交
234

235
        self.checkData()
236
        self.checkDropData(False)
wmmhello's avatar
wmmhello 已提交
237

238
        return
wmmhello's avatar
wmmhello 已提交
239

240 241 242 243 244
    def checkWalMultiVgroupsWithDropTable(self):
        buildPath = tdCom.getBuildPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -sv 3 -dv 5 -d'%(buildPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)
wmmhello's avatar
wmmhello 已提交
245

246
        self.checkDropData(True)
wmmhello's avatar
wmmhello 已提交
247

248
        return
wmmhello's avatar
wmmhello 已提交
249

250 251 252 253 254 255
    def checkSnapshot1Vgroup(self):
        buildPath = tdCom.getBuildPath()
        cfgPath = tdCom.getClientCfgPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1 -s'%(buildPath, cfgPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)
wmmhello's avatar
wmmhello 已提交
256

257 258
        self.checkJson(cfgPath, "tmq_taosx_tmp_snapshot")
        self.checkData()
259 260 261 262 263 264 265 266 267 268 269 270 271
        self.checkDropData(False)

        return

    def checkSnapshot1VgroupTable(self):
        buildPath = tdCom.getBuildPath()
        cfgPath = tdCom.getClientCfgPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -c %s -sv 1 -dv 1 -s -t'%(buildPath, cfgPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)

        self.checkJson(cfgPath, "tmq_taosx_tmp_snapshot")
        self.checkDataTable()
wmmhello's avatar
wmmhello 已提交
272

273
        return
wmmhello's avatar
wmmhello 已提交
274

275 276 277 278 279
    def checkSnapshotMultiVgroups(self):
        buildPath = tdCom.getBuildPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -sv 2 -dv 4 -s'%(buildPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)
wmmhello's avatar
wmmhello 已提交
280

281
        self.checkData()
282
        self.checkDropData(False)
wmmhello's avatar
wmmhello 已提交
283

284
        return
wmmhello's avatar
wmmhello 已提交
285

286 287 288 289 290
    def checkSnapshotMultiVgroupsWithDropTable(self):
        buildPath = tdCom.getBuildPath()
        cmdStr = '%s/build/bin/tmq_taosx_ci -sv 2 -dv 4 -s -d'%(buildPath)
        tdLog.info(cmdStr)
        os.system(cmdStr)
wmmhello's avatar
wmmhello 已提交
291

292
        self.checkDropData(True)
wmmhello's avatar
wmmhello 已提交
293 294 295 296 297

        return

    def run(self):
        tdSql.prepare()
298 299 300
        self.checkWal1Vgroup()
        self.checkSnapshot1Vgroup()

301 302 303
        self.checkWal1VgroupTable()
        self.checkSnapshot1VgroupTable()

304 305 306 307 308
        self.checkWalMultiVgroups()
        self.checkSnapshotMultiVgroups()

        self.checkWalMultiVgroupsWithDropTable()
        self.checkSnapshotMultiVgroupsWithDropTable()
wmmhello's avatar
wmmhello 已提交
309 310 311 312 313 314 315

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

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