def tbase300(self): tdLog.debug("begin tbase300") tdSql.prepare() tdSql.execute( "create table mt(ts timestamp, c1 int, c2 int) tags(t1 int)") tdSql.execute("create table tb1 using mt tags(1)") tdSql.execute("create table tb2 using mt tags(2)") tdSql.execute( "create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2),first(c1), last(c2) from mt interval(4s) sliding(2s)" ) #tdSql.execute("create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2), first(c1) from mt interval(4s) sliding(2s)") tdLog.sleep(10) tdSql.execute("insert into tb2 values(now, 1, 1)") tdSql.execute("insert into tb1 values(now, 1, 1)") tdLog.sleep(4) tdSql.query("select * from mt") tdSql.query("select * from strm") tdSql.execute("drop table tb1") tdSql.waitedQuery("select * from strm", 1, 100) if tdSql.queryRows < 1 or tdSql.queryRows > 2: tdLog.exit("rows should be 1 or 2") tdSql.execute("drop table tb2") tdSql.execute("drop table mt") tdSql.execute("drop table strm")
def tbase304(self): tdLog.debug("begin tbase304") # we cannot reset query cache in server side, as a workaround, # set super table name to mt304, need to change back to mt later tdSql.execute( "create table mt304 (ts timestamp, c1 int) tags(t1 int, t2 int)") tdSql.execute("create table tb1 using mt304 tags(1, 1)") tdSql.execute("create table tb2 using mt304 tags(1, -1)") time.sleep(0.1) tdSql.execute( "create table strm as select count(*), avg(c1) from mt304 where t2 >= 0 interval(4s) sliding(2s)" ) tdSql.execute("insert into tb1 values (now,1)") tdSql.execute("insert into tb2 values (now,2)") tdSql.waitedQuery("select * from strm", 1, 100) if tdSql.queryRows < 1 or tdSql.queryRows > 2: tdLog.exit("rows should be 1 or 2") tdSql.checkData(0, 1, 1) tdSql.checkData(0, 2, 1.000000000) tdSql.execute("alter table mt304 drop tag t2") tdSql.execute("insert into tb2 values (now,2)") tdSql.execute("insert into tb1 values (now,1)") tdSql.query("select * from strm") tdSql.execute("alter table mt304 add tag t2 int") tdLog.sleep(1) tdSql.query("select * from strm")
def run(self): nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) ctest.connectDB() ctest.createSTable(1) ctest.run() tdSql.init(ctest.conn.cursor(), False) tdSql.execute("use %s" % ctest.dbName) totalTime = 0 for i in range(10): startTime = time.time() tdSql.query("select * from %s" % ctest.stbName) totalTime += time.time() - startTime print("replica 1: avarage query time for %d records: %f seconds" % (ctest.numberOfTables * ctest.numberOfRecords,totalTime / 10)) tdSql.execute("alter database %s replica 3" % ctest.dbName) tdLog.sleep(60) totalTime = 0 for i in range(10): startTime = time.time() tdSql.query("select * from %s" % ctest.stbName) totalTime += time.time() - startTime print("replica 3: avarage query time for %d records: %f seconds" % (ctest.numberOfTables * ctest.numberOfRecords,totalTime / 10)) tdSql.close() tdLog.success("%s successfully executed" % __file__)
def datatypes(self): tdLog.debug("begin data types") tdSql.prepare() tdSql.execute( "create table stb3 (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(15), c6 nchar(15), c7 bool) tags(t1 int, t2 binary(15))" ) tdSql.execute("create table tb0 using stb3 tags(0, 'tb0')") tdSql.execute("create table tb1 using stb3 tags(1, 'tb1')") tdSql.execute("create table tb2 using stb3 tags(2, 'tb2')") tdSql.execute("create table tb3 using stb3 tags(3, 'tb3')") tdSql.execute("create table tb4 using stb3 tags(4, 'tb4')") tdSql.execute( "create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5), last(c6) from stb3 where ts < now + 30s interval(4s) sliding(2s)" ) #tdSql.execute("create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5) from stb where ts < now + 30s interval(4s) sliding(2s)") tdLog.sleep(1) tdSql.execute( "insert into tb0 values (now, 0, 0, 0, 0, 'binary0', '涛思0', true) tb1 values (now, 1, 1, 1, 1, 'binary1', '涛思1', false) tb2 values (now, 2, 2, 2, 2, 'binary2', '涛思2', true) tb3 values (now, 3, 3, 3, 3, 'binary3', '涛思3', false) tb4 values (now, 4, 4, 4, 4, 'binary4', '涛思4', true) " ) tdSql.waitedQuery("select * from strm0 order by ts desc", 2, 120) tdSql.checkRows(2) tdSql.execute( "insert into tb0 values (now, 10, 10, 10, 10, 'binary0', '涛思0', true) tb1 values (now, 11, 11, 11, 11, 'binary1', '涛思1', false) tb2 values (now, 12, 12, 12, 12, 'binary2', '涛思2', true) tb3 values (now, 13, 13, 13, 13, 'binary3', '涛思3', false) tb4 values (now, 14, 14, 14, 14, 'binary4', '涛思4', true) " ) tdSql.waitedQuery("select * from strm0 order by ts desc", 4, 120) tdSql.checkRows(4)
def run(self): nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) ctest.connectDB() ctest.createSTable(3) ctest.run() tdSql.init(ctest.conn.cursor(), False) nodes.node2.stopTaosd() tdSql.execute("use %s" % ctest.dbName) tdSql.query("show vgroups") vnodeID = tdSql.getData(0, 0) nodes.node2.removeDataForVnode(vnodeID) nodes.node2.startTaosd() # Wait for vnode file to recover for i in range(10): tdSql.query("select count(*) from t0") tdLog.sleep(10) for i in range(10): tdSql.query("select count(*) from t0") tdSql.checkData(0, 0, 1000) tdSql.close() tdLog.success("%s successfully executed" % __file__)
def run(self): rowNum = 200 totalNum = 200 tdSql.prepare() tdLog.info("=============== step1") tdSql.execute("create table mt(ts timestamp, tbcol int, tbcol2 float) TAGS(tgcol int)") for i in range(5): tdSql.execute("create table tb%d using mt tags(%d)" % (i, i)) for j in range(rowNum): tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j)) time.sleep(0.1) tdLog.info("=============== step2") tdSql.query("select count(*), count(tbcol), count(tbcol2) from mt interval(10s)") tdSql.execute("create table st as select count(*), count(tbcol), count(tbcol2) from mt interval(10s)") tdLog.info("=============== step3") tdSql.waitedQuery("select * from st", 1, 120) v = tdSql.getData(0, 3) if v >= 51: tdLog.exit("value is %d, which is larger than 51" % v) tdLog.info("=============== step4") for i in range(5, 10): tdSql.execute("create table tb%d using mt tags(%d)" % (i, i)) for j in range(rowNum): tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j)) tdLog.info("=============== step5") tdLog.sleep(40) tdSql.waitedQuery("select * from st order by ts desc", 1, 120) v = tdSql.getData(0, 3) if v <= 51: tdLog.exit("value is %d, which is smaller than 51" % v)
def run(self): nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) ctest.connectDB() tdSql.init(ctest.conn.cursor(), False) tdSql.execute("use %s" % ctest.dbName) tdSql.query("show vgroups") for i in range(10): tdSql.checkData(i, 5, "master") tdSql.execute("alter database %s replica 2" % ctest.dbName) tdLog.sleep(30) tdSql.query("show vgroups") for i in range(10): tdSql.checkData(i, 5, "master") tdSql.checkData(i, 7, "slave") tdSql.execute("alter database %s replica 3" % ctest.dbName) tdLog.sleep(30) tdSql.query("show vgroups") for i in range(10): tdSql.checkData(i, 5, "master") tdSql.checkData(i, 7, "slave") tdSql.checkData(i, 9, "slave")
def wildcardFilterOnTags(self): tdLog.debug("begin wildcardFilterOnTag") tdSql.prepare() tdSql.execute( "create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10))" ) tdSql.execute("create table tb1 using stb tags('a1')") tdSql.execute("create table tb2 using stb tags('b2')") tdSql.execute("create table tb3 using stb tags('a3')") tdSql.execute( "create table strm as select count(*), avg(c1), first(c2) from stb where t1 like 'a%' interval(4s) sliding(2s)" ) tdSql.query("describe strm") tdSql.checkRows(4) tdLog.sleep(1) tdSql.execute("insert into tb1 values (now, 0, 'tb1')") tdLog.sleep(4) tdSql.execute("insert into tb2 values (now, 2, 'tb2')") tdLog.sleep(4) tdSql.execute("insert into tb3 values (now, 0, 'tb3')") tdSql.waitedQuery("select * from strm", 4, 60) tdSql.checkRows(4) tdSql.checkData(0, 2, 0.000000000) if tdSql.getData(0, 3) == 'tb2': tdLog.exit("unexpected value of data03") if tdSql.getData(1, 3) == 'tb2': tdLog.exit("unexpected value of data13") if tdSql.getData(2, 3) == 'tb2': tdLog.exit("unexpected value of data23") if tdSql.getData(3, 3) == 'tb2': tdLog.exit("unexpected value of data33") tdLog.info("add table tb4 to see if stream still works correctly") # The vnode client needs to refresh metadata cache to allow strm calculate tb4's data. # But the current refreshing frequency is every 10 min # commented out the case below to save running time tdSql.execute("create table tb4 using stb tags('a4')") tdSql.execute("insert into tb4 values(now, 4, 'tb4')") tdSql.waitedQuery("select * from strm order by ts desc", 6, 60) tdSql.checkRows(6) tdSql.checkData(0, 2, 4) tdSql.checkData(0, 3, "tb4") tdLog.info("change tag values to see if stream still works correctly") tdSql.execute("alter table tb4 set tag t1='b4'") tdLog.sleep(3) tdSql.execute("insert into tb1 values (now, 1, 'tb1_a1')") tdLog.sleep(4) tdSql.execute("insert into tb4 values (now, -4, 'tb4_b4')") tdSql.waitedQuery("select * from strm order by ts desc", 8, 100) tdSql.checkRows(8) tdSql.checkData(0, 2, 1) tdSql.checkData(0, 3, "tb1_a1")
def run(self): tdSql.prepare() tdSql.execute( "create table if not exists st (ts timestamp, tagtype int) tags(dev nchar(50))" ) tdSql.execute( 'CREATE TABLE if not exists dev_001 using st tags("dev_01")') tdSql.execute( 'CREATE TABLE if not exists dev_002 using st tags("dev_02")') tdSql.execute( """INSERT INTO dev_001(ts, tagtype) VALUES('2020-05-13 10:00:00.000', 1), ('2020-05-13 10:00:00.001', 1) dev_002 VALUES('2020-05-13 10:00:00.001', 1)""") for i in range(10): for j in range(1000): tdSql.query("select * from db.st") tdLog.sleep(10)
def run(self): nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) tdSql.init(ctest.conn.cursor(), False) tdSql.query("show databases") count = tdSql.queryRows nodes.stopAllTaosd() nodes.node1.startTaosd() tdSql.error("show databases") nodes.node2.startTaosd() tdSql.error("show databases") nodes.node3.startTaosd() tdLog.sleep(10) tdSql.query("show databases") tdSql.checkRows(count)
def run(self): # cluster environment set up nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) ctest.connectDB() tdSql.init(ctest.conn.cursor(), False) nodes.addConfigs("offlineThreshold", "10") nodes.removeAllDataFiles() nodes.restartAllTaosd() nodes.node3.stopTaosd() tdLog.sleep(10) tdSql.query("show dnodes") tdSql.checkRows(3) tdSql.checkData(2, 4, "offline") tdLog.sleep(60) tdSql.checkRows(3) tdSql.checkData(2, 4, "dropping") tdLog.sleep(300) tdSql.checkRows(2) nodes.removeConfigs("offlineThreshold", "10") nodes.restartAllTaosd() tdSql.close() tdLog.success("%s successfully executed" % __file__)
def run(self): nodes = Nodes() ctest = ClusterTest(nodes.node1.hostName) ctest.connectDB() tdSql.init(ctest.conn.cursor(), False) ## Test case 1 ## tdLog.info("Test case 1 repeat %d times" % ctest.repeat) for i in range(ctest.repeat): tdLog.info("Start Round %d" % (i + 1)) replica = random.randint(1, 3) ctest.createSTable(replica) ctest.run() tdLog.sleep(10) tdSql.query("select count(*) from %s.%s" % (ctest.dbName, ctest.stbName)) tdSql.checkData(0, 0, ctest.numberOfRecords * ctest.numberOfTables) tdLog.info("Round %d completed" % (i + 1)) tdSql.close() tdLog.success("%s successfully executed" % __file__)