merge_commit_data2.py 12.2 KB
Newer Older
W
wangyazhou1313 已提交
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
###################################################################
#           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
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
import time


class TDTestCase:
    def init(self, conn, logSql):
        tdLog.debug("start to execute %s" % __file__)
        tdSql.init(conn.cursor(), logSql)
    
    
    def restart_taosd(self,db):
        tdDnodes.stop(1)
        tdDnodes.startWithoutSleep(1)
L
fix  
liuyq-617 已提交
31
        tdLog.sleep(2)
W
wangyazhou1313 已提交
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        tdSql.execute("use %s;" % db)

    def date_to_timestamp_microseconds(self, date):
        datetime_obj = datetime.strptime(date, "%Y-%m-%d %H:%M:%S.%f")
        obj_stamp = int(time.mktime(datetime_obj.timetuple()) * 1000.0 + datetime_obj.microsecond / 1000.0)
        return obj_stamp

    def timestamp_microseconds_to_date(self, timestamp):
        d = datetime.datetime.fromtimestamp(timestamp/1000)
        str1 = d.strftime("%Y-%m-%d %H:%M:%S.%f")
        return str1



    def run(self):
        print("==========step1")
        print("create table && insert data")
        sql = 'reset query cache'
        tdSql.execute(sql)
        sql = 'drop database if exists db'
        tdSql.execute(sql)
        sql = 'create database db update 1 days 30;'
        tdSql.execute(sql)
        sql = 'use db;'
        tdSql.execute(sql)
        tdSql.execute('create table t1 (ts timestamp, a int)')


        print("==================================1 start")
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t1 values (%d , 1)' %(t0+i))
        print("==========step2")
        print("restart to commit ")
        self.restart_taosd('db')

        print('check query result after restart')
        tdSql.query('select * from db.t1;')
        for i in range(insert_rows):
            tdSql.checkData(i, 1, 1)

        print("==========step3")
        print('insert data')
        for i in range(insert_rows):
            tdSql.execute('insert into t1 values (%d , 1)' %(t0+i+5000))
        print('check query result before restart')
        tdSql.query('select * from db.t1;')
        for i in range(insert_rows, insert_rows*2):
            tdSql.checkData(i, 1, 1)

        self.restart_taosd('db')
        print('check query result after restart')
        tdSql.query('select * from db.t1;')
        for i in range(insert_rows, insert_rows*2):
            tdSql.checkData(i, 1, 1)

        print("==========step4")
        print('insert data')
        for i in range(insert_rows):
            tdSql.execute('insert into t1 values (%d , 2)' %(t0+i))
        for i in range(insert_rows):
            tdSql.execute('insert into t1 values (%d , 1)' %(t0+i+5000))

        print('check query result before restart')
        tdSql.query('select * from db.t1;')
        print(tdSql.queryResult)
        for i in range(insert_rows):
            tdSql.checkData(i, 1, 2)
        for i in range(insert_rows, insert_rows*2):
            tdSql.checkData(i, 1, 1)

        print('check query result after restart')
        self.restart_taosd('db')
        tdSql.query('select * from db.t1;')
        # print(tdSql.queryResult)
        for i in range(insert_rows):
            tdSql.checkData(i, 1, 2)
        for i in range(insert_rows, insert_rows*2):
            tdSql.checkData(i, 1, 1)

        print("==================================2 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t2 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t2 values (%d , 1)' %(t0+i))
        print('restart to commit')
        self.restart_taosd('db')
        for i in range(insert_rows):
            tdSql.execute('insert into t2 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for k in range(10):
            for i in range(10):
                tdSql.execute('insert into t2 values (%d , 1)' %(t0 + 200 + k * 10 + i))
                print('insert into t2 values (%d , 1)' %(t0 + 200 + k * 10 + i))


        print("==========step2")
        print('check query result before restart')
        tdSql.query('select * from db.t2;')
        for i in range(insert_rows*2+100):
            tdSql.checkData(i, 1, 1)
        # print(tdSql.queryResult)
        print('restart to commit')
        self.restart_taosd('db')
        print('check query result after restart')
        tdSql.query('select * from db.t2;')
        for i in range(insert_rows*2+100):
            tdSql.checkData(i, 1, 1)


        print("==================================3 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t3 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t3 values (%d , 1)' %(t0+i))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(insert_rows):
            tdSql.execute('insert into t3 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(5200):
            tdSql.execute('insert into t3 values (%d , 2)' %(t0+i))

        print("==========step2")
        print('check query result before restart')
        tdSql.query('select * from db.t3;')
        for i in range(5200):
            tdSql.checkData(i, 1, 2)
        # print(tdSql.queryResult)
        print('restart to commit')
        self.restart_taosd('db')
        print('check query result after restart')
        tdSql.query('select * from db.t3;')
        for i in range(5200):
            tdSql.checkData(i, 1, 2)

        print("==================================4 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t4 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t4 values (%d , 1)' %(t0+i))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(insert_rows):
            tdSql.execute('insert into t4 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(100):
            tdSql.execute('insert into t4 values (%d , 2)' %(t0+i))

        for i in range(200, 5000):
            tdSql.execute('insert into t4 values (%d , 2)' %(t0+i))

        for i in range(100):
            tdSql.execute('insert into t4 values (%d , 1)' %(t0+i+5000))

        print('check query result before restart')
        tdSql.query('select * from db.t4;')
        for i in range(100):
            tdSql.checkData(i, 1, 2)
        for i in range(100, 200):
            tdSql.checkData(i, 1, 1)
        for i in range(200, 5000):
            tdSql.checkData(i, 1, 2)
        for i in range(5000, 5200):
            tdSql.checkData(i, 1, 1)

        print('check query result after restart')
        self.restart_taosd('db')
        tdSql.query('select * from db.t4;')
        for i in range(100):
            tdSql.checkData(i, 1, 2)
        for i in range(100, 200):
            tdSql.checkData(i, 1, 1)
        for i in range(200, 5000):
            tdSql.checkData(i, 1, 2)
        for i in range(5000, 5200):
            tdSql.checkData(i, 1, 1)

        print("==================================5 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t5 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t5 values (%d , 1)' %(t0+i))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(insert_rows):
            tdSql.execute('insert into t5 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(100, 200):
            tdSql.execute('insert into t5 values (%d , 2)' %(t0+i))

        for i in range(200, 5000):
            tdSql.execute('insert into t5 values (%d , 2)' %(t0+i))

        for i in range(100, 200):
            tdSql.execute('insert into t5 values (%d , 2)' %(t0+i+5000))

        print('check query result before restart')
        tdSql.query('select * from db.t5;')
        for i in range(100):
            tdSql.checkData(i, 1, 1)
        for i in range(100, 5000):
            tdSql.checkData(i, 1, 2)
        for i in range(5000, 5100):
            tdSql.checkData(i, 1, 1)
        for i in range(5100, 5200):
            tdSql.checkData(i, 1, 2)

        print('check query result after restart')
        self.restart_taosd('db')
        tdSql.query('select * from db.t5;')
        for i in range(100):
            tdSql.checkData(i, 1, 1)
        for i in range(100, 5000):
            tdSql.checkData(i, 1, 2)
        for i in range(5000, 5100):
            tdSql.checkData(i, 1, 1)
        for i in range(5100, 5200):
            tdSql.checkData(i, 1, 2)

        print("==================================6 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t6 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t6 values (%d , 1)' %(t0+i))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(insert_rows):
            tdSql.execute('insert into t6 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(-1000, 10000):
            tdSql.execute('insert into t6 values (%d , 2)' %(t0+i))

        print('check query result before restart')
        tdSql.query('select * from db.t6;')
        tdSql.checkRows(11000)
        for i in range(11000):
            tdSql.checkData(i, 1, 2)

        print('check query result after restart')
        self.restart_taosd('db')
        tdSql.query('select * from db.t6;')
        tdSql.checkRows(11000)
        for i in range(11000):
            tdSql.checkData(i, 1, 2)


        print("==================================7 start")
        print("==========step1")
        print("create table && insert data")
        tdSql.execute('create table t7 (ts timestamp, a int)')
        insert_rows = 200
        t0 = 1603152000000
        tdLog.info("insert %d rows" % insert_rows)
        for i in range(insert_rows):
            tdSql.execute('insert into t7 values (%d , 1)' %(t0+i))

        for i in range(insert_rows):
            tdSql.execute('insert into t7 values (%d , 1)' %(t0+i+5000))
        print('restart to commit')
        self.restart_taosd('db')

        for i in range(-1000, 10000):
            tdSql.execute('insert into t7 values (%d , 2)' %(t0+i))

        print('check query result before restart')
        tdSql.query('select * from db.t7;')
        tdSql.checkRows(11000)
        for i in range(11000):
            tdSql.checkData(i, 1, 2)

        print('check query result after restart')
        self.restart_taosd('db')
        tdSql.query('select * from db.t7;')
        tdSql.checkRows(11000)
        for i in range(11000):
            tdSql.checkData(i, 1, 2)


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


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