taosdemoTestInsertShell.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
###################################################################
#           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
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *


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

27
    def getPath(self, tool="taosBenchmark"):
28 29 30 31 32 33 34 35 36
        selfPath = os.path.dirname(os.path.realpath(__file__))
        global cfgPath
        if ("community" in selfPath):
            projPath = selfPath[:selfPath.find("community")]
            cfgPath = projPath + "/community/sim/dnode1/cfg"
        else:
            projPath = selfPath[:selfPath.find("tests")]
            cfgPath = projPath + "/sim/dnode1/cfg"

37
        paths = []
38
        for root, dirs, files in os.walk(projPath):
39
            if ((tool) in files):
40 41
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
42
                    paths.append(os.path.join(root, tool))
43
                    break
44
        return paths[0]
45 46 47 48

    # def checkGerData():

    def run(self):
49 50 51 52
        binPath = self.getPath("taosBenchmark")
        print("%s" % cfgPath)
        if (binPath == ""):
            tdLog.exit("taosBenchmark not found!")
53
        else:
54
            tdLog.info("taosBenchmark found in %s" % binPath)
55 56

        tdLog.info("create super table")
57 58 59 60 61
        # create super table
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 4096 \
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test.  " %
            (binPath, cfgPath))
62 63 64 65 66 67 68 69 70 71 72 73
        tdSql.execute("use db1")
        tdSql.query("describe meters;")
        tdSql.checkRows(13)
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        tdLog.info("create general table -N ")
        tdSql.execute("drop database db1;")
74 75 76 77 78
        # create general table -N
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 4096 \
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -N " %
            (binPath, cfgPath))
79 80 81 82 83 84 85 86 87 88 89
        tdSql.execute("use db1")
        tdSql.query("describe `test.0`;")
        tdSql.checkRows(11)
        tdSql.error("select count(*) from meters")
        tdSql.error("select count(tbname) from meters")
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        tdLog.info("use diffrent interface stmt")
        tdSql.execute("drop database db1;")
        # use diffrent interface-stmt
90 91 92 93
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,BINARY\(4000\) -w 40 \
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I stmt " %
            (binPath, cfgPath))
94 95 96 97 98 99 100 101 102 103 104
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        tdLog.info("use diffrent interface rest")
        tdSql.execute("drop database db1;")
        # use diffrent interface -rest
105 106 107 108
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 4097 \
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I rest " %
            (binPath, cfgPath))
109 110 111 112 113 114 115 116 117 118 119
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        tdLog.info("use diffrent interface sml")
        tdSql.execute("drop database db1;")
        # use diffrent interface-sml
120 121 122 123
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 1024 \
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I sml " %
            (binPath, cfgPath))
124 125 126 127 128 129 130 131 132
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)

        tdLog.info("all data type")
        tdSql.execute("drop database db1;")
        # all data type-taosc
133
        os.system("%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 \
134
        -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY\(15\),NCHAR\(15\) -w 4096 \
135
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. " % (binPath, cfgPath))
136 137 138 139 140 141 142 143 144 145
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)
        tdLog.info("all data type")
        tdSql.execute("drop database db1;")
        # all data type-stmt
146
        os.system("%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 \
147
        -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY\(15\),NCHAR\(15\) -w 4096 \
148
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I stmt " % (binPath, cfgPath))
149 150 151 152 153 154 155 156 157
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        # all data type-rest
158
        os.system("%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 \
159
        -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY\(15\),NCHAR\(15\) -w 4096 \
160
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I rest " % (binPath, cfgPath))
161 162 163 164 165 166 167 168 169
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        # # all data type-rest
170
        # os.system("%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 \
171 172 173 174 175 176 177 178 179 180 181 182
        # -b INT,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY\(15\),NCHAR\(15\) -w 4096 \
        # -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. -I sml " % (binPath,cfgPath))
        # tdSql.execute("use db1")
        # tdSql.query("select count(*) from meters")
        # tdSql.checkData(0, 0, 1000)
        # tdSql.query("select count(tbname) from meters")
        # tdSql.checkData(0, 0, 10)
        # # tdSql.query("select count(*) from `test.0`")
        # # tdSql.checkData(0, 0, 100)

        tdLog.info("all data type and interlace rows")
        tdSql.execute("drop database db1;")
183 184
        # all data type
        os.system("%s -u root  -c %s -h localhost -P 6030 -d db3  -a 1 -l 10\
185
        -b INT,TIMESTAMP,BIGINT,FLOAT,DOUBLE,SMALLINT,TINYINT,BOOL,UINT,UBIGINT,UTINYINT,USMALLINT,BINARY\(15\),NCHAR\(15\) -w 4096\
186
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -B 1000  -M  -x -y -O 10 -R 100  -E  -m test.  " % (binPath, cfgPath))
187 188 189 190 191 192 193 194 195
        tdSql.execute("use db3")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        tdLog.info("all data type and too much para")
196 197
        tdLog.info(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 4096 \
198
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test.taosdemo -u root  -c %s -h \
199 200
        localhost -P 6030 -d db1  -a 1 -l 100 -b float,int,NCHAR\(15\) -w 4096   -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. " %
            (binPath, cfgPath, cfgPath))
201
        tdSql.execute("drop database db3;")
202 203 204
        # repeate parameters
        os.system(
            "%s -u root  -c %s -h localhost -P 6030 -d db1  -a 1 -l 10 -b float,int,NCHAR\(15\) -w 4096 \
205
        -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test.taosdemo -u root  -c %s -h \
206 207
        localhost -P 6030 -d db1  -a 1 -l 100 -b float,int,NCHAR\(15\) -w 4096   -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M  -x -y -O 10 -R 100  -E  -m test. " %
            (binPath, cfgPath, cfgPath))
208 209 210 211 212 213 214 215 216 217
        tdSql.execute("use db1")
        tdSql.query("select count(*) from meters")
        tdSql.checkData(0, 0, 1000)
        tdSql.query("select count(tbname) from meters")
        tdSql.checkData(0, 0, 10)
        tdSql.query("select count(*) from `test.0`")
        tdSql.checkData(0, 0, 100)

        # taosdemo error
        # too max length
218 219 220 221 222 223 224 225 226 227 228 229
        sql = "%s -u root -c %s -h localhost -P 6030 -d db1 -a 1 -l 10 -b float,int,NCHAR\(4096\) \
                -w 40 -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M -x -y -O 10 -R 100 -E -m test. -I taosc" % (binPath,
                                                                                                                cfgPath)
        tdLog.info("%s" % sql)
        assert os.system("%s" % sql) != 0

        # error password
        sql = "%s -u root -c %s -h localhost -P 6030 -p123 -d db1 -a 1 -l 10 -b float,int,NCHAR\(40\) \
        -w 40 -T 8 -i 10 -S 1000 -r 1000000 -t 10 -n 100 -M -x -y -O 10 -R 100 -E -m test. -I stmt" % (binPath,
                                                                                                       cfgPath)
        tdLog.info("%s" % sql)
        assert os.system("%s" % sql) != 0
230 231 232

        testcaseFilename = os.path.split(__file__)[-1]
        os.system("rm -rf ./insert_res*.txt*")
233
        os.system("rm -rf tools/taosdemoAllTest/%s.sql" % testcaseFilename)
234 235 236 237 238 239 240 241

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


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