alter_replica.py 4.0 KB
Newer Older
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
###################################################################
#       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):
        tdLog.debug("start to execute %s" % __file__)
        tdLog.info("prepare cluster")
        tdDnodes.stopAll()
        tdDnodes.deploy(1)
        tdDnodes.start(1)

        self.conn = taos.connect(config=tdDnodes.getSimCfgPath())
        tdSql.init(self.conn.cursor())
        tdSql.execute('reset query cache')
        tdSql.execute('create dnode 192.168.0.2')
        tdDnodes.deploy(2)
        tdDnodes.start(2)

        self.conn = taos.connect(config=tdDnodes.getSimCfgPath())
        tdSql.init(self.conn.cursor())
        tdSql.execute('reset query cache')
        tdSql.execute('create dnode 192.168.0.3')
        tdDnodes.deploy(3)
        tdDnodes.start(3)

    def run(self):
45
        tdSql.execute('create database db replica 3 duration 7')
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
        tdSql.execute('use db')
        for tid in range(1, 11):
            tdSql.execute('create table tb%d(ts timestamp, i int)' % tid)
        tdLog.sleep(10)

        tdLog.info("================= step1")
        startTime = 1520000010000
        for rid in range(1, 11):
            for tid in range(1, 11):
                tdSql.execute(
                    'insert into tb%d values(%ld, %d)' %
                    (tid, startTime, rid))
            startTime += 1
        tdSql.query('select * from tb1')
        tdSql.checkRows(10)
        tdLog.sleep(5)

        tdLog.info("================= step2")
        tdSql.execute('alter database db replica 2')
        tdLog.sleep(10)

        tdLog.info("================= step3")
        for rid in range(1, 11):
            for tid in range(1, 11):
                tdSql.execute(
                    'insert into tb%d values(%ld, %d)' %
                    (tid, startTime, rid))
            startTime += 1
        tdSql.query('select * from tb1')
        tdSql.checkRows(20)
        tdLog.sleep(5)

        tdLog.info("================= step4")
        tdSql.execute('alter database db replica 1')
        tdLog.sleep(10)

        tdLog.info("================= step5")
        for rid in range(1, 11):
            for tid in range(1, 11):
                tdSql.execute(
                    'insert into tb%d values(%ld, %d)' %
                    (tid, startTime, rid))
            startTime += 1
        tdSql.query('select * from tb1')
        tdSql.checkRows(30)
        tdLog.sleep(5)

        tdLog.info("================= step6")
        tdSql.execute('alter database db replica 2')
        tdLog.sleep(10)

        tdLog.info("================= step7")
        for rid in range(1, 11):
            for tid in range(1, 11):
                tdSql.execute(
                    'insert into tb%d values(%ld, %d)' %
                    (tid, startTime, rid))
            startTime += 1
        tdSql.query('select * from tb1')
        tdSql.checkRows(40)
        tdLog.sleep(5)

        tdLog.info("================= step8")
        tdSql.execute('alter database db replica 3')
        tdLog.sleep(10)

        tdLog.info("================= step9")
        for rid in range(1, 11):
            for tid in range(1, 11):
                tdSql.execute(
                    'insert into tb%d values(%ld, %d)' %
                    (tid, startTime, rid))
            startTime += 1
        tdSql.query('select * from tb1')
        tdSql.checkRows(50)
        tdLog.sleep(5)

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


tdCases.addCluster(__file__, TDTestCase())