mirror of
https://github.com/taosdata/TDengine
synced 2026-05-24 10:09:01 +00:00
172 lines
6.5 KiB
Python
172 lines
6.5 KiB
Python
# author : wenzhouwww
|
|
from new_test_framework.utils import tdLog, tdSql
|
|
from ssl import ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE
|
|
import sys
|
|
import time
|
|
import os
|
|
import socket
|
|
import subprocess
|
|
sys.path.append(os.path.dirname(__file__))
|
|
|
|
class Test4dnode1mnodeBasicReplica1Insertdatas:
|
|
def setup_class(cls):
|
|
tdLog.debug(f"start to excute {__file__}")
|
|
cls.mnode_list = {}
|
|
cls.dnode_list = {}
|
|
cls.ts = 1483200000000
|
|
cls.db_name ='testdb'
|
|
cls.replicaVar = 1
|
|
cls.vgroups = 2
|
|
cls.tb_nums = 10
|
|
cls.row_nums = 100
|
|
|
|
|
|
def check_setup_cluster_status(self):
|
|
tdSql.query("select * from information_schema.ins_mnodes")
|
|
for mnode in tdSql.queryResult:
|
|
name = mnode[1]
|
|
info = mnode
|
|
self.mnode_list[name] = info
|
|
|
|
tdSql.query("select * from information_schema.ins_dnodes")
|
|
for dnode in tdSql.queryResult:
|
|
name = dnode[1]
|
|
info = dnode
|
|
self.dnode_list[name] = info
|
|
|
|
count = 0
|
|
is_leader = False
|
|
mnode_name = ''
|
|
for k,v in self.mnode_list.items():
|
|
count +=1
|
|
# only for 1 mnode
|
|
mnode_name = k
|
|
|
|
if v[2] =='leader':
|
|
is_leader=True
|
|
|
|
if count==1 and is_leader:
|
|
tdLog.notice("===== depoly cluster success with 1 mnode as leader =====")
|
|
else:
|
|
tdLog.notice("===== depoly cluster fail with 1 mnode as leader =====")
|
|
|
|
for k ,v in self.dnode_list.items():
|
|
if k == mnode_name:
|
|
if v[3]==0:
|
|
tdLog.notice("===== depoly cluster mnode only success at {} , support_vnodes is {} ".format(mnode_name,v[3]))
|
|
else:
|
|
tdLog.notice("===== depoly cluster mnode only fail at {} , support_vnodes is {} ".format(mnode_name,v[3]))
|
|
else:
|
|
continue
|
|
|
|
def create_db_check_vgroups(self):
|
|
|
|
tdSql.execute("drop database if exists test")
|
|
tdSql.execute("create database if not exists test replica 1 duration 100")
|
|
tdSql.execute("use test")
|
|
tdSql.execute(
|
|
'''create table stb1
|
|
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
|
|
tags (t1 int)
|
|
'''
|
|
)
|
|
tdSql.execute(
|
|
'''
|
|
create table t1
|
|
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
|
|
'''
|
|
)
|
|
|
|
for i in range(5):
|
|
tdSql.execute("create table sub_tb_{} using stb1 tags({})".format(i,i))
|
|
tdSql.query("show stables")
|
|
tdSql.checkRows(1)
|
|
tdSql.query("show tables")
|
|
tdSql.checkRows(6)
|
|
|
|
tdSql.query("show test.vgroups;")
|
|
vgroups_infos = {} # key is id: value is info list
|
|
for vgroup_info in tdSql.queryResult:
|
|
vgroup_id = vgroup_info[0]
|
|
tmp_list = []
|
|
for role in vgroup_info[3:-4]:
|
|
if role in ['leader', 'leader*', 'leader**', 'follower']:
|
|
tmp_list.append(role)
|
|
vgroups_infos[vgroup_id]=tmp_list
|
|
|
|
for k , v in vgroups_infos.items():
|
|
if len(v) == 1 and v[0] in ['leader', 'leader*', 'leader**']:
|
|
tdLog.notice(" === create database replica only 1 role leader check success of vgroup_id {} ======".format(k))
|
|
else:
|
|
tdLog.notice(" === create database replica only 1 role leader check fail of vgroup_id {} ======".format(k))
|
|
|
|
def create_db_replica_1_insertdatas(self, dbname, replica_num ,vgroup_nums ,tb_nums , row_nums ):
|
|
drop_db_sql = "drop database if exists {}".format(dbname)
|
|
create_db_sql = "create database {} replica {} vgroups {}".format(dbname,replica_num,vgroup_nums)
|
|
|
|
tdLog.notice(" ==== create database {} and insert rows begin =====".format(dbname))
|
|
tdSql.execute(drop_db_sql)
|
|
tdSql.execute(create_db_sql)
|
|
tdSql.execute("use {}".format(dbname))
|
|
tdSql.execute(
|
|
'''create table stb1
|
|
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp)
|
|
tags (t1 int)
|
|
'''
|
|
)
|
|
tdSql.execute(
|
|
'''
|
|
create table t1
|
|
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp)
|
|
'''
|
|
)
|
|
|
|
for i in range(tb_nums):
|
|
sub_tbname = "sub_tb_{}".format(i)
|
|
tdSql.execute("create table {} using stb1 tags({})".format(sub_tbname,i))
|
|
# insert datas about new database
|
|
|
|
for row_num in range(row_nums):
|
|
ts = self.ts + 1000*row_num
|
|
tdSql.execute(f"insert into {sub_tbname} values ({ts}, {row_num} ,{row_num}, 10 ,1 ,{row_num} ,{row_num},true,'bin_{row_num}','nchar_{row_num}',now) ")
|
|
|
|
tdLog.notice(" ==== create database {} and insert rows execute end =====".format(dbname))
|
|
|
|
def check_insert_status(self, dbname, tb_nums , row_nums):
|
|
tdSql.execute("use {}".format(dbname))
|
|
tdSql.query("select count(*) from {}.{}".format(dbname,'stb1'))
|
|
tdSql.checkData(0 , 0 , tb_nums*row_nums)
|
|
tdSql.query("select distinct tbname from {}.{}".format(dbname,'stb1'))
|
|
tdSql.checkRows(tb_nums)
|
|
|
|
def test_4dnode1mnode_basic_replica1_insertdatas(self):
|
|
"""Cluster 4 dnodes 1 mnode replica 1 insert
|
|
|
|
1. Create 4 node and 1 mnode cluster
|
|
2. Ensure above cluster setup success
|
|
3. Check mnode is leader and only 1 mnode
|
|
4. Create database with replica 1
|
|
5. Create 1 super table and 1 normal table
|
|
6. Create 5 subtables using super table
|
|
7. Ensure above tables created success
|
|
8. Insert each subtable 100 rows data
|
|
9. Check vgroups info , ensure each vgroup only has 1 leader role
|
|
|
|
Since: v3.0.0.0
|
|
|
|
Labels: common,ci
|
|
|
|
Jira: None
|
|
|
|
History:
|
|
-2025-11-01 Alex Duan Migrated from uncatalog/system-test/6-cluster/test_4dnode1mnode_basic_replica1_insertdatas.py
|
|
|
|
"""
|
|
self.check_setup_cluster_status()
|
|
self.create_db_check_vgroups()
|
|
self.create_db_replica_1_insertdatas(self.db_name , self.replicaVar , self.vgroups , self.tb_nums , self.row_nums)
|
|
self.check_insert_status(self.db_name , self.tb_nums , self.row_nums)
|
|
|
|
|
|
tdLog.success(f"{__file__} successfully executed")
|
|
|