allow_update.py 6.0 KB
Newer Older
H
Hui Li 已提交
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
###################################################################
#           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 taos
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)
        
        self.numOfRecords = 10
        self.ts = 1604295582000    
    
    def restartTaosd(self):
        tdDnodes.stop(1)
        tdDnodes.start(1)
        tdSql.execute("use udb")

    def run(self):
        tdSql.prepare()
        startTs = self.ts

        print("==============step1")        
        tdSql.execute("create database udb update 1")
        tdSql.execute("use udb")
        tdSql.execute("create table t (ts timestamp, a int)")
        tdSql.execute("insert into t values (%d, 1)" % (startTs))
        tdSql.execute("insert into t values (%d, 1)" % (startTs - 3))
        tdSql.execute("insert into t values (%d, 1)" % (startTs + 3))
        
        tdSql.query("select * from t")
        tdSql.checkRows(3)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 1)
        tdSql.checkData(1, 0, 1)
        tdSql.checkData(2, 0, 1)

        print("==============step2")
        tdSql.execute("insert into t values (%d, 2)" % (startTs))
        tdSql.execute("insert into t values (%d, 2)" % (startTs - 3))
        tdSql.execute("insert into t values (%d, 2)" % (startTs + 3))
        
        tdSql.query("select * from t")
        tdSql.checkRows(3)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 2)
        tdSql.checkData(1, 0, 2)
        tdSql.checkData(2, 0, 2)

        print("==============step3")
        tdSql.execute("insert into t values (%d, 3)" % (startTs - 4))
        tdSql.execute("insert into t values (%d, 3)" % (startTs - 2))
        tdSql.execute("insert into t values (%d, 3)" % (startTs + 2))
        tdSql.execute("insert into t values (%d, 3)" % (startTs + 4))
        
        tdSql.query("select * from t")
        tdSql.checkRows(7)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 3)
        tdSql.checkData(1, 0, 2)
        tdSql.checkData(2, 0, 3)
        tdSql.checkData(3, 0, 2)
        tdSql.checkData(4, 0, 3)
        tdSql.checkData(5, 0, 2)
        tdSql.checkData(6, 0, 3)
        
        print("==============step4")
        tdSql.execute("insert into t values (%d, 4)" % (startTs - 4))
        tdSql.execute("insert into t values (%d, 4)" % (startTs - 2))
        tdSql.execute("insert into t values (%d, 4)" % (startTs + 2))
        tdSql.execute("insert into t values (%d, 4)" % (startTs + 4))
        
        tdSql.query("select * from t")
        tdSql.checkRows(7)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 4)
        tdSql.checkData(1, 0, 2)
        tdSql.checkData(2, 0, 4)
        tdSql.checkData(3, 0, 2)
        tdSql.checkData(4, 0, 4)
        tdSql.checkData(5, 0, 2)
        tdSql.checkData(6, 0, 4)
        
        print("==============step5")
        tdSql.execute("insert into t values (%d, 5)" % (startTs - 1))
        tdSql.execute("insert into t values (%d, 5)" % (startTs + 1))
        
        tdSql.query("select * from t")
        tdSql.checkRows(9)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 4)
        tdSql.checkData(1, 0, 2)
        tdSql.checkData(2, 0, 4)        
        tdSql.checkData(3, 0, 5)
        tdSql.checkData(4, 0, 2)
        tdSql.checkData(5, 0, 5)        
        tdSql.checkData(6, 0, 4)
        tdSql.checkData(7, 0, 2)
        tdSql.checkData(8, 0, 4)
        
        print("==============step6")
        tdSql.execute("insert into t values (%d, 6)" % (startTs - 4))
        tdSql.execute("insert into t values (%d, 6)" % (startTs - 3))
        tdSql.execute("insert into t values (%d, 6)" % (startTs - 2))
        tdSql.execute("insert into t values (%d, 6)" % (startTs - 1))
        tdSql.execute("insert into t values (%d, 6)" % (startTs))
        tdSql.execute("insert into t values (%d, 6)" % (startTs + 1))
        tdSql.execute("insert into t values (%d, 6)" % (startTs + 2))
        tdSql.execute("insert into t values (%d, 6)" % (startTs + 3))
        tdSql.execute("insert into t values (%d, 6)" % (startTs + 4))
        
        tdSql.query("select * from t")
        tdSql.checkRows(9)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 6)
        tdSql.checkData(1, 0, 6)
        tdSql.checkData(2, 0, 6)        
        tdSql.checkData(3, 0, 6)
        tdSql.checkData(4, 0, 6)
        tdSql.checkData(5, 0, 6)        
        tdSql.checkData(6, 0, 6)
        tdSql.checkData(7, 0, 6)
        tdSql.checkData(8, 0, 6)
        
        # restart taosd to commit, and check
        self.restartTaosd();
        
        tdSql.query("select * from t")
        tdSql.checkRows(9)
        
        tdSql.query("select a from t")
        tdSql.checkData(0, 0, 6)
        tdSql.checkData(1, 0, 6)
        tdSql.checkData(2, 0, 6)        
        tdSql.checkData(3, 0, 6)
        tdSql.checkData(4, 0, 6)
        tdSql.checkData(5, 0, 6)        
        tdSql.checkData(6, 0, 6)
        tdSql.checkData(7, 0, 6)
        tdSql.checkData(8, 0, 6)        

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


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