taosdumpTest2.py 5.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
###################################################################
#           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 -*-

14
from logging.config import dictConfig
15 16 17 18 19 20
import sys
import os
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
21 22
import string
import random
23 24


25
class TDTestCase:
26

27 28 29 30 31 32
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)

        self.ts = 1601481600000
        self.numberOfTables = 1
33
        self.numberOfRecords = 150
34

35
    def getPath(self, tool="taosdump"):
36 37 38 39 40 41 42
        selfPath = os.path.dirname(os.path.realpath(__file__))

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

43
        paths = []
44
        for root, dirs, files in os.walk(projPath):
45
            if ((tool) in files):
46 47
                rootRealPath = os.path.dirname(os.path.realpath(root))
                if ("packaging" not in rootRealPath):
48
                    paths.append(os.path.join(root, tool))
49
                    break
50 51
        if (len(paths) == 0):
            return ""
52
        return paths[0]
53

54 55 56 57 58 59 60
    def generateString(self, length):
        chars = string.ascii_uppercase + string.ascii_lowercase
        v = ""
        for i in range(length):
            v += random.choice(chars)
        return v

61
    def run(self):
62 63 64 65
        if not os.path.exists("./taosdumptest/tmp"):
            os.makedirs("./taosdumptest/tmp")
        else:
            print("directory exists")
66
            os.system("rm -rf ./taosdumptest/tmp/*")
67

68 69 70 71 72 73 74 75 76 77 78
        tdSql.prepare()

        tdSql.execute("create table st(ts timestamp, c1 timestamp, c2 int, c3 bigint, c4 float, c5 double, c6 binary(8), c7 smallint, c8 tinyint, c9 bool, c10 nchar(8)) tags(t1 int)")
        tdSql.execute("create table t1 using st tags(0)")
        currts = self.ts
        finish = 0
        while(finish < self.numberOfRecords):
            sql = "insert into t1 values"
            for i in range(finish, self.numberOfRecords):
                sql += "(%d, 1019774612, 29931, 1442173978, 165092.468750, 1128.643179, 'MOCq1pTu', 18405, 82, 0, 'g0A6S0Fu')" % (currts + i)
                finish = i + 1
K
kailixu 已提交
79
                if (1048576 - len(sql)) < 65519:
80 81 82
                    break
            tdSql.execute(sql)

83 84
        binPath = self.getPath()
        if (binPath == ""):
85 86
            tdLog.exit("taosdump not found!")
        else:
87
            tdLog.info("taosdump found in %s" % binPath)
88

89 90
        os.system("rm ./taosdumptest/tmp/*.sql")
        os.system("rm ./taosdumptest/tmp/*.avro*")
91
        os.system("rm -rf ./taosdumptest/taosdump.*")
92
        os.system(
93
            "%s --databases db -o ./taosdumptest/tmp " %
94 95 96
            binPath)

        tdSql.execute("drop database db")
97 98
        tdSql.query("show databases")
        tdSql.checkRows(0)
99

100
        os.system("%s -i ./taosdumptest/tmp -y" % binPath)
101 102 103 104 105 106 107 108 109 110 111

        tdSql.query("show databases")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, 'db')

        tdSql.execute("use db")
        tdSql.query("show stables")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, 'st')

        tdSql.query("select count(*) from t1")
112
        tdSql.checkData(0, 0, self.numberOfRecords)
113

114
        # test case for TS-1225
115 116
        tdSql.execute("create database test")
        tdSql.execute("use test")
117 118 119 120 121 122 123 124
        tdSql.execute(
            "create table stb(ts timestamp, c1 binary(16374), c2 binary(16374), c3 binary(16374)) tags(t1 nchar(256))")
        tdSql.execute(
            "insert into t1 using stb tags('t1') values(now, '%s', '%s', '%s')" %
            (self.generateString(16374),
             self.generateString(16374),
             self.generateString(16374)))

125 126
        os.system("rm ./taosdumptest/tmp/*.sql")
        os.system("rm ./taosdumptest/tmp/*.avro*")
127
        os.system("rm -rf ./taosdumptest/tmp/taosdump.*")
128
        os.system("%s -D test -o ./taosdumptest/tmp -y" % binPath)
129 130 131

        tdSql.execute("drop database test")
        tdSql.query("show databases")
132
        tdSql.checkRows(1)
133

134
        os.system("%s -i ./taosdumptest/tmp -y" % binPath)
135 136 137 138 139 140 141 142 143

        tdSql.execute("use test")
        tdSql.error("show vnodes '' ")
        tdSql.query("show stables")
        tdSql.checkRows(1)
        tdSql.checkData(0, 0, 'stb')

        tdSql.query("select * from stb")
        tdSql.checkRows(1)
P
Ping Xiao 已提交
144
        os.system("rm -rf dump_result.txt")
145

146 147 148 149 150 151 152
    def stop(self):
        tdSql.close()
        tdLog.success("%s successfully executed" % __file__)


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