mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
137 lines
68 KiB
Python
137 lines
68 KiB
Python
|
|
#!/usr/bin/python
|
||
|
|
###################################################################
|
||
|
|
# 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
|
||
|
|
#
|
||
|
|
###################################################################
|
||
|
|
# install pip
|
||
|
|
# pip install src/connector/python/
|
||
|
|
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
import sys
|
||
|
|
import getopt
|
||
|
|
import subprocess
|
||
|
|
from distutils.log import warn as printf
|
||
|
|
|
||
|
|
from util.log import *
|
||
|
|
from util.dnodes import *
|
||
|
|
from util.cases import *
|
||
|
|
from util.sql import *
|
||
|
|
|
||
|
|
import taos
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
fileName = "all"
|
||
|
|
deployPath = ""
|
||
|
|
testCluster = False
|
||
|
|
valgrind = 0
|
||
|
|
logSql = True
|
||
|
|
stop = 0
|
||
|
|
opts, args = getopt.gnu_getopt(sys.argv[1:], 'l:sgh', [
|
||
|
|
'logSql', 'stop', 'valgrind', 'help'])
|
||
|
|
for key, value in opts:
|
||
|
|
if key in ['-h', '--help']:
|
||
|
|
tdLog.printNoPrefix(
|
||
|
|
'A collection of test cases written using Python')
|
||
|
|
tdLog.printNoPrefix('-l <True:False> logSql Flag')
|
||
|
|
tdLog.printNoPrefix('-s stop All dnodes')
|
||
|
|
tdLog.printNoPrefix('-g valgrind Test Flag')
|
||
|
|
sys.exit(0)
|
||
|
|
|
||
|
|
if key in ['-l', '--logSql']:
|
||
|
|
if (value.upper() == "TRUE"):
|
||
|
|
logSql = True
|
||
|
|
elif (value.upper() == "FALSE"):
|
||
|
|
logSql = False
|
||
|
|
else:
|
||
|
|
tdLog.printNoPrefix("logSql value %s is invalid" % logSql)
|
||
|
|
sys.exit(0)
|
||
|
|
|
||
|
|
if key in ['-g', '--valgrind']:
|
||
|
|
valgrind = 1
|
||
|
|
|
||
|
|
if key in ['-s', '--stop']:
|
||
|
|
stop = 1
|
||
|
|
|
||
|
|
if (stop != 0):
|
||
|
|
if (valgrind == 0):
|
||
|
|
toBeKilled = "taosd"
|
||
|
|
else:
|
||
|
|
toBeKilled = "valgrind.bin"
|
||
|
|
|
||
|
|
killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -HUP > /dev/null 2>&1" % toBeKilled
|
||
|
|
|
||
|
|
psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled
|
||
|
|
processID = subprocess.check_output(psCmd, shell=True)
|
||
|
|
|
||
|
|
while(processID):
|
||
|
|
os.system(killCmd)
|
||
|
|
time.sleep(1)
|
||
|
|
processID = subprocess.check_output(psCmd, shell=True)
|
||
|
|
|
||
|
|
for port in range(6030, 6041):
|
||
|
|
usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port
|
||
|
|
processID = subprocess.check_output(usePortPID, shell=True)
|
||
|
|
|
||
|
|
if processID:
|
||
|
|
killCmd = "kill -9 %s" % processID
|
||
|
|
os.system(killCmd)
|
||
|
|
fuserCmd = "fuser -k -n tcp %d" % port
|
||
|
|
os.system(fuserCmd)
|
||
|
|
if valgrind:
|
||
|
|
time.sleep(2)
|
||
|
|
|
||
|
|
tdLog.info('stop All dnodes')
|
||
|
|
sys.exit(0)
|
||
|
|
|
||
|
|
tdDnodes.init(deployPath)
|
||
|
|
tdDnodes.setTestCluster(testCluster)
|
||
|
|
tdDnodes.setValgrind(valgrind)
|
||
|
|
|
||
|
|
tdDnodes.stopAll()
|
||
|
|
tdDnodes.addSimExtraCfg("compressMsgSize", "10240")
|
||
|
|
tdDnodes.deploy(1)
|
||
|
|
tdDnodes.start(1)
|
||
|
|
|
||
|
|
host = '127.0.0.1'
|
||
|
|
|
||
|
|
tdLog.info("Procedures for tdengine deployed in %s" % (host))
|
||
|
|
|
||
|
|
tdCases.logSql(logSql)
|
||
|
|
|
||
|
|
conn = taos.connect(
|
||
|
|
host,
|
||
|
|
config=tdDnodes.getSimCfgPath())
|
||
|
|
|
||
|
|
tdSql.init(conn.cursor(), True)
|
||
|
|
|
||
|
|
tdSql.execute("CREATE DATABASE IF NOT EXISTS t10b")
|
||
|
|
tdSql.execute("USE t10b")
|
||
|
|
tdSql.execute(
|
||
|
|
"CREATE TABLE IF NOT EXISTS s_sensor_info (ts TIMESTAMP, temperature INT, humidity FLOAT)")
|
||
|
|
|
||
|
|
start_time = int(round(time.time() * 1000))
|
||
|
|
for i in range(1, 1000):
|
||
|
|
tdSql.execute("IMPORT INTO s_sensor_info VALUES (1575129600000, 16, 19.405090) (1575129601000, 22, 14.377142) (1575129602000, 16, 16.868231) (1575129603000, 20, 11.565193) (1575129604000, 31, 13.009119) (1575129605000, 29, 18.136400) (1575129606000, 17, 13.806572) (1575129607000, 23, 14.688898) (1575129608000, 26, 12.931019) (1575129609000, 32, 12.185531) (1575129610000, 30, 13.608714) (1575129611000, 23, 18.624914) (1575129612000, 22, 12.970826) (1575129613000, 22, 12.065827) (1575129614000, 25, 16.967192) (1575129615000, 16, 10.283031) (1575129616000, 22, 16.072535) (1575129617000, 24, 10.794536) (1575129618000, 32, 10.591207) (1575129619000, 20, 13.015227) (1575129620000, 28, 15.410999) (1575129621000, 29, 12.785076) (1575129622000, 28, 15.305857) (1575129623000, 33, 12.820810) (1575129624000, 34, 13.618055) (1575129625000, 32, 12.971123) (1575129626000, 24, 10.974546) (1575129627000, 15, 10.742910) (1575129628000, 23, 16.810783) (1575129629000, 18, 13.115224) (1575129630000, 26, 17.418489) (1575129631000, 20, 17.302315) (1575129632000, 21, 14.283571) (1575129633000, 16, 16.826534) (1575129634000, 18, 19.222122) (1575129635000, 18, 14.931420) (1575129636000, 17, 19.549454) (1575129637000, 22, 16.908388) (1575129638000, 32, 15.637796) (1575129639000, 31, 15.517650) (1575129640000, 18, 14.038033) (1575129641000, 32, 19.859648) (1575129642000, 16, 13.220840) (1575129643000, 28, 16.445398) (1575129644000, 26, 16.695753) (1575129645000, 33, 13.696928) (1575129646000, 21, 15.352819) (1575129647000, 15, 12.388407) (1575129648000, 27, 11.267529) (1575129649000, 20, 14.103228) (1575129650000, 20, 16.250950) (1575129651000, 30, 16.236088) (1575129652000, 22, 18.305340) (1575129653000, 25, 17.360685) (1575129654000, 25, 14.978681) (1575129655000, 33, 14.096183) (1575129656000, 26, 10.019039) (1575129657000, 19, 19.158213) (1575129658000, 22, 15.593924) (1575129659000, 26, 18.780119) (1575129660000, 21, 16.001656) (1575129661000, 16, 18.458328) (1575129662000, 21, 16.417843) (1575129663000, 28, 11.736558) (1575129664000, 34, 18.143946) (1575129665000, 27, 10.303225) (1575129666000, 20, 19.756748) (1575129667000, 22, 12.940063) (1575129668000, 23, 11.509640) (1575129669000, 19, 18.319309) (1575129670000, 19, 16.278345) (1575129671000, 27, 10.898361) (1575129672000, 31, 13.922162) (1575129673000, 15, 19.296116) (1575129674000, 26, 15.885763) (1575129675000, 15, 15.525804) (1575129676000, 19, 19.579538) (1575129677000, 20, 11.073811) (1575129678000, 16, 13.932510) (1575129679000, 17, 11.900328) (1575129680000, 22, 16.540415) (1575129681000, 33, 15.203803) (1575129682000, 17, 11.518434) (1575129683000, 17, 13.152081) (1575129684000, 18, 11.378041) (1575129685000, 21, 15.390745) (1575129686000, 30, 15.127818) (1575129687000, 19, 16.530401) (1575129688000, 32, 16.542702) (1575129689000, 26, 16.366442) (1575129690000, 25, 10.306822) (1575129691000, 15, 13.691117) (1575129692000, 15, 13.476817) (1575129693000, 25, 12.529998) (1575129694000, 22, 15.550021) (1575129695000, 20, 15.064971) (1575129696000, 24, 13.313683) (1575129697000, 23, 17.002878) (1575129698000, 30, 19.991594) (1575129699000, 15, 11.116746) (1575129699990, 16, 19.405090) (1575129700990, 22, 14.377142) (1575129701990, 16, 16.868231) (1575129702990, 20, 11.565193) (1575129703990, 31, 13.009119) (1575129704990, 29, 18.136400) (1575129705990, 17, 13.806572) (1575129706990, 23, 14.688898) (1575129707990, 26, 12.931019) (1575129708990, 32, 12.185531) (1575129709990, 30, 13.608714) (1575129710990, 23, 18.624914) (1575129711990, 22, 12.970826) (1575129712990, 22, 12.065827) (1575129713990, 25, 16.967192) (1575129714990, 16, 10.283031) (1575129715990, 22, 16.072535) (1575129716990, 24, 10.794536) (1575129717990, 32, 10.591207) (1575129718990, 20, 13.015227) (1575129719990, 28, 15.410999) (1575129720990, 29, 12.785076) (1575129721990, 28, 15.305857) (1575129722990, 33, 12.820810) (1575129723990, 34, 13.618055) (1575129724990, 32, 12.971123) (1575129725990, 24, 10.974546) (1575129726990, 15, 10.742910) (1575129727990, 23, 16.810783) (1575129728990, 18, 13.115224) (15751297
|
||
|
|
|
||
|
|
end_time = int(round(time.time() * 1000))
|
||
|
|
tdLog.info("Execute time with compress: %dms" % (end_time - start_time))
|
||
|
|
|
||
|
|
simLogPath = tdDnodes.getSimLogPath()
|
||
|
|
grepCmd = "grep -a 'compress rpc msg, before:' -r %s | head -2" % simLogPath
|
||
|
|
output = subprocess.check_output(grepCmd, shell=True).decode("utf-8")
|
||
|
|
|
||
|
|
if output != "":
|
||
|
|
tdLog.info("Find %s in log file." % output)
|
||
|
|
tdLog.success("%s successfully executed! Compress works as expected." % __file__)
|
||
|
|
else:
|
||
|
|
tdLog.exit("%s failed! Compress does NOT works." % __file__)
|
||
|
|
|
||
|
|
conn.close()
|