提交 9e32cd4f 编写于 作者: haoranc's avatar haoranc

test: modify testcases of muti-mnodes

上级 bf474228
...@@ -84,10 +84,10 @@ class TDSql: ...@@ -84,10 +84,10 @@ class TDSql:
self.queryResult = None self.queryResult = None
tdLog.info("sql:%s, expect error occured" % (sql)) tdLog.info("sql:%s, expect error occured" % (sql))
def query(self, sql, row_tag=None,queyTimes=10): def query(self, sql, row_tag=None,queryTimes=10):
self.sql = sql self.sql = sql
i=1 i=1
while i <= queyTimes: while i <= queryTimes:
try: try:
self.cursor.execute(sql) self.cursor.execute(sql)
self.queryResult = self.cursor.fetchall() self.queryResult = self.cursor.fetchall()
...@@ -97,26 +97,15 @@ class TDSql: ...@@ -97,26 +97,15 @@ class TDSql:
return self.queryResult return self.queryResult
return self.queryRows return self.queryRows
except Exception as e: except Exception as e:
i+=1
tdLog.notice("Try to query again, query times: %d "%i) tdLog.notice("Try to query again, query times: %d "%i)
if i == queryTimes:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
raise Exception(repr(e))
i+=1
time.sleep(1) time.sleep(1)
pass pass
else:
try:
tdLog.notice("Try the last query ")
self.cursor.execute(sql)
self.queryResult = self.cursor.fetchall()
self.queryRows = len(self.queryResult)
self.queryCols = len(self.cursor.description)
if row_tag:
return self.queryResult
return self.queryRows
except Exception as e:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
traceback.print_exc()
raise Exception(repr(e))
def is_err_sql(self, sql): def is_err_sql(self, sql):
...@@ -305,28 +294,23 @@ class TDSql: ...@@ -305,28 +294,23 @@ class TDSql:
time.sleep(1) time.sleep(1)
continue continue
def execute(self, sql,queyTimes=10): def execute(self, sql,queryTimes=10):
self.sql = sql self.sql = sql
i=1 i=1
while i <= queyTimes: while i <= queryTimes:
try: try:
self.affectedRows = self.cursor.execute(sql) self.affectedRows = self.cursor.execute(sql)
return self.affectedRows return self.affectedRows
except Exception as e: except Exception as e:
i+=1
tdLog.notice("Try to execute sql again, query times: %d "%i) tdLog.notice("Try to execute sql again, query times: %d "%i)
if i == queryTimes:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
raise Exception(repr(e))
i+=1
time.sleep(1) time.sleep(1)
pass pass
else:
try:
tdLog.notice("Try the last execute sql ")
self.affectedRows = self.cursor.execute(sql)
return self.affectedRows
except Exception as e:
caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, sql, repr(e))
tdLog.notice("%s(%d) failed: sql:%s, %s" % args)
raise Exception(repr(e))
def checkAffectedRows(self, expectAffectedRows): def checkAffectedRows(self, expectAffectedRows):
if self.affectedRows != expectAffectedRows: if self.affectedRows != expectAffectedRows:
......
...@@ -48,7 +48,7 @@ endi ...@@ -48,7 +48,7 @@ endi
$replica = 3 $replica = 3
$vgroups = 1 $vgroups = 1
print ============= create database print ============= create database db
sql create database db replica $replica vgroups $vgroups sql create database db replica $replica vgroups $vgroups
$loop_cnt = 0 $loop_cnt = 0
...@@ -135,7 +135,7 @@ endw ...@@ -135,7 +135,7 @@ endw
$totalTblNum = $tbNum * 2 $totalTblNum = $tbNum * 2
sleep 1000 sleep 1000
sql show tables sql show tables
print ====> expect $totalTblNum and infinsert $rows in fact print ====> expect $totalTblNum and insert $rows in fact
if $rows != $totalTblNum then if $rows != $totalTblNum then
return -1 return -1
endi endi
......
...@@ -202,7 +202,7 @@ else ...@@ -202,7 +202,7 @@ else
endi endi
vg_ready: vg_ready:
print ====> create stable/child table print ====> create stable stb /child table ctb and general table ntb
sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int) sql create table stb (ts timestamp, c1 int, c2 float, c3 binary(10)) tags (t1 int)
sql show stables sql show stables
...@@ -225,7 +225,7 @@ endw ...@@ -225,7 +225,7 @@ endw
$totalTblNum = $tbNum * 2 $totalTblNum = $tbNum * 2
sleep 1000 sleep 1000
sql show tables sql show tables
print ====> expect $totalTblNum and infinsert $rows in fact print ====> expect $totalTblNum and insert $rows in fact
if $rows != $totalTblNum then if $rows != $totalTblNum then
return -1 return -1
endi endi
...@@ -237,6 +237,7 @@ sql show vgroups ...@@ -237,6 +237,7 @@ sql show vgroups
$dnodeId = $data[0][3] $dnodeId = $data[0][3]
$dnodeId = dnode . $dnodeId $dnodeId = dnode . $dnodeId
print ====> switch_leader_to_offine_loop
switch_leader_to_offine_loop: switch_leader_to_offine_loop:
print $dnodeId print $dnodeId
...@@ -271,22 +272,7 @@ system sh/exec.sh -n $dnodeId -s start ...@@ -271,22 +272,7 @@ system sh/exec.sh -n $dnodeId -s start
$switch_loop_cnt = $switch_loop_cnt + 1 $switch_loop_cnt = $switch_loop_cnt + 1
print $switch_loop_cnt print $switch_loop_cnt
if $switch_loop_cnt == 1 then if $switch_loop_cnt <= 4 then
sql show vgroups
$dnodeId = $data[0][3]
$dnodeId = dnode . $dnodeId
goto switch_leader_to_offine_loop
elif $switch_loop_cnt == 2 then
sql show vgroups
$dnodeId = $data[0][3]
$dnodeId = dnode . $dnodeId
goto switch_leader_to_offine_loop
elif $switch_loop_cnt == 3 then
sql show vgroups
$dnodeId = $data[0][3]
$dnodeId = dnode . $dnodeId
goto switch_leader_to_offine_loop
elif $switch_loop_cnt == 4 then
sql show vgroups sql show vgroups
$dnodeId = $data[0][3] $dnodeId = $data[0][3]
$dnodeId = dnode . $dnodeId $dnodeId = dnode . $dnodeId
......
...@@ -4,6 +4,8 @@ import sys ...@@ -4,6 +4,8 @@ import sys
import datetime import datetime
import inspect import inspect
import random import random
from util.dnodes import TDDnode
from util.dnodes import tdDnodes
from util.log import * from util.log import *
from util.sql import * from util.sql import *
...@@ -30,10 +32,10 @@ class TDTestCase: ...@@ -30,10 +32,10 @@ class TDTestCase:
for i in range(ctbNum): for i in range(ctbNum):
tagValue = 'beijing' tagValue = 'beijing'
if (i % 10 == 0): if (i % 10 == 0):
sql += " %s%d using %s (name,fleet,driver,device_version) tags('truck_%d', 'South%d','Trish%d','v2.%d')"%(ctbPrefix,i,stbName,i,i,i,i) sql += " %s%d using %s (name,fleet,driver,device_version,load_capacity,fuel_capacity,nominal_fuel_consumption) tags('truck_%d', 'South%d','Trish%d','v2.%d', 1500+%d*20, 150+%d*2, 5+%d)"%(ctbPrefix,i,stbName,i,i,i,i,(1500+i*20),(150+i*2),(5+i))
else: else:
model = 'H-%d'%i model = 'H-%d'%i
sql += " %s%d using %s tags('truck_%d', 'South%d','Trish%d','%s','v2.%d')"%(ctbPrefix,i,stbName,i,i,i,model,i) sql += " %s%d using %s tags('truck_%d', 'South%d','Trish%d','%s','v2.%d', %d, %d,%d)"%(ctbPrefix,i,stbName,i,i,i,model,i,(1500+i*20),(150+i*2),(5+i))
if (i > 0) and (i%1000 == 0): if (i > 0) and (i%1000 == 0):
tsql.execute(sql) tsql.execute(sql)
sql = pre_create sql = pre_create
...@@ -55,10 +57,10 @@ class TDTestCase: ...@@ -55,10 +57,10 @@ class TDTestCase:
sql += " %s%d values "%(ctbPrefix,i) sql += " %s%d values "%(ctbPrefix,i)
for j in range(rowsPerTbl): for j in range(rowsPerTbl):
if(ctbPrefix=="rct"): if(ctbPrefix=="rct"):
sql += f"({startTs+j*60000}, {80+j}, {90+j}, {85+j}, {30+j*10}, {1.2*j}, {221+j*2}, {20+j*0.2}, {1500+j*20}, {150+j*2},{5+j}) " sql += f"({startTs+j*60000}, {80+j}, {90+j}, {85+j}, {30+j*10}, {1.2*j}, {221+j*2}, {20+j*0.2}) "
elif ( ctbPrefix=="dct"): elif ( ctbPrefix=="dct"):
status= random.randint(0,1) status= random.randint(0,1)
sql += f"( {startTs+j*60000}, {1+j*0.1},{1400+j*15}, {status},{1500+j*20}, {150+j*2},{5+j} ) " sql += f"( {startTs+j*60000}, {1+j*0.1},{1400+j*15}, {status} ) "
# tdLog.debug("1insert sql:%s"%sql) # tdLog.debug("1insert sql:%s"%sql)
if (j > 0) and ((j%batchNum == 0) or (j == rowsPerTbl - 1)): if (j > 0) and ((j%batchNum == 0) or (j == rowsPerTbl - 1)):
# tdLog.debug("2insert sql:%s"%sql) # tdLog.debug("2insert sql:%s"%sql)
...@@ -79,22 +81,22 @@ class TDTestCase: ...@@ -79,22 +81,22 @@ class TDTestCase:
stabname2="diagnostics" stabname2="diagnostics"
ctbnamePre1="rct" ctbnamePre1="rct"
ctbnamePre2="dct" ctbnamePre2="dct"
ctbNums=40 ctbNums=50
self.ctbNums=ctbNums self.ctbNums=ctbNums
rowNUms=200 rowNUms=5000
ts=1451606400000 ts=1451606400000
tdSql.execute(f"create database {dbname};") tdSql.execute(f"create database {dbname};")
tdSql.execute(f"use {dbname} ") tdSql.execute(f"use {dbname} ")
tdSql.execute(f''' tdSql.execute(f'''
create table {stabname1} (ts timestamp,latitude double,longitude double,elevation double,velocity double,heading double,grade double,fuel_consumption double,load_capacity double,fuel_capacity double,nominal_fuel_consumption double) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30)); create table {stabname1} (ts timestamp,latitude double,longitude double,elevation double,velocity double,heading double,grade double,fuel_consumption double) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30),load_capacity double,fuel_capacity double,nominal_fuel_consumption double);
''') ''')
tdSql.execute(f''' tdSql.execute(f'''
create table {stabname2} (ts timestamp,fuel_state double,current_load double,status bigint,load_capacity double,fuel_capacity double,nominal_fuel_consumption double) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30)) ; create table {stabname2} (ts timestamp,fuel_state double,current_load double,status bigint) tags (name binary(30),fleet binary(30),driver binary(30),model binary(30),device_version binary(30),load_capacity double,fuel_capacity double,nominal_fuel_consumption double) ;
''') ''')
self.create_ctable(tsql=tdSql,dbName=dbname,stbName=stabname1,ctbPrefix=ctbnamePre1,ctbNum=ctbNums) self.create_ctable(tsql=tdSql,dbName=dbname,stbName=stabname1,ctbPrefix=ctbnamePre1,ctbNum=ctbNums)
self.create_ctable(tsql=tdSql,dbName=dbname,stbName=stabname2,ctbPrefix=ctbnamePre2,ctbNum=ctbNums) self.create_ctable(tsql=tdSql,dbName=dbname,stbName=stabname2,ctbPrefix=ctbnamePre2,ctbNum=ctbNums)
self.insertData(tsql=tdSql,dbName=dbname,stbName=stabname1,ctbPrefix=ctbnamePre1,ctbNum=ctbNums,rowsPerTbl=rowNUms,startTs=ts,batchNum=1000) self.insertData(tsql=tdSql,dbName=dbname,stbName=stabname1,ctbPrefix=ctbnamePre1,ctbNum=ctbNums,rowsPerTbl=rowNUms,startTs=ts,batchNum=10000)
self.insertData(tsql=tdSql,dbName=dbname,stbName=stabname2,ctbPrefix=ctbnamePre2,ctbNum=ctbNums,rowsPerTbl=rowNUms,startTs=ts,batchNum=1000) self.insertData(tsql=tdSql,dbName=dbname,stbName=stabname2,ctbPrefix=ctbnamePre2,ctbNum=ctbNums,rowsPerTbl=rowNUms,startTs=ts,batchNum=10000)
# for i in range(ctbNum): # for i in range(ctbNum):
# if i %10 == 0 : # if i %10 == 0 :
# # tdLog.debug(f"create table rct{i} using readings (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}', NULL,'v2.3')") # # tdLog.debug(f"create table rct{i} using readings (name,fleet,driver,model,device_version) tags ('truck_{i}','South{i}','Trish{i}', NULL,'v2.3')")
...@@ -131,7 +133,7 @@ class TDTestCase: ...@@ -131,7 +133,7 @@ class TDTestCase:
# tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query ) # tdLog.info("avg value check pass , it work as expected ,sql is \"%s\" "%check_query )
def tsbsIotQuery(self): def tsbsIotQuery(self,insertinto=True):
tdSql.execute("use db_tsbs") tdSql.execute("use db_tsbs")
...@@ -143,10 +145,11 @@ class TDTestCase: ...@@ -143,10 +145,11 @@ class TDTestCase:
# test insert into # test insert into
tdSql.execute("create table testsnode (ts timestamp, c1 float,c2 binary(30),c3 binary(30),c4 binary(30)) ;") if insertinto == True :
tdSql.query("insert into testsnode SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);") tdSql.execute("create table testsnode (ts timestamp, c1 float,c2 binary(30),c3 binary(30),c4 binary(30)) ;")
tdSql.query("insert into testsnode SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);")
tdSql.query("insert into testsnode(ts,c1,c2,c3,c4) SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);")
tdSql.query("insert into testsnode(ts,c1,c2,c3,c4) SELECT ts,avg(velocity) as mean_velocity,name,driver,fleet FROM readings WHERE ts > 1451606400000 AND ts <= 1451606460000 partition BY name,driver,fleet,ts interval(10m);")
# test paitition interval fill # test paitition interval fill
...@@ -182,8 +185,7 @@ class TDTestCase: ...@@ -182,8 +185,7 @@ class TDTestCase:
# # 6. avg-daily-driving-session # # 6. avg-daily-driving-session
# #taosc core dumped # #taosc core dumped
# tdSql.execute("create table random_measure2_1 (ts timestamp,ela float, name binary(40))") tdSql.query(" SELECT _wstart as ts,name,floor(avg(velocity)/5) AS mv FROM readings WHERE name is not null AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0);")
# tdSql.query("SELECT ts,diff(mv) AS difka FROM (SELECT ts,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name,ts interval(10m) fill(value,0)) GROUP BY name,ts;")
# tdSql.query("select name,diff(mv) AS difka FROM (SELECT ts,name,mv FROM (SELECT _wstart as ts,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0))) group BY name ;") # tdSql.query("select name,diff(mv) AS difka FROM (SELECT ts,name,mv FROM (SELECT _wstart as ts,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0))) group BY name ;")
# tdSql.query("SELECT _wstart,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0)") # tdSql.query("SELECT _wstart,name,floor(avg(velocity)/10)/floor(avg(velocity)/10) AS mv FROM readings WHERE name!='' AND ts > '2016-01-01T00:00:00Z' AND ts < '2016-01-05T00:00:01Z' partition by name interval(10m) fill(value,0)")
...@@ -234,7 +236,9 @@ class TDTestCase: ...@@ -234,7 +236,9 @@ class TDTestCase:
tdLog.printNoPrefix("==========step1:create database and table,insert data ==============") tdLog.printNoPrefix("==========step1:create database and table,insert data ==============")
self.prepareData() self.prepareData()
self.tsbsIotQuery() self.tsbsIotQuery()
tdDnodes.stop(1)
tdDnodes.start(1)
self.tsbsIotQuery(False)
def stop(self): def stop(self):
tdSql.close() tdSql.close()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册