supertable.py 4.2 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
###################################################################
 #		   Copyright (c) 2020 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
import time
from util.log import *
from util.cases import *
from util.sql import *
from util.sub import *

class TDTestCase:
	def init(self, conn, logSql):
		tdLog.debug("start to execute %s" % __file__)
		tdSql.init(conn.cursor(), logSql)
		self.conn = conn

	def run(self):
		sqlstr = "select * from meters"
		topic = "test"
		now = int(time.time() * 1000)
		tdSql.prepare()

B
Bomin Zhang 已提交
34 35 36 37
		numTables = 2000
		rowsPerTable = 5
		totalRows = numTables * rowsPerTable
		tdLog.info("create a super table and %d sub-tables, then insert %d rows into each sub-table." % (numTables, rowsPerTable))
38
		tdSql.execute("create table meters(ts timestamp, a int, b int) tags(area int, loc binary(20));")
B
Bomin Zhang 已提交
39 40
		for i in range(0, numTables):
			for j in range(0, rowsPerTable):
41 42 43 44 45
				tdSql.execute("insert into t%d using meters tags(%d, 'area%d') values (%d, %d, %d);" % (i, i, i, now + j, j, j))

		tdLog.info("consumption 01.")
		tdSub.init(self.conn.subscribe(True, topic, sqlstr, 0))
		tdSub.consume()
B
Bomin Zhang 已提交
46
		tdSub.checkRows(totalRows)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

		tdLog.info("consumption 02: no new rows inserted")
		tdSub.consume()
		tdSub.checkRows(0)

		tdLog.info("consumption 03: after one new rows inserted")
		tdSql.execute("insert into t0 values (%d, 10, 10);" % (now + 10))
		tdSub.consume()
		tdSub.checkRows(1)

		tdLog.info("consumption 04: keep progress and continue previous subscription")
		tdSub.close(True)
		tdSub.init(self.conn.subscribe(False, topic, sqlstr, 0))
		tdSub.consume()
		tdSub.checkRows(0)

		tdLog.info("consumption 05: remove progress and continue previous subscription")
		tdSub.close(False)
		tdSub.init(self.conn.subscribe(False, topic, sqlstr, 0))
		tdSub.consume()
B
Bomin Zhang 已提交
67
		tdSub.checkRows(totalRows + 1)
68 69 70 71 72

		tdLog.info("consumption 06: keep progress and restart the subscription")
		tdSub.close(True)
		tdSub.init(self.conn.subscribe(True, topic, sqlstr, 0))
		tdSub.consume()
B
Bomin Zhang 已提交
73
		tdSub.checkRows(totalRows + 1)
74 75 76

		tdLog.info("consumption 07: insert one row to two table then remove one table")
		tdSql.execute("insert into t0 values (%d, 11, 11);" % (now + 11))
B
Bomin Zhang 已提交
77
		tdSql.execute("insert into t%d values (%d, 11, 11);" % ((numTables-1), (now + 11)))
78 79 80 81 82 83 84 85
		tdSql.execute("drop table t0")
		tdSub.consume()
		tdSub.checkRows(1)

		tdLog.info("consumption 08: check timestamp criteria")
		tdSub.close(False)
		tdSub.init(self.conn.subscribe(True, topic, sqlstr + " where ts > %d" % now, 0))
		tdSub.consume()
B
Bomin Zhang 已提交
86
		tdSub.checkRows((numTables-1) * (rowsPerTable-1) + 1)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

		tdLog.info("consumption 09: insert large timestamp to t2 then insert smaller timestamp to t1")
		tdSql.execute("insert into t2 values (%d, 100, 100);" % (now + 100))
		tdSub.consume()
		tdSub.checkRows(1)
		tdSql.execute("insert into t1 values (%d, 12, 12);" % (now + 12))
		tdSub.consume()
		tdSub.checkRows(1)

		tdLog.info("consumption 10: field criteria")
		tdSub.close(True)
		tdSub.init(self.conn.subscribe(False, topic, sqlstr + " where a > 100", 0))
		tdSql.execute("insert into t2 values (%d, 101, 100);" % (now + 101))
		tdSql.execute("insert into t2 values (%d, 100, 100);" % (now + 102))
		tdSql.execute("insert into t2 values (%d, 102, 100);" % (now + 103))
		tdSub.consume()
		tdSub.checkRows(2)

		tdLog.info("consumption 11: two vnodes")
		tdSql.execute("insert into t2 values (%d, 102, 100);" % (now + 104))
B
Bomin Zhang 已提交
107
		tdSql.execute("insert into t1299 values (%d, 102, 100);" % (now + 104))
108 109 110
		tdSub.consume()
		tdSub.checkRows(2)

B
Bomin Zhang 已提交
111 112 113 114 115
		tdLog.info("consumption 12: create a new table")
		tdSql.execute("insert into t%d using meters tags(%d, 'area%d') values (%d, 102, 100);" % (numTables, numTables, numTables, now + 105))
		tdSub.consume()
		tdSub.checkRows(1)

116 117 118 119 120 121 122
	def stop(self):
		tdSub.close(False)
		tdSql.close()
		tdLog.success("%s successfully executed" % __file__)
	
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())