commandline.py 11.0 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
###################################################################
#           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 os
import subprocess
import time

from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *


class TDTestCase:
    def caseDescription(self):
        '''
        [TD-11510] taosBenchmark test cases
        '''
        return

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

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    def getPath(self, tool="taosBenchmark"):
        selfPath = os.path.dirname(os.path.realpath(__file__))

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

        paths = []
        for root, dirs, files in os.walk(projPath):
            if ((tool) in files):
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
                    paths.append(os.path.join(root, tool))
                    break
        if (len(paths) == 0):
            tdLog.exit("taosBenchmark not found!")
            return
        else:
            tdLog.info("taosBenchmark found in %s" % paths[0])
            return paths[0]

56
    def run(self):
57
        binPath = self.getPath()
58
        cmd = "%s -F 7 -n 10 -t 2 -x -y -M -C -d newtest -l 5 -A binary,nchar\(31\) -b tinyint,binary\(23\),bool,nchar -w 29 -E -m $%%^*" %binPath
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
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("use newtest")
        tdSql.query("select count(*) from newtest.meters")
        tdSql.checkData(0, 0, 20)
        tdSql.query("describe meters")
        tdSql.checkRows(8)
        tdSql.checkData(0, 1, "TIMESTAMP")
        tdSql.checkData(1, 1, "TINYINT")
        tdSql.checkData(2, 1, "BINARY")
        tdSql.checkData(2, 2, 23)
        tdSql.checkData(3, 1, "BOOL")
        tdSql.checkData(4, 1, "NCHAR")
        tdSql.checkData(4, 2, 29)
        tdSql.checkData(5, 1, "INT")
        tdSql.checkData(6, 1, "BINARY")
        tdSql.checkData(6, 2, 29)
        tdSql.checkData(6, 3, "TAG")
        tdSql.checkData(7, 1, "NCHAR")
        tdSql.checkData(7, 2, 31)
        tdSql.checkData(7, 3, "TAG")
        tdSql.query("select tbname from meters where tbname like '$%^*%'")
        tdSql.checkRows(2)
        tdSql.execute("drop database if exists newtest")

84
        cmd = "%s -F 7 -n 10 -t 2 -y -M -I stmt" %binPath
85 86 87 88 89 90 91
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.query("select count(tbname) from test.meters")
        tdSql.checkData(0, 0, 2)
        tdSql.query("select count(*) from test.meters")
        tdSql.checkData(0, 0, 20)

92
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 2>&1 | grep sleep | wc -l" %binPath
93 94 95 96 97 98
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 2):
            tdLog.exit("expected sleep times 2, actual %d" % int(sleepTimes))

99
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 -r 1 2>&1 | grep sleep | wc -l" %binPath
100 101 102 103 104 105
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 3):
            tdLog.exit("expected sleep times 3, actual %d" % int(sleepTimes))

106
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 -I sml 2>&1 | grep sleep | wc -l" %binPath
107 108 109 110 111 112
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 2):
            tdLog.exit("expected sleep times 2, actual %d" % int(sleepTimes))

113
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 -r 1 -I sml 2>&1 | grep sleep | wc -l" %binPath
114 115 116 117 118 119
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 3):
            tdLog.exit("expected sleep times 3, actual %d" % int(sleepTimes))

120
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 -I stmt 2>&1 | grep sleep | wc -l" %binPath
121 122 123 124 125 126
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 2):
            tdLog.exit("expected sleep times 2, actual %d" % int(sleepTimes))

127
        cmd = "%s -n 3 -t 3 -B 2 -i 1 -G -y -T 1 -r 1 -I stmt 2>&1 | grep sleep | wc -l" %binPath
128 129 130 131 132 133
        sleepTimes = subprocess.check_output(cmd, shell=True).decode("utf-8")
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        if (int(sleepTimes) != 3):
            tdLog.exit("expected sleep times 3, actual %d" % int(sleepTimes))

134
        cmd = "%s -S 17 -n 3 -t 1 -y -x" %binPath
135 136 137 138 139
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.query("select last(ts) from test.meters")
        tdSql.checkData(0, 0 , "2017-07-14 10:40:00.034")

140
        cmd = "%s -N -I taosc -t 11 -n 11 -y -x -E" %binPath
141 142 143 144 145 146 147 148 149 150
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("use test")
        tdSql.query("show stables")
        tdSql.checkRows(0)
        tdSql.query("show tables")
        tdSql.checkRows(11)
        tdSql.query("select count(*) from `d10`")
        tdSql.checkData(0, 0, 11)

151
        cmd = "%s -N -I rest -t 11 -n 11 -y -x" %binPath
152 153 154 155 156 157 158 159 160 161
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("use test")
        tdSql.query("show stables")
        tdSql.checkRows(0)
        tdSql.query("show tables")
        tdSql.checkRows(11)
        tdSql.query("select count(*) from d10")
        tdSql.checkData(0, 0, 11)

162
        cmd = "%s -N -I stmt -t 11 -n 11 -y -x" %binPath
163 164 165 166 167 168 169 170 171 172
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("use test")
        tdSql.query("show stables")
        tdSql.checkRows(0)
        tdSql.query("show tables")
        tdSql.checkRows(11)
        tdSql.query("select count(*) from d10")
        tdSql.checkData(0, 0, 11)

173
        cmd = "%s -N -I sml -y" %binPath
174 175 176
        tdLog.info("%s" % cmd)
        assert(os.system("%s" % cmd) !=0 )

177
        cmd = "%s -n 1 -t 1 -y -b bool" %binPath
178 179 180 181 182 183
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "BOOL")

184
        cmd = "%s -n 1 -t 1 -y -b tinyint" %binPath
185 186 187 188 189 190
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "TINYINT")

191
        cmd = "%s -n 1 -t 1 -y -b utinyint" %binPath
192 193 194 195 196 197
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "TINYINT UNSIGNED")

198
        cmd = "%s -n 1 -t 1 -y -b smallint" %binPath
199 200 201 202 203 204
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "SMALLINT")

205
        cmd = "%s -n 1 -t 1 -y -b usmallint" %binPath
206 207 208 209 210 211
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "SMALLINT UNSIGNED")

212
        cmd = "%s -n 1 -t 1 -y -b int" %binPath
213 214 215 216 217 218
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "INT")

219
        cmd = "%s -n 1 -t 1 -y -b uint" %binPath
220 221 222 223 224 225
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "INT UNSIGNED")

226
        cmd = "%s -n 1 -t 1 -y -b bigint" %binPath
227 228 229 230 231 232
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "BIGINT")

233
        cmd = "%s -n 1 -t 1 -y -b ubigint" %binPath
234 235 236 237 238 239
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "BIGINT UNSIGNED")

240
        cmd = "%s -n 1 -t 1 -y -b timestamp" %binPath
241 242 243 244 245 246
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "TIMESTAMP")

247
        cmd = "%s -n 1 -t 1 -y -b float" %binPath
248 249 250 251 252 253
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "FLOAT")

254
        cmd = "%s -n 1 -t 1 -y -b double" %binPath
255 256 257 258 259 260
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "DOUBLE")

261
        cmd = "%s -n 1 -t 1 -y -b nchar" %binPath
262 263 264 265 266 267
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "NCHAR")

268
        cmd = "%s -n 1 -t 1 -y -b nchar\(7\)" %binPath
269 270 271 272 273 274
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "NCHAR")

275
        cmd = "%s -n 1 -t 1 -y -b binary" %binPath
276 277 278 279 280 281
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "BINARY")

282
        cmd = "%s -n 1 -t 1 -y -b binary\(7\)" %binPath
283 284 285 286 287 288
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(1, 1, "BINARY")

289
        cmd = "%s -n 1 -t 1 -y -A json\(7\)" %binPath
290 291 292 293 294 295
        tdLog.info("%s" % cmd)
        os.system("%s" % cmd)
        tdSql.execute("reset query cache")
        tdSql.query("describe test.meters")
        tdSql.checkData(4, 1, "JSON")

296
        cmd = "%s -n 1 -t 1 -y -b int,x" %binPath
297 298 299
        tdLog.info("%s" % cmd)
        assert(os.system("%s" % cmd) != 0)

300
        cmd = "%s -n 1 -t 1 -y -A int,json" %binPath
301 302 303 304 305 306 307 308 309 310 311 312 313
        tdLog.info("%s" % cmd)
        assert(os.system("%s" % cmd) != 0)




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


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