loadrunner之java协议脚本编写

1.导入相对应的jar包

2.使用java反编译工具反编译jar包,了解其中的业务流程,选择需要的service以及方法。以下以productWrapService服务为例。

3.在saf框架的配置文件中注册:

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:saf="http://code.xx.com/schema/saf"
	xmlns:dubbo="http://code.xx.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://code.xx.com/schema/saf http://code.xx.com/schema/saf/saf.xsd
	http://code.xxxx.com/schema/dubbo
	http://code.xxxx.com/schema/dubbo/dubbo.xsd"
	default-lazy-init="true">
	
        <saf:registry address="jdZooKeeper://192.168.12.159:2181" />
 				<saf:reference  id="productWrapService"  interface="xx.xx.xx.pbim.pbia.dubbo.service.ProductWrapService" group="xxxx" version="1.0"  timeout="30000"   />
 				<saf:reference  id="bookVideoService"  interface="xx.xx.xx.pbim.pbia.dubbo.service.BookVideoService" group="xxxx" version="1.0"  timeout="30000"   />
 				<saf:reference  id="attributeService"  interface="xx.xx.xx.pbim.pbia.dubbo.service.AttributeService" group="xxxx" version="1.0"  timeout="30000"   />
 </beans>


 4.编写loadrunner脚本:

 

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */

import lrapi.lr;

import com.xxx.catagory.pbim.pbia.dubbo.service.ProductWrapService;
import com.xxx.catagory.pbim.pbia.dubbo.model.ProductSort;
import java.util.*;
import java.lang.*;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Actions
{
        ProductWrapService r = null;
	public int init() throws Throwable {
	    		int i = 0;
                ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-dubbo.xml");//读环境配置XML,并注册SAF和redis认证
		r = (ProductWrapService)context.getBean("productWrapService",ProductWrapService.class); 
		return 0;
	}//end of init


	public int action() throws Throwable {
		Integer skuIdInteger;
		Set<Integer> cids = new HashSet<Integer>();
		String str=lr.eval_string("<P_sortid>");
		skuIdInteger = Integer.valueOf(str);
		cids.add(skuIdInteger);
		
		List<ProductSort> retList = new ArrayList<ProductSort>();
		ProductSort ps = new ProductSort();
		lr.start_transaction("productWrapService_queryProductSort");

		try
		{
		    retList = r.queryProductSort(cids);
                    for (Iterator i$ = retList.iterator(); i$.hasNext(); ) {
			ps = (ProductSort)i$.next();
			lr.output_message("+++++++++" + ps.getName());
		    }
		    //lr.output_message("++++++++" + retList);
		    if (retList != null) {
			lr.end_transaction("productWrapService_queryProductSort", lr.PASS);
		    }
		    else {
			lr.end_transaction("productWrapService_queryProductSort", lr.FAIL);
		    }
			
		}
		catch(Exception e) {
		    e.printStackTrace();
		}
		return 0;
	}//end of action


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

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值