table_param_ttl.py 3.9 KB
Newer Older
J
jiacy-jcy 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
###################################################################
#           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 -*-

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

class TDTestCase:
J
jiacy-jcy 已提交
20
    updatecfgDict = {'ttlUnit':5,'ttlPushInterval':3}
21
    def init(self, conn, logSql, replicaVar=1):
J
jiacy-jcy 已提交
22
        tdLog.debug("start to execute %s" % __file__)
G
Ganlin Zhao 已提交
23
        tdSql.init(conn.cursor())
J
jiacy-jcy 已提交
24 25 26 27
        self.ntbname = 'ntb'
        self.stbname = 'stb'
        self.tbnum = 10
        self.ttl_param = 1
J
update  
jiacy-jcy 已提交
28 29 30
        self.default_ttl = 100
        self.modify_ttl = 1
    def ttl_check_ntb(self):
J
jiacy-jcy 已提交
31
        tdSql.prepare()
J
update  
jiacy-jcy 已提交
32

J
jiacy-jcy 已提交
33
        for i in range(self.tbnum):
J
jiacy-jcy 已提交
34 35
            tdSql.execute(f'create table db.{self.ntbname}_{i} (ts timestamp,c0 int) ttl {self.ttl_param}')
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
36
        tdSql.checkRows(self.tbnum)
J
jiacy-jcy 已提交
37
        sleep(self.updatecfgDict['ttlUnit']*self.ttl_param+self.updatecfgDict['ttlPushInterval'])
J
jiacy-jcy 已提交
38
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
39
        tdSql.checkRows(0)
J
update  
jiacy-jcy 已提交
40
        for i in range(self.tbnum):
J
jiacy-jcy 已提交
41
            tdSql.execute(f'create table db.{self.ntbname}_{i} (ts timestamp,c0 int) ttl {self.default_ttl}')
J
update  
jiacy-jcy 已提交
42
        for i in range(int(self.tbnum/2)):
J
jiacy-jcy 已提交
43
            tdSql.execute(f'alter table db.{self.ntbname}_{i} ttl {self.modify_ttl}')
J
update  
jiacy-jcy 已提交
44
        sleep(self.updatecfgDict['ttlUnit']*self.modify_ttl+self.updatecfgDict['ttlPushInterval'])
J
jiacy-jcy 已提交
45
        tdSql.query(f'show db.tables')
J
update  
jiacy-jcy 已提交
46 47 48 49
        tdSql.checkRows(self.tbnum - int(self.tbnum/2))
        tdSql.execute('drop database db')
    def ttl_check_ctb(self):
        tdSql.prepare()
J
jiacy-jcy 已提交
50
        tdSql.execute(f'create table db.{self.stbname} (ts timestamp,c0 int) tags(t0 int)')
J
update  
jiacy-jcy 已提交
51

J
jiacy-jcy 已提交
52
        for i in range(self.tbnum):
J
jiacy-jcy 已提交
53 54
            tdSql.execute(f'create table db.{self.stbname}_{i} using db.{self.stbname} tags({i}) ttl {self.ttl_param}')
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
55
        tdSql.checkRows(self.tbnum)
J
jiacy-jcy 已提交
56
        sleep(self.updatecfgDict['ttlUnit']*self.ttl_param+self.updatecfgDict['ttlPushInterval'])
J
jiacy-jcy 已提交
57
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
58
        tdSql.checkRows(0)
J
update  
jiacy-jcy 已提交
59
        for i in range(self.tbnum):
J
jiacy-jcy 已提交
60 61
            tdSql.execute(f'create table db.{self.stbname}_{i} using db.{self.stbname} tags({i}) ttl {self.default_ttl}')
        tdSql.query(f'show db.tables')
J
update  
jiacy-jcy 已提交
62 63
        tdSql.checkRows(self.tbnum)
        for i in range(int(self.tbnum/2)):
J
jiacy-jcy 已提交
64
            tdSql.execute(f'alter table db.{self.stbname}_{i} ttl {self.modify_ttl}')
J
update  
jiacy-jcy 已提交
65
        sleep(self.updatecfgDict['ttlUnit']*self.modify_ttl+self.updatecfgDict['ttlPushInterval'])
J
jiacy-jcy 已提交
66
        tdSql.query(f'show db.tables')
J
update  
jiacy-jcy 已提交
67 68
        tdSql.checkRows(self.tbnum - int(self.tbnum/2))
        tdSql.execute('drop database db')
J
jiacy-jcy 已提交
69

J
jiacy-jcy 已提交
70 71
    def ttl_check_insert(self):
        tdSql.prepare()
J
jiacy-jcy 已提交
72
        tdSql.execute(f'create table db.{self.stbname} (ts timestamp,c0 int) tags(t0 int)')
J
jiacy-jcy 已提交
73
        for i in range(self.tbnum):
J
jiacy-jcy 已提交
74 75
            tdSql.execute(f'insert into db.{self.stbname}_{i} using db.{self.stbname} tags({i}) ttl {self.ttl_param} values(now,1)')
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
76 77
        tdSql.checkRows(self.tbnum)
        sleep(self.updatecfgDict['ttlUnit']*self.ttl_param+self.updatecfgDict['ttlPushInterval'])
J
jiacy-jcy 已提交
78
        tdSql.query(f'show db.tables')
J
jiacy-jcy 已提交
79 80
        tdSql.checkRows(0)
        tdSql.execute('drop database db')
J
jiacy-jcy 已提交
81
    def run(self):
J
update  
jiacy-jcy 已提交
82 83
        self.ttl_check_ntb()
        self.ttl_check_ctb()
J
jiacy-jcy 已提交
84
        self.ttl_check_insert()
J
jiacy-jcy 已提交
85 86 87 88 89 90 91

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

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