loadrunner数据库性能测试之oracle
2017-12-03 本文已影响69人
老林说测试
数据库性能测试也是性能调优中的一项工作,今天跟大家分享一个oracle数据库性能测试的脚本实例。首先我们在写脚本的时候第一件事必须确认好协议,数据库脚本一般选择webservices协议,脚本一般分为两个部分:数据库连接和oracle语句的执行
一、oracle在loadrunner连接的脚本如下:
vuser_init()
{
lr_start_transaction("login");
//数据库连接 Data Source=mydba NET服务名,"ConnectionName=testdb"服务名 ,User ID为数据库的用户名
lr_db_connect("StepName=Connect",
"ConnectionString=Provider=OraOLEDB.Oracle.1;Persist Security Info=True;Data Source=mydba;User ID=yy;Password=123456;Server=13.10.39.108",
"ConnectionName=testdb",
"ConnectionType=OLEDB",
LAST);
lr_end_transaction("login",LR_AUTO);
return0;
}
二、oracle语句执行的脚本,本例为查询语句
Action()
{
intNumRows=0;
inti=1;
lr_start_transaction("query");
//执行oracle语句
NumRows=lr_db_executeSQLStatement("StepName=PerformQuery",
"ConnectionName=testdb",
"SQLStatement=select YY,JJ from lj.yyx where rownum<48 ",
"DatasetName=MyDataset",
LAST);
lr_output_message("The query returned %d rows.",NumRows);
//打印出结果
lr_db_dataset_action("StepName=PrintDataset",
"DatasetName=MyDataset",
"Action=PRINT",
LAST);
//利用循环检索数据值
while(i<48){
lr_db_getvalue("StepName=GetValue",
"DatasetName=MyDataset",
"Column=YY",//列名
"Row=next",
"OutParam=MyOutputParam",
LAST);
lr_output_message("The value is: %s",lr_eval_string("{MyOutputParam}"));
i=i+1;}
lr_end_transaction("query",LR_AUTO);
return0;
}
三、脚本执行后的结果:
vuser_init.c(4): Notify: Transaction "login" started.
vuser_init.c(7): DB Connection "Connect" started ... Wait ....
vuser_init.c(7): DB connection was successful
vuser_init.c(12): Notify: Transaction "login" ended with "Pass" status (Duration: 0.2870 Wasted Time: 0.2713).
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action.
Action.c(6): Notify: Transaction "query" started.
Action.c(9): SQL Statement execution "PerformQuery" started
Action.c(9): SQL Statement execution was successful
Action.c(9): ================================================
Action.c(14): The query returned 47 rows.
Action.c(17): Dataset action "PrintDataset" started
Action.c(17):
Action.c(17): ******** Start printing ***********
Action.c(17): Number of records in dataset = 47
Action.c(17): Num. YY JJ
Action.c(17): =========================================================
Action.c(17): 1 10 ad
Action.c(17): 2 11 rt
Action.c(17): 3 12 fgf
Action.c(17): 4 13 fgf
Action.c(17): 5 26 fg
Action.c(17): 6 25 fg
Action.c(17): 7 24 fgf
Action.c(17): 8 23 fge
Action.c(17): 9 22 f
Action.c(17): 10 21 fg
Action.c(17): 11 20 fg
Action.c(17): 12 19 dfg
Action.c(17): 13 18 gf
Action.c(17): 14 17 fg
Action.c(17): 15 16 fg
Action.c(17): 16 15 fg
Action.c(17): 17 14 fg
Action.c(17): 18 27 fg
Action.c(17): 19 28 f
Action.c(17): 20 40 d
Action.c(17): 21 41 dfg
Action.c(17): 22 38 f
Action.c(17): 23 39 f
Action.c(17): 24 44 dfgdfg
Action.c(17): 25 45 fg
Action.c(17): 26 42 fg
Action.c(17): 27 43 fd
Action.c(17): 28 37 dfgd
Action.c(17): 29 31 gf
Action.c(17): 30 32 fd
Action.c(17): 31 29 fg
Action.c(17): 32 30 fd
Action.c(17): 33 35 df
Action.c(17): 34 36 df
Action.c(17): 35 33 fd
Action.c(17): 36 34 f
Action.c(17): 37 46 fg
Action.c(17): 38 50 dfg
Action.c(17): 39 7 sd
Action.c(17): 40 6 ds
Action.c(17): 41 5 we
Action.c(17): 42 4 we
Action.c(17): 43 3 ww
Action.c(17): 44 2 qq
Action.c(17): 45 1 qq
Action.c(17): 46 8 sd
Action.c(17): 47 9 sd
Action.c(17): ********End printing ***********
Action.c(17):
Action.c(17): Dataset action was successful
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 10
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 11
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 12
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 13
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 26
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 25
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 24
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 23
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 22
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 21
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 20
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 19
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 18
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 17
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 16
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 15
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 14
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 27
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 28
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 40
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 41
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 38
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 39
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 44
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 45
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 42
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 43
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 37
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 31
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 32
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 29
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 30
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 35
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 36
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 33
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 34
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 46
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 50
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 7
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 6
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 5
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 4
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 3
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 2
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 1
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 8
Action.c(23): Get db value "GetValue" started
Action.c(23): Get db value was successful
Action.c(23): ================================================
Action.c(29): The value is: 9
Action.c(31): Notify: Transaction "query" ended with "Pass" status (Duration: 1.3776 Wasted Time: 0.4054).
本文章为个人原创,转载时请尊重版权