table_param_ttl.py 4.0 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):
22
        self.replicaVar = int(replicaVar)
J
jiacy-jcy 已提交
23
        tdLog.debug("start to execute %s" % __file__)
G
Ganlin Zhao 已提交
24
        tdSql.init(conn.cursor())
J
jiacy-jcy 已提交
25 26 27 28
        self.ntbname = 'ntb'
        self.stbname = 'stb'
        self.tbnum = 10
        self.ttl_param = 1
J
update  
jiacy-jcy 已提交
29 30 31
        self.default_ttl = 100
        self.modify_ttl = 1
    def ttl_check_ntb(self):
J
jiacy-jcy 已提交
32
        tdSql.prepare()
J
update  
jiacy-jcy 已提交
33

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

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

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

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

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