From 07f16b0443f746a19e1760ffb849224048306883 Mon Sep 17 00:00:00 2001 From: lichunlong <147397071@qq.com> Date: Sun, 28 Apr 2024 10:17:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E4=BE=8B20=E6=9D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...gauss_Function_Ustore_Transaction_Case0001 | 41 ----- openGaussBase/schedule/FU_ST_USTORE_PY.schd | 21 +++ ...ss_Function_Ustore_Transaction_Case0001.py | 115 ++++++++++++ ...s_Function_Ustore_Transaction_Case0001.sql | 40 ----- ...ss_Function_Ustore_Transaction_Case0031.py | 113 ++++++++++++ ...ss_Function_Ustore_Transaction_Case0032.py | 124 +++++++++++++ ...ss_Function_Ustore_Transaction_Case0033.py | 104 +++++++++++ ...ss_Function_Ustore_Transaction_Case0034.py | 146 +++++++++++++++ ...ss_Function_Ustore_Transaction_Case0035.py | 144 +++++++++++++++ ...ss_Function_Ustore_Transaction_Case0036.py | 141 +++++++++++++++ ...ss_Function_Ustore_Transaction_Case0037.py | 147 +++++++++++++++ ...ss_Function_Ustore_Transaction_Case0038.py | 164 +++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0039.py | 167 ++++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0040.py | 167 ++++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0041.py | 158 +++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0042.py | 165 +++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0043.py | 134 ++++++++++++++ ...ss_Function_Ustore_Transaction_Case0044.py | 136 ++++++++++++++ ...ss_Function_Ustore_Transaction_Case0045.py | 132 ++++++++++++++ ...ss_Function_Ustore_Transaction_Case0046.py | 132 ++++++++++++++ ...ss_Function_Ustore_Transaction_Case0047.py | 151 ++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0048.py | 157 ++++++++++++++++ ...ss_Function_Ustore_Transaction_Case0049.py | 144 +++++++++++++++ ...ss_Function_Ustore_Transaction_Case0050.py | 138 +++++++++++++++ ...ss_Function_Ustore_Transaction_Teardown.py | 45 +++++ 25 files changed, 3045 insertions(+), 81 deletions(-) delete mode 100644 openGaussBase/expect/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001 create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.py delete mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.sql create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0031.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0032.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0033.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0034.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0035.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0036.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0037.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0038.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0039.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0040.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0041.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0042.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0043.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0044.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0045.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0046.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0047.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0048.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0049.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0050.py create mode 100644 openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Teardown.py diff --git a/openGaussBase/expect/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001 b/openGaussBase/expect/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001 deleted file mode 100644 index 1d6b52a9b2..0000000000 --- a/openGaussBase/expect/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001 +++ /dev/null @@ -1,41 +0,0 @@ --- @owner: @kyleze --- @date: 2019-12-21 --- @testpoint: 通用用户创建 创建用户,默认加密表空间 ---step1:建表 插入数据;expect:成功 -drop schema if exists schema_ustore_trans cascade; -SQL SUCCESS -create schema schema_ustore_trans; -SQL SUCCESS -create table schema_ustore_trans.t_ustore_trans_0001(c_id int, -c_d_id int not null, -c_w_id int not null, -c_first varchar(16) not null, -c_middle char(2), -c_last varchar(16) not null, -c_street_1 varchar(20) not null, -c_street_2 varchar(20), -c_city varchar(20) not null, -c_state char(2) not null, -c_zip char(9) not null, -c_phone char(16) not null, -c_since timestamp, -c_credit char(2) not null, -c_credit_lim numeric(12,2), -c_discount numeric(4,4), -c_balance numeric(12,2), -c_ytd_payment real not null, -c_payment_cnt number not null, -c_delivery_cnt bool not null, -c_end date not null, -c_vchar varchar(1000), -c_data clob, -primary key (c_id,c_d_id,c_w_id)) with (storage_type=ustore); -SQL SUCCESS -insert into schema_ustore_trans.t_ustore_trans_0001 values(1,1,1,'is'||'1'||'cmRDs'||'1','OE','BAR'||'1'||'Bar'||'1','bkili'||'1'||'fcrRGF'||'1','pmbwo'||'1'||'vhSDGJ'||'1','dyf'||'1'||'rDa'||'1','uq',4801||'1',940||'1'||215||'1',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'GC',50000.0,0.4361328,-10.0,10.0,1,true,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'QVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSF'||'1','1234354587643123455213445656723123424554566776763221132454566768767433242323445453565654542323'); -SQL SUCCESS -begin - forall i in 1..1000 - insert into schema_ustore_trans.t_ustore_trans_0001 select c_id+i,c_d_id+i,c_w_id+i,'isi'||i,c_middle,'bar'||i,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim,c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_vchar,c_data from schema_ustore_trans.t_ustore_trans_0001 where c_id=1; -end; -/ -SQL SUCCESS diff --git a/openGaussBase/schedule/FU_ST_USTORE_PY.schd b/openGaussBase/schedule/FU_ST_USTORE_PY.schd index 5e754aad60..4017fc97db 100644 --- a/openGaussBase/schedule/FU_ST_USTORE_PY.schd +++ b/openGaussBase/schedule/FU_ST_USTORE_PY.schd @@ -133,5 +133,26 @@ test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_T test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0028 test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0029 test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0030 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0031 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0032 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0033 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0034 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0035 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0036 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0037 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0038 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0039 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0040 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0041 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0042 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0043 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0044 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0045 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0046 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0047 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0048 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0049 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0050 +test:COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Teardown test:COMPETITIVE/USTORE/SQL_TESTCASE/FUNCTION/regexp_substr/Opengauss_Function_Ustore_Regexp_Substr_Case0018 test:COMPETITIVE/USTORE/SQL_TESTCASE/FUNCTION/regexp_substr/Opengauss_Function_Ustore_Regexp_Substr_Case0019 diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.py new file mode 100644 index 0000000000..f4aafdc27c --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.py @@ -0,0 +1,115 @@ +""" +Case Type : 事务-ustore +Case Name : 创建所需要表 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建schema及表 + 2.插入数据 +Expect : + 1.成功 + 2.成功 +History : +""" +import os +import unittest + +from yat.test import Node + +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0001' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建schema及表;expect:成功----' + self.log.info(text) + q_str = f'''drop schema if exists schema_ustore_trans cascade; + create schema {self.schema}; + create table {self.schema}.{self.table}( + c_id int, c_d_id int not null, + c_w_id int not null, + c_first varchar(16) not null, + c_middle char(2), + c_last varchar(16) not null, + c_street_1 varchar(20) not null, + c_street_2 varchar(20), + c_city varchar(20) not null, + c_state char(2) not null, + c_zip char(9) not null, + c_phone char(16) not null, + c_since timestamp, + c_credit char(2) not null, + c_credit_lim numeric(12,2), + c_discount numeric(4,4), + c_balance numeric(12,2), + c_ytd_payment real not null, + c_payment_cnt number not null, + c_delivery_cnt bool not null, + c_end date not null, + c_vchar varchar(1000), + c_data clob, + primary key (c_id,c_d_id,c_w_id)) with + (storage_type=ustore);''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertIn(self.constant.CREATE_SCHEMA_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + + text = '--step2:插入数据 expect:成功--' + insert_sql = f"insert into {self.schema}.{self.table} " \ + f"values(1,1,1,'is'||'1'||'cmRDs'||'1','OE','BAR'||'1'||" \ + f"'Bar'||'1','bkili'||'1'||'fcrRGF'||'1','pmbwo'||'1'||" \ + f"'vhSDGJ'||'1','dyf'||'1'||'rDa'||'1','uq',4801||'1'," \ + f"940||'1'||215||'1'," \ + f"to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')," \ + f"'GC',50000.0,0.4361328,-10.0,10.0,1,true," \ + f"to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')," \ + f"'QVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZ" \ + f"CSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC3484932" \ + f"14893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSM" \ + f"NTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMf" \ + f"hlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDE" \ + f"TANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjl" \ + f"ufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893" \ + f"542NPFZCSfjlufvCDSF'||'1','12343545876431234552134456" \ + f"56723123424554566776763221132454566768767433242323445" \ + f"453565654542323');" \ + f"begin" \ + f" forall i in 1..1000" \ + f" insert into {self.schema}.{self.table} " \ + f" select c_id+i,c_d_id+i,c_w_id+i,'isi'||i,c_middle," \ + f" 'bar'||i,c_street_1,c_street_2,c_city,c_state," \ + f" c_zip,c_phone,c_since,c_credit,c_credit_lim," \ + f" c_discount,c_balance,c_ytd_payment," \ + f" c_payment_cnt,c_delivery_cnt,c_end,c_vchar," \ + f" c_data from {self.schema}.{self.table} " \ + f" where c_id=1;" \ + f"end;" + self.log.info(insert_sql) + insert_res = self.pri_sh.execut_db_sql(insert_sql) + self.log.info(insert_res) + self.assertIn(self.constant.CREATE_ANONYMOUS_BLOCK_SUCCESS_MSG, + insert_res, '执行失败' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, + insert_res, '执行失败' + text) + + def tearDown(self): + text = '----无需清理环境----' + self.log.info(text) + self.log.info(f'---{os.path.basename(__file__)} end---') + diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.sql b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.sql deleted file mode 100644 index 0027e54941..0000000000 --- a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0001.sql +++ /dev/null @@ -1,40 +0,0 @@ --- @owner: @kyleze --- @date: 2019-12-21 --- @testpoint: 通用用户创建 创建用户,默认加密表空间 - ---step1:建表 插入数据;expect:成功 -drop schema if exists schema_ustore_trans cascade; -create schema schema_ustore_trans; -create table schema_ustore_trans.t_ustore_trans_0001(c_id int, -c_d_id int not null, -c_w_id int not null, -c_first varchar(16) not null, -c_middle char(2), -c_last varchar(16) not null, -c_street_1 varchar(20) not null, -c_street_2 varchar(20), -c_city varchar(20) not null, -c_state char(2) not null, -c_zip char(9) not null, -c_phone char(16) not null, -c_since timestamp, -c_credit char(2) not null, -c_credit_lim numeric(12,2), -c_discount numeric(4,4), -c_balance numeric(12,2), -c_ytd_payment real not null, -c_payment_cnt number not null, -c_delivery_cnt bool not null, -c_end date not null, -c_vchar varchar(1000), -c_data clob, -primary key (c_id,c_d_id,c_w_id)) with (storage_type=ustore); - - -insert into schema_ustore_trans.t_ustore_trans_0001 values(1,1,1,'is'||'1'||'cmRDs'||'1','OE','BAR'||'1'||'Bar'||'1','bkili'||'1'||'fcrRGF'||'1','pmbwo'||'1'||'vhSDGJ'||'1','dyf'||'1'||'rDa'||'1','uq',4801||'1',940||'1'||215||'1',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'GC',50000.0,0.4361328,-10.0,10.0,1,true,to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'QVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSFQVLDETANRBRBURBMfhlhfrcllgfSMNTECC348493214893542NPFZCSfjlufvCDSF'||'1','1234354587643123455213445656723123424554566776763221132454566768767433242323445453565654542323'); - -begin - forall i in 1..1000 - insert into schema_ustore_trans.t_ustore_trans_0001 select c_id+i,c_d_id+i,c_w_id+i,'isi'||i,c_middle,'bar'||i,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim,c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_vchar,c_data from schema_ustore_trans.t_ustore_trans_0001 where c_id=1; -end; -/ diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0031.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0031.py new file mode 100644 index 0000000000..e7357ec4f3 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0031.py @@ -0,0 +1,113 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->插入数据->子回滚->主回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中插入数据 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询无数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0031' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中插入数据;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + savepoint point0031; + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback to savepoint point0031; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('1001 rows', q_res, '执行失败: ' + text) + self.assertIn('1001 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:0 rows----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('0 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0032.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0032.py new file mode 100644 index 0000000000..1c84ad605a --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0032.py @@ -0,0 +1,124 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->插入数据->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中插入数据 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询无数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0032' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中插入数据;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + savepoint point0032; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('1001 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:0 rows----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('0 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0033.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0033.py new file mode 100644 index 0000000000..50caade37c --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0033.py @@ -0,0 +1,104 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->插入数据->子回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中插入数据 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询无数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0033' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int + not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + + text = '----step2:;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + rollback to savepoint point0033; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('no such savepoint', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:0 rows----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('0 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0034.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0034.py new file mode 100644 index 0000000000..a2d38cd162 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0034.py @@ -0,0 +1,146 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->(delete)后的insert->提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0034' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0034_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0034_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0034_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0034_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0034_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0034_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + commit; + vacuum; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0035.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0035.py new file mode 100644 index 0000000000..6c5f88b17c --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0035.py @@ -0,0 +1,144 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->(delete)后的insert->回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0035' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0022_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0022_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0022_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0022_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0022_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0022_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0036.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0036.py new file mode 100644 index 0000000000..816d8275aa --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0036.py @@ -0,0 +1,141 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->(delete)后的insert->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0036' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0023_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0023_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0023_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0023_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0023_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0023_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0037.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0037.py new file mode 100644 index 0000000000..dbf73d6351 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0037.py @@ -0,0 +1,147 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->主提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询无数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0037' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0024_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0024_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0024_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0024_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0024_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0024_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + savepoint point0037; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + commit; + vacuum; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:1002----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0038.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0038.py new file mode 100644 index 0000000000..2a973de95f --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0038.py @@ -0,0 +1,164 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->主回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0038' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int + not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0025_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0025_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0025_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0025_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0025_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0025_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + savepoint point0038_01; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + savepoint point0038_01; + insert into {self.schema}.{self.table} select c_id+1000003,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0038_02; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0039.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0039.py new file mode 100644 index 0000000000..b413d5dc1f --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0039.py @@ -0,0 +1,167 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->子回滚->主提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0039' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + analyze {self.schema}.{self.table} ; + create unique index {self.schema}.index_ustore_trans_0026_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0026_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0026_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0026_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0026_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0026_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0039_01; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + savepoint point0039_01; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + savepoint point0039_02; + insert into {self.schema}.{self.table} select c_id+3000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback to savepoint point0039_01; + commit; + vacuum; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0040.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0040.py new file mode 100644 index 0000000000..d2b84d7df1 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0040.py @@ -0,0 +1,167 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->子回滚->主回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0040' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0027_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0027_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0027_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0027_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0027_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0027_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0040_01; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_data,c_clob from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0040_01; + insert into {self.schema}.{self.table} select c_id+3000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_data,c_clob from + {self.schema}.{self.table} where c_id=1; + savepoint point0040_02; + insert into {self.schema}.{self.table} select c_id+3000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_data,c_clob from + {self.schema}.{self.table} where c_id=1; + rollback to savepoint point0040_01; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0041.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0041.py new file mode 100644 index 0000000000..d3e0bdef6a --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0041.py @@ -0,0 +1,158 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0041' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0028_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0028_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0028_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0028_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0028_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0028_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0041; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + insert into {self.schema}.{self.table} select c_id+3000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end,c_data,c_clob from + {self.schema}.{self.table} where c_id=50; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0042.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0042.py new file mode 100644 index 0000000000..6920f4c830 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0042.py @@ -0,0 +1,165 @@ +""" +Case Type : 事务-ustore +Case Name : 索引->事务->子事务->(delete)后的insert->子回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0042' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + create unique index {self.schema}.index_ustore_trans_0029_01 on + {self.schema}.{self.table}(c_id,c_d_id); + create index {self.schema}.index_ustore_trans_0029_02 on + {self.schema}.{self.table}(c_id); + create index {self.schema}.index_ustore_trans_0029_03 on + {self.schema}.{self.table}(c_city); + create index {self.schema}.index_ustore_trans_0029_04 on + {self.schema}.{self.table}(c_first,c_state); + create index {self.schema}.index_ustore_trans_0029_05 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle); + create index {self.schema}.index_ustore_trans_0029_06 on + {self.schema}.{self.table}(c_id,c_d_id,c_middle,c_street_1); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.CREATE_INDEX_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0042; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + insert into {self.schema}.{self.table} select c_id+3000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback to savepoint point0042; + rollback; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0043.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0043.py new file mode 100644 index 0000000000..543daff8c4 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0043.py @@ -0,0 +1,134 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->(delete)后的insert->提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0043' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + commit; + vacuum; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0044.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0044.py new file mode 100644 index 0000000000..6a82157d3d --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0044.py @@ -0,0 +1,136 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->(delete)后的insert->回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0044' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int + not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0045.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0045.py new file mode 100644 index 0000000000..c174b41448 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0045.py @@ -0,0 +1,132 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->(delete)后的insert->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询无数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0045' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int + not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0046.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0046.py new file mode 100644 index 0000000000..79badf3578 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0046.py @@ -0,0 +1,132 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->(delete)后的insert->主提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0046' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + commit; + vacuum; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0047.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0047.py new file mode 100644 index 0000000000..8dc6910e9e --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0047.py @@ -0,0 +1,151 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->(delete)后的insert->主回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0047' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0047_01; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0047_02; + insert into {self.schema}.{self.table} select c_id+3000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0048.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0048.py new file mode 100644 index 0000000000..5bc12e7481 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0048.py @@ -0,0 +1,157 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->(delete)后的insert->子回滚->主提交->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0048' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + analyze {self.schema}.{self.table} ; + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0048; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback to savepoint point0048; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + insert into {self.schema}.{self.table} select c_id+3000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + commit; + vacuum; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('COMMIT', q_res, '执行失败: ' + text) + self.assertIn('VACUUM', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0049.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0049.py new file mode 100644 index 0000000000..3db3167736 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0049.py @@ -0,0 +1,144 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->(delete)后的insert->子回滚->主回滚->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0049' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0049; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback to savepoint point0049; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + rollback; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('ROLLBACK', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0050.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0050.py new file mode 100644 index 0000000000..e4f68f91a6 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Case0050.py @@ -0,0 +1,138 @@ +""" +Case Type : 事务-ustore +Case Name : 事务->子事务->(delete)后的insert->kill数据库 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.创建表 + 2.在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,小于删除的两条数据长度之和 + 3.kill数据库 + 4.查询数据 + 5.环境清理 +Expect : + 1.成功 + 2.成功 + 3.成功 + 4.查询有数据 + 5.成功 +History : +""" +import os +import sys +import unittest + +from yat.test import macro +from yat.test import Node + +from testcase.utils.Common import Common +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0050' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:创建表;expect:成功----' + self.log.info(text) + q_str = f'''drop table if exists {self.schema}.{self.table} cascade; + create table {self.schema}.{self.table}(c_id int,c_d_id int not null, + c_w_id int not null,c_first varchar(16) not null,c_middle char(22),c_last varchar(16) not null,c_street_1 varchar(20) not null,c_street_2 varchar(20),c_city varchar(20) not null, + c_state char(22) not null,c_zip char(9) not null,c_phone char(16) not null, + c_since timestamp,c_credit char(22) not null,c_credit_lim numeric(22,12),c_discount + numeric(4,4),c_balance numeric(22,12),c_ytd_payment real not null,c_payment_cnt number not null,c_delivery_cnt bool not null,c_end date not null,c_data clob,c_clob clob) with (storage_type=ustore); + insert into {self.schema}.{self.table} select * from {self.schema}.t_ustore_trans_0001; + delete from {self.schema}.{self.table} where mod(c_id,22)=0; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn(self.constant.TABLE_CREATE_SUCCESS, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + self.assertIn(self.constant.DELETE_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step2:在事务中,连续多次向表中插入数据,数据长度大于删除的1条数据,' \ + '小于删除的两条数据长度之和;expect:成功----' + self.log.info(text) + q_str = f'''start transaction; + insert into {self.schema}.{self.table} select c_id+1000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000001,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id=1; + insert into {self.schema}.{self.table} select c_id+1000002,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + savepoint point0050; + insert into {self.schema}.{self.table} select c_id+2000000,c_d_id,c_w_id,c_first,c_middle, + c_last,c_street_1,c_street_2,c_city,c_state,c_zip,c_phone,c_since,c_credit,c_credit_lim, + c_discount,c_balance,c_ytd_payment,c_payment_cnt,c_delivery_cnt,c_end, + lpad('sbfacwjdafgjyjhfpyxcpmnutcjxrbxxbm',350,'yxcfgdsgtcjxrbxxbm'), + lpad('sbfacwjpbvpgthpyxcpmnutcjxrbxxbm',300,'yxcpmnutcjxrbxxbm') from + {self.schema}.{self.table} where c_id<1000; + select distinct c_first,count(*) from {self.schema}.{self.table} group by c_first order by + c_first; + ''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('START TRANSACTION', q_res, '执行失败: ' + text) + self.assertIn('SAVEPOINT', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + self.assertIn(self.constant.INSERT_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + text = '----step3:kill-重启数据库;expect:成功----' + self.log.info(text) + result = self.pri_sh.restart_db_cluster() + self.log.info(result) + status = self.pri_sh.get_db_cluster_status() + self.assertTrue('Degraded' in status or 'Normal' in status) + + text = '----step4:查询数据;expect:956----' + self.log.info(text) + q_str = f'select distinct c_first,count(*) ' \ + f'from {self.schema}.{self.table} ' \ + f'group by c_first order by c_first;' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertNotIn('ERROR', q_res, '执行失败: ' + text) + self.assertIn('956 rows', q_res, '执行失败: ' + text) + + def tearDown(self): + text = '----step5:清理环境;expect:成功----' + self.log.info(text) + sql = f'drop table {self.schema}.{self.table} cascade;' + result = self.pri_sh.execut_db_sql(sql) + self.log.info(result) + self.assertIn(self.constant.TABLE_DROP_SUCCESS, result, + '执行失败: ' + text) + text = f'---{os.path.basename(__file__)} end---' + self.log.info(text) diff --git a/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Teardown.py b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Teardown.py new file mode 100644 index 0000000000..e9aded15e6 --- /dev/null +++ b/openGaussBase/testcase/COMPETITIVE/USTORE/STORAGE_TESTCASE/transaction/Opengauss_Function_Ustore_Transaction_Teardown.py @@ -0,0 +1,45 @@ +""" +Case Type : 事务-ustore +Case Name : 清理环境 +Create At : 2022/1/14 +Owner : @kyleze +Description : + 1.清理环境 +Expect : + 1.成功 +History : +""" +import os +import unittest + +from yat.test import Node + +from testcase.utils.CommonSH import CommonSH +from testcase.utils.Constant import Constant +from testcase.utils.Logger import Logger + + +class USTORE(unittest.TestCase): + def setUp(self): + self.pri_user = Node('PrimaryDbUser') + self.pri_sh = CommonSH('PrimaryDbUser') + self.constant = Constant() + self.log = Logger() + self.schema = 'schema_ustore_trans' + self.table = 't_ustore_trans_0001' + text = f'---{os.path.basename(__file__)} start---' + self.log.info(text) + + def testunit_1(self): + text = '----step1:清理环境;expect:成功----' + self.log.info(text) + q_str = f'''drop schema if exists schema_ustore_trans cascade;''' + self.log.info(q_str) + q_res = self.pri_sh.execut_db_sql(q_str) + self.log.info(q_res) + self.assertIn(self.constant.DROP_SCHEMA_SUCCESS_MSG, q_res, + '执行失败: ' + text) + + def tearDown(self): + self.log.info(f'---{os.path.basename(__file__)} end---') + -- Gitee