int.py 5.8 KB
Newer Older
sangshuduo's avatar
sangshuduo 已提交
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
###################################################################
#           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 datetime

from util.log import *
from util.cases import *
from util.sql import *


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

    def run(self):
        tdSql.prepare()

        tdLog.info("=============== step1")
        tdSql.execute('create table tb (ts timestamp, speed int)')

        cmd = 'insert into tb values (now, NULL)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(1)
        if(tdSql.getData(0, 1) is not None):
            tdLog.exit("data is not NULL")

        tdLog.info("=============== step2")
        cmd = 'insert into tb values (now+1m, -2147483648)'
        tdLog.info(cmd)
        try:
            tdSql.execute(cmd)
            tdLog.exit(
                "This test failed: INT data overflow error _not_ catched")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.notice("INT data overflow error catched")

        cmd = 'insert into tb values (now+1m, NULL)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(2)

        if(tdSql.getData(0, 1) is not None):
            tdLog.exit("data is not NULL")

        tdLog.info("=============== step3")
        cmd = 'insert into tb values (now+2m, 2147483647)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(3)
        if(tdSql.getData(0, 1) != 2147483647):
            tdLog.exit("data is not 2147483647")

        tdLog.info("=============== step4")
        cmd = 'insert into tb values (now+3m, 2147483648)'
        tdLog.info(cmd)
        try:
            tdSql.execute(cmd)
            tdLog.exit(
                "This test failed: INT data overflow error _not_ catched")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.notice("INT data overflow error catched")

        cmd = 'insert into tb values (now+3m, NULL)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(4)

        if(tdSql.getData(0, 1) is not None):
            tdLog.exit("data is not NULL")

        tdLog.info("=============== step5")
        cmd = 'insert into tb values (now+4m, a2)'
        tdLog.info(cmd)
        try:
            tdSql.execute(cmd)
            tdLog.exit(
                "This test failed: insert wrong data error _not_ catched")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.notice("insert wrong data error catched")

        cmd = 'insert into tb values (now+4m, 0)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(5)

        if(tdSql.getData(0, 1) != 0):
            tdLog.exit("data is not 0")

        tdLog.info("=============== step6")
        cmd = 'insert into tb values (now+5m, 2a)'
        tdLog.info(cmd)
        try:
            tdSql.execute(cmd)
            tdLog.exit(
                "This test failed: insert wrong data error _not_ catched")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.notice("insert wrong data error catched")

        cmd = 'insert into tb values (now+5m, 2)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(6)
        if (tdSql.getData(0, 1) != 2):
            tdLog.exit("data is not 2")

        tdLog.info("=============== step7")
        cmd = "insert into tb values (now+6m, 2a'1)"
        tdLog.info(cmd)
        try:
            tdSql.execute(cmd)
            tdLog.exit(
                "This test failed: insert wrong data error _not_ catched")
        except Exception as e:
            tdLog.info(repr(e))
            tdLog.notice("insert wrong data error catched")

        cmd = 'insert into tb values (now+6m, 2)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(7)
        if (tdSql.getData(0, 1) != 2):
            tdLog.exit("data is not 2")

        tdLog.info("=============== step8")
        cmd = 'insert into tb values (now+8m, "null")'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(8)

        if (tdSql.getData(0, 1) is not None):
            tdLog.exit("data is not null")

        tdLog.info("=============== step9")
        cmd = "insert into tb values (now+9m, 'null')"
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(9)
        if (tdSql.getData(0, 1) is not None):
            tdLog.exit("data is not null")

        tdLog.info("=============== step10")
        cmd = 'insert into tb values (now+10m, -123)'
        tdLog.info(cmd)
        tdSql.execute(cmd)
        tdSql.query('select * from tb order by ts desc')
        tdSql.checkRows(10)

        if (tdSql.getData(0, 1) != -123):
            tdLog.exit("data is not -123")

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


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