您的位置:首页 > 其它

使用loadrunner编写dubbo接口的性能测试脚本

2016-08-13 16:00 726 查看
强大的不是loadrunner,而是spring和dubbo
近期跳槽换了份工作,新公司里使用dubbo和基于dubbo自己封装的一套中间件,于是性能测试就需要编写对dubbo类接口的脚本。
网上已经有一篇loadrunner压dubbo的文章,里面是通过编程的方式初始化与dubbo provider的连接和调用,但由于公司自己封装的那套中间件不提供编程方式访问,只能通过读取xml配置文件的方式来初始化,因此对脚本做了简单的修改。
将spring框架和dubbo相关的jar包拷贝到loadrunner脚本文件夹下,classpath里增加当前目录,applicationContext.xml也拷贝到脚本文件夹下,里面定义好dubbo的provider信息,loadrunner脚本内容如下:
/*
 * LoadRunner Java script. (Build: _build_number_)
 *
 * Script. Description:
 *                     
 */

    import org.springframework.context.support.ClassPathXmlApplicationContext;

    import com.alibaba.dubbo.demo.DemoService;//这里导入你定义的接口

    import lrapi.lr;

public class Actions
{       
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
    DemoService demoService;
    public int init() throws Throwable {
        demoService = (DemoService) context.getBean("demoService");
        return 0;
    }//end of init

    public int action() throws Throwable {
   
        lr.start_transaction("dubbo");
            String hello = demoService.sayHello("dio");
        System.out.println(hello);
        lr.end_transaction("dubbo",lr.PASS);
        return 0;
    }//end of action

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


以上脚本是个很简单的示例,使用jmeter封装java request同样可以实现dubbo类接口的调用,后续有空再补充。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息