[LoadRunner]性能测试实践_Hessian协议脚本编写

时间:2024-07-31 12:06:32

第一步,新建LR的脚本,选择Java Vuser协议:

[LoadRunner]性能测试实践_Hessian协议脚本编写

第二步,编写hessian测试脚本,如下:

import lrapi.lr;
import java.net.MalformedURLException;
import kf.ats.gvnsvr.common.service.base.IBaseTimeService;
import com.caucho.hessian.client.HessianProxyFactory;

public class Actions
{
private static final String postUrl = "http://192.168.2.161:18081/test/HS/";
private static final String serverName="BaseTimeService";

public int init() throws Throwable {

return 0;
}//end of init
 
 
public int action() throws Throwable {

lr.start_transaction("deal");

HessianProxyFactory factory = new HessianProxyFactory();
     IBaseTimeService service;
     String result=null;
     try {
      service = (IBaseTimeService) factory.create(IBaseTimeService.class, postUrl + serverName);
      result=service.getCurrentTime().toString();
      System.out.println(result);
    } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
        }

if (result!=null) {
  lr.end_transaction("deal", lr.PASS);
     } else {
  lr.end_transaction("deal", lr.FAIL);
     }
     return 0;
}//end of action

public int end() throws Throwable {

return 0;
}//end of end
}

第三步,导入必要的jar类(这步很关键):

[LoadRunner]性能测试实践_Hessian协议脚本编写