taosdemoTestTblAlt.py 4.2 KB
Newer Older
P
Ping Xiao 已提交
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
###################################################################
#           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 *
import threading
import time


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

        self.numberOfTables = 10
        self.numberOfRecords = 1000000

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    def getBuildPath(self):
        selfPath = os.path.dirname(os.path.realpath(__file__))

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

        for root, dirs, files in os.walk(projPath):
            if ("taosd" in files):
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
                    buildPath = root[:len(root) - len("/build/bin")]
                    break
        return buildPath

P
Ping Xiao 已提交
48
    def insertDataAndAlterTable(self, threadID):
49 50 51 52 53 54 55
        buildPath = self.getBuildPath()
        if (buildPath == ""):
            tdLog.exit("taosd not found!")
        else:
            tdLog.info("taosd found in %s" % buildPath)
        binPath = buildPath + "/build/bin/"

P
Ping Xiao 已提交
56
        if(threadID == 0):
57
            os.system("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT -m t" %
58
                      (binPath, self.numberOfTables, self.numberOfRecords))
P
Ping Xiao 已提交
59
        if(threadID == 1):
P
Ping Xiao 已提交
60
            time.sleep(2)
P
Ping Xiao 已提交
61
            print("use test")
62 63 64 65 66 67 68 69 70
            while True:
                try:
                    tdSql.execute("use test")
                    break
                except Exception as e:
                    tdLog.info("use database test failed")
                    time.sleep(1)
                    continue

P
Ping Xiao 已提交
71
            # check if all the tables have heen created
P
Ping Xiao 已提交
72
            while True:
73 74 75 76 77 78 79
                try:
                    tdSql.query("show tables")
                except Exception as e:
                    tdLog.info("show tables test failed")
                    time.sleep(1)
                    continue

P
Ping Xiao 已提交
80
                rows = tdSql.queryRows
P
Ping Xiao 已提交
81 82 83 84 85
                print("number of tables: %d" % rows)
                if(rows == self.numberOfTables):
                    break
                time.sleep(1)
            # check if there are any records in the last created table
P
Ping Xiao 已提交
86 87
            while True:
                print("query started")
88 89 90 91 92 93 94
                try:
                    tdSql.query("select * from test.t9")
                except Exception as e:
                    tdLog.info("select * test failed")
                    time.sleep(2)
                    continue

P
Ping Xiao 已提交
95
                rows = tdSql.queryRows
P
Ping Xiao 已提交
96
                print("number of records: %d" % rows)
P
Ping Xiao 已提交
97 98
                if(rows > 0):
                    break
99
                time.sleep(1)
100

101 102
            print("alter table test.meters add column col10 int")
            tdSql.execute("alter table test.meters add column col10 int")
103 104
            print("insert into test.t9 values (now, 1, 2, 3, 4, 0)")
            tdSql.execute("insert into test.t9 values (now, 1, 2, 3, 4, 0)")
P
Ping Xiao 已提交
105

106
    def run(self):
P
Ping Xiao 已提交
107 108 109 110 111
        tdSql.prepare()

        t1 = threading.Thread(target=self.insertDataAndAlterTable, args=(0, ))
        t2 = threading.Thread(target=self.insertDataAndAlterTable, args=(1, ))

112
        t1.start()
P
Ping Xiao 已提交
113 114 115 116
        t2.start()
        t1.join()
        t2.join()

117 118
        time.sleep(3)

P
Ping Xiao 已提交
119 120 121 122 123 124 125 126 127
        tdSql.query("select count(*) from test.meters")
        tdSql.checkData(0, 0, self.numberOfRecords * self.numberOfTables + 1)

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


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