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

协议选取和运行配置请参考:http://www.cnblogs.com/whylaughing/p/5430821.html

这次直接贴代码让大家参考:

import lrapi.lr;
import java.net.MalformedURLException;
import service.GetSystemTimeService;
import com.caucho.hessian.client.HessianProxyFactory;

public class Actions
{
private static final String postUrl = "http://192.168.5.222:7001/ats_dmz_server/RequestStoreServlet/test_nwwhl/time";

public int init() throws Throwable {

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

     lr.start_transaction("deal");
     String result=null;

     HessianProxyFactory factory=new HessianProxyFactory();
     try {
     GetSystemTimeService GetSystemTimeService=(GetSystemTimeService) factory.create(GetSystemTimeService.class, postUrl);
     System.out.print(GetSystemTimeService.getTime());
     result =GetSystemTimeService.getTime();
     lr.message(result);

     } catch (MalformedURLException e) {
         // TODO Auto-generated catch block
      e.printStackTrace();
        }
    
// 判断从服务端取回的结果是否正确,并判断事务是否通过(判断条件中的时间要根据测试时服务器的时间进行修改)
     if (result.equals("2016-09-07")) {
  lr.end_transaction("deal", lr.PASS);
  lr.message("the test result=pass");
     } else {
  lr.end_transaction("deal", lr.FAIL);
  lr.message("the test result=fail");
     }

     return 0;
}//end of action
 

public int end() throws Throwable {

  return 0;
}//end of end
}

原文地址:https://www.cnblogs.com/whylaughing/p/5849563.html