binary.py 3.1 KB
Newer Older
sangshuduo's avatar
sangshuduo 已提交
1 2 3 4 5 6
# -*- coding: utf-8 -*-

import sys
from util.log import *
from util.cases import *
from util.sql import *
7 8
import subprocess
import os
sangshuduo's avatar
sangshuduo 已提交
9 10 11


class TDTestCase:
S
Shuduo Sang 已提交
12
    def init(self, conn, logSql):
sangshuduo's avatar
sangshuduo 已提交
13
        tdLog.debug("start to execute %s" % __file__)
S
Shuduo Sang 已提交
14
        tdSql.init(conn.cursor(), logSql)
sangshuduo's avatar
sangshuduo 已提交
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

    def run(self):
        tdSql.prepare()

        tdLog.info('=============== step1')
        tdLog.info('create table tb (ts timestamp, speed binary(5))')
        tdSql.execute('create table tb (ts timestamp, speed binary(5))')
        tdLog.info("insert into tb values (now, ) -x step1")
        tdSql.error("insert into tb values (now, )")
        tdLog.info('=============== step2')
        tdLog.info("insert into tb values (now+1a, '1234')")
        tdSql.execute("insert into tb values (now+1a, '1234')")
        tdLog.info('select speed from tb order by ts desc')
        tdSql.query('select speed from tb order by ts desc')
        tdLog.info('tdSql.checkRow(1)')
        tdSql.checkRows(1)
31 32
        tdLog.info("tdSql.checkData(0, 0, '1234')")
        tdSql.checkData(0, 0, '1234')
sangshuduo's avatar
sangshuduo 已提交
33 34 35 36 37 38 39 40
        tdLog.info('=============== step3')
        tdLog.info("insert into tb values (now+2a, '23456')")
        tdSql.execute("insert into tb values (now+2a, '23456')")
        tdLog.info('select speed from tb order by ts desc')
        tdSql.query('select speed from tb order by ts desc')
        tdLog.info('tdSql.checkRow(2)')
        tdSql.checkRows(2)
        tdLog.info('==> $data00')
41
        tdLog.info("tdSql.checkData(0, 0, '23456')")
sangshuduo's avatar
fixup.  
sangshuduo 已提交
42
        tdSql.checkData(0, 0, '23456')
sangshuduo's avatar
sangshuduo 已提交
43 44 45 46 47 48 49 50 51 52
        tdLog.info('=============== step4')
        tdLog.info("insert into tb values (now+3a, '345678')")
        tdSql.error("insert into tb values (now+3a, '345678')")
        tdLog.info("insert into tb values (now+3a, '34567')")
        tdSql.execute("insert into tb values (now+3a, '34567')")
        tdLog.info('select speed from tb order by ts desc')
        tdSql.query('select speed from tb order by ts desc')
        tdLog.info('tdSql.checkRow(3)')
        tdSql.checkRows(3)
        tdLog.info('==> $data00')
53 54
        tdLog.info("tdSql.checkData(0, 0, '34567')")
        tdSql.checkData(0, 0, '34567')
55
        tdLog.info("insert into tb values (now+4a, \"'';\")")
56 57 58
        # config_dir = subprocess.check_output(str("ps -ef |grep dnode1|grep -v grep |awk '{print $NF}'"), stderr=subprocess.STDOUT, shell=True).decode('utf-8').replace('\n', '')
        # result = ''.join(os.popen(r"""taos  -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(config_dir)).readlines())
        result = ''.join(os.popen(r"""taos  -s "insert into db.tb values (now+4a, \"'';\")" -c %s"""%(tdSql.cursor._connection._config)).readlines())
59
        if "Query OK" not in result: tdLog.exit("err:insert '';")            
sangshuduo's avatar
sangshuduo 已提交
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
        tdLog.info('drop database db')
        tdSql.execute('drop database db')
        tdLog.info('show databases')
        tdSql.query('show databases')
        tdLog.info('tdSql.checkRow(0)')
        tdSql.checkRows(0)
# convert end

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


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