存储过程在性能测试中的应用
 
2009-01-15 来源: 网络
 

测试具有重复性,每个测试用例可能执行十几遍,我恨透了每执行一次测试,准备测试数据、还有清理测试数据都要花费大量的时间,怎么样做才能把这个时间减为0?在大量数据处理的性能测试中这个需求更迫切。怎么样做才能让测试环境更健壮呢?我执行了一次测试用例,喝杯水抽支烟的功夫,就能再次执行的同样的测试用例,想想多好呀。

在年前负责的工作流项目的性能测试过程中,遇到一个小问题,我们需要足够多的工作流用户。在实际生产环境中也是需要这么多的登录用户的,不可能出现几百个用户同时登录系统处理同样一条记录的情况吧。怎么解决这样的问题?在界面上一个用户一个用户的增加?800个用户呢?!因为登录用户的信息是维护在数据表里面的,在界面上的操作都会调用持久层的接口把用户信息保存在数据库的,我们如果明白后台SQL语句执行逻辑,是可以使用存储过程批量生成工作流用户的。这样就能保证每个工作流用户的待办任务显示的流程记录是不一样的。

下面是创建存储过程department_insert_test_users的SQL语句,可以像创建一个普通的表对象一样在SQL/PLUS里执行。这里只是演示使用,为避免泄漏项目信息,一些表名和字段已经删改,现在不保证在数据库可以执行通过。

create or replace procedure department_insert_test _users(testuser in varchar2,iCount in number) is
i int;
--parent department stru_id BPM
p_stru_id varchar2(30);
p_organ_id varchar2(30);
p_stru_path varchar2(20);
account varchar2(20);
var_organ_name varchar2(20);
var_organ_id varchar2(20);
var_stru_id  varchar2(20);
var_stru_path varchar2(1000);
begin
--insert bpm department
p_stru_id  :='Sp_stru_id00113';
p_organ_id :='Op_organ_id0113';
p_stru_path :='1#' || p_stru_id;

delete from test_stru where STRU_ID=p_stru_id;
delete from test_organ where organ_id=p_organ_id;
commit;
insert into TEST_ORGAN (ORGAN_ID, ORGAN_CODE, ORGAN_NAME, SHORT_NAME, ORGAN_TYPE, WORKPLACE_ID, BEGIN_DATE, END_DATE, SCN, IN_USE)
values (p_organ_id, '999902', 'BPM部门', 'BPM部门', '2', '1', '20080904', '99991231', 50, '1');
insert into TEST_STRU (STRU_ID, ORGAN_ID, ORGAN_ALIAS, STRU_TYPE, PARENT_ID, PRINCIPAL_ID, CORPORATION_ID, STRU_LEVEL, STRU_PATH, STRU_ORDER, GLOBAL_ORDER, BEGIN_DATE, END_DATE, SCN, IS_LEAF, IN_USE, DEPARTMENT_ID, PERMISSION_STRU_ID)
values (p_stru_id, p_organ_id, 'BPM部门', '00', '1', null, '1', 2, p_stru_path, 400, 1, '20080904', '99991231', 54, '0', '1', '1', '1');
commit;

for i in 1..iCount loop

 

--insert organ stru
var_organ_name :='BPM员工' || to_char(i);
var_organ_id :='vorgan_id' || to_char(i);
var_stru_id  :='vstru_id' || to_char(i);
var_stru_path :=p_stru_path ||'#'|| var_stru_id;

insert into TEST_ORGAN (ORGAN_ID, ORGAN_CODE, ORGAN_NAME, SHORT_NAME, ORGAN_TYPE, WORKPLACE_ID, BEGIN_DATE, END_DATE, SCN, IN_USE)
values (var_organ_id, var_organ_id, var_organ_name, var_organ_name, '8', '1', '20080904', '99991231', 57, '1');

insert into TEST_STRU (STRU_ID, ORGAN_ID, ORGAN_ALIAS, STRU_TYPE, PARENT_ID, PRINCIPAL_ID, CORPORATION_ID, STRU_LEVEL, STRU_PATH, STRU_ORDER, GLOBAL_ORDER, BEGIN_DATE, END_DATE, SCN, IS_LEAF, IN_USE, DEPARTMENT_ID, PERMISSION_STRU_ID)
values (var_stru_id, var_organ_id, var_organ_name, '00', p_organ_id, null, '1', 3, var_stru_path, 200, 1, '20080904', '99991231', 58, '1', '1', p_organ_id, '1');
--insert user
account := testuser || to_char(i);
insert into TEST_USERS (USER_ID, EXTERNAL_USER, USER_NAME, PASSWORD, ACCOUNT_STATUS, SECURITY_LEVEL, MAX_SESSIONS, IS_SYS, IS_CPUBLIC, CREATE_TIME, LOCK_TIME, EXPIRED_TIME, PSWD_UPT_TIME, PSWD_TIME, CORPORATION_ID, DEPARTMENT_ID, EMPLOYEE_ID, E_MAIL, MSN, QQ, MOBILE, CHAR_1, CHAR_2, NUM_1, NUM_2, PERMISSION_STRU_ID)
values (account, '01', var_organ_name, ' 99c6b157085564b43b85711360ec6166', '11', 0, -1, '0', '0', '20080904 16:12:57', null, '99991231 23:59:59', '20080904 16:12:57', '20081103 16:12:57', '1', p_stru_id, var_stru_id, null, null, null, null, null, null, 0, 0, '1');
insert into TEST_USER_DATAREF (REF_ID, USER_ID, RES_VALUE, DATA_RES_TYPE, IS_DEFAULT, IN_USE, STRU_ID, STRU_TYPE, DATE_BEGIN, DATE_END, IS_WRITABLE)
values (account, account, '1', 'permitOrgT', '1', '1', null, null, '20000101', '99991231', '1');
insert into TEST_USER_PROXY (USER_ID, PROXY_USER_ID)
values ('CPUBLIC', account);
insert into TEST_USER_PROXY (USER_ID, PROXY_USER_ID)
values ('GPUBLIC', account);
insert into TEST_USER_ROLE (USER_ID, GRANTED_ROLE, ADMIN_OPTION, DEFAULT_ROLE)
values (account, 'GPUBLIC', '1', '1');
insert into TEST_USER_ROLE (USER_ID, GRANTED_ROLE, ADMIN_OPTION, DEFAULT_ROLE)
values (account, 'SYSADMIN', '1', '1');
insert into TEST_USER_ROLE (USER_ID, GRANTED_ROLE, ADMIN_OPTION, DEFAULT_ROLE)
values (account, 'WORKFLOWADMIN', '1', '1');
insert into TEST_USER_ROLE (USER_ID, GRANTED_ROLE, ADMIN_OPTION, DEFAULT_ROLE)
values (account, 'WORKFLOWCOMUSER', '1', '1');
insert into TEST_STRU_TYPE_REF (USER_ID, STRU_TYPE, STRU_ID, ORGAN_NAME)
values (account, '00', '1', 'State Grid');
  end loop;
  commit;

end department_insert_test_users;

可以使用下面的语句在sql/plus窗口调用,'BPM'作为前缀需要大写:

SQL> call department_insert_test_users('BPM',100);

调用完成。

下面的两个存储过程delete_test_users,delete_test_stru_organ可以用于清除工作流用户数据,会清除BPM部门,BPM员工,BPM用户,后台的其他信息。调用方法如下:

SQL> call delete_test_users('BPM');

调用完成。

SQL>  call delete_test_stru_organ();

调用完成。


create or replace procedure delete_test_users(likecount  in  varchar2) is
likecount2 varchar2(30);
begin
  likecount2 :=likecount ||'%';

 delete from TEST_USER_ROLE  t where t.user_id like likecount2;
 delete from TEST_STRU_TYPE_REF t where t.user_id like likecount2;
 delete from  TEST_USER_PROXY t where t.user_id like likecount2 or t.proxy_user_id  like likecount2;
 delete from TEST_USER_DATAREF t where t.user_id  like likecount2;
 commit;
 delete from TEST_USERS t where t.user_id  like likecount2;
 commit;
 end delete_test_users;

create or replace procedure delete_test_stru_organ is
p_stru_id varchar2(30);
p_organ_id varchar2(30);
begin
p_stru_id  :='Sp_stru_id00113';
p_organ_id :='Op_organ_id0113';
delete from test_stru where STRU_ID=p_stru_id;
delete from test_organ where organ_id=p_organ_id;
delete from test_stru t where t.organ_id like 'vorgan_id%';
delete from test_organ t where t.organ_id like 'vorgan_id%';
commit;
end delete_test_stru_organ;

火龙果软件/UML软件工程组织致力于提高您的软件工程实践能力,我们不断地吸取业界的宝贵经验,向您提供经过数百家企业验证的有效的工程技术实践经验,同时关注最新的理论进展,帮助您“领跑您所在行业的软件世界”。
资源网站: UML软件工程组织