taosdemoTestTblAlt.py 4.3 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):
P
Ping Xiao 已提交
57 58 59
            print("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT -m t" %
                      (binPath, self.numberOfTables, self.numberOfRecords))
            os.system("%staosdemo -y -t %d -n %d -b INT,INT,INT,INT" %
60
                      (binPath, self.numberOfTables, self.numberOfRecords))
P
Ping Xiao 已提交
61
        if(threadID == 1):
P
Ping Xiao 已提交
62
            time.sleep(2)
P
Ping Xiao 已提交
63
            print("use test")
64 65 66 67 68 69 70 71 72
            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 已提交
73
            # check if all the tables have heen created
P
Ping Xiao 已提交
74
            while True:
75 76 77 78 79 80 81
                try:
                    tdSql.query("show tables")
                except Exception as e:
                    tdLog.info("show tables test failed")
                    time.sleep(1)
                    continue

P
Ping Xiao 已提交
82
                rows = tdSql.queryRows
P
Ping Xiao 已提交
83 84 85 86 87
                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 已提交
88 89
            while True:
                print("query started")
90
                try:
P
Ping Xiao 已提交
91
                    tdSql.query("select * from test.d9")
92 93 94 95 96
                except Exception as e:
                    tdLog.info("select * test failed")
                    time.sleep(2)
                    continue

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

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

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

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

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

119 120
        time.sleep(3)

P
Ping Xiao 已提交
121 122 123 124 125 126 127 128 129
        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())
130
tdCases.addLinux(__file__, TDTestCase())