未验证 提交 c7d7133f 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #6440 from taosdata/xiaoping/test_case

[TD-4630]<test>: add exception handling for restful insert
...@@ -40,12 +40,13 @@ class RestfulInsert: ...@@ -40,12 +40,13 @@ class RestfulInsert:
if tableID + i >= self.numOfTables : break if tableID + i >= self.numOfTables : break
name = 'beijing' if (tableID + i) % 2 == 0 else 'shanghai' name = 'beijing' if (tableID + i) % 2 == 0 else 'shanghai'
data = "create table if not exists %s.%s%d using %s.meters tags(%d, '%s')" % (self.dbname, self.tableNamePerfix, tableID + i, self.dbname, tableID + i, name) data = "create table if not exists %s.%s%d using %s.meters tags(%d, '%s')" % (self.dbname, self.tableNamePerfix, tableID + i, self.dbname, tableID + i, name)
response = requests.post(self.url, data, headers = self.header) try:
if response.status_code != 200: response = requests.post(self.url, data, headers = self.header)
print(response.content) if response.status_code != 200:
print(response.content)
except Exception as e:
print(e)
def insertData(self, threadID): def insertData(self, threadID):
print("thread %d started" % threadID) print("thread %d started" % threadID)
tablesPerThread = int (self.numOfTables / self.numOfThreads) tablesPerThread = int (self.numOfTables / self.numOfThreads)
...@@ -90,10 +91,16 @@ class RestfulInsert: ...@@ -90,10 +91,16 @@ class RestfulInsert:
if len(data) > 1024*1024 : if len(data) > 1024*1024 :
print ('batch size is larger than 1M') print ('batch size is larger than 1M')
exit(-1) exit(-1)
response = requests.post(self.url, data, headers = self.header) try:
if response.status_code != 200: startTime = time.time()
print(response.content) response = requests.post(self.url, data, headers = self.header)
endTime = time.time()
if response.status_code != 200:
print(response.content)
else:
print("inserted %d records, %d seconds" % (bloop, endTime - startTime))
except Exception as e:
print(e)
def insertUnlimitedData(self, threadID): def insertUnlimitedData(self, threadID):
print("thread %d started" % threadID) print("thread %d started" % threadID)
...@@ -119,10 +126,17 @@ class RestfulInsert: ...@@ -119,10 +126,17 @@ class RestfulInsert:
else: else:
random.shuffle(values) random.shuffle(values)
for k in range(len(values)): for k in range(len(values)):
data += values[k] data += values[k]
response = requests.post(self.url, data, headers = self.header) try:
if response.status_code != 200: startTime = time.time()
print(response.content) response = requests.post(self.url, data, headers = self.header)
endTime = time.time()
if response.status_code != 200:
print(response.content)
else:
print("inserted %d records, %d seconds" % (self.batchSize, endTime - startTime))
except Exception as e:
print(e)
def run(self): def run(self):
data = "create database if not exists %s" % self.dbname data = "create database if not exists %s" % self.dbname
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册