遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

jmeter5.1测试dubbo接口

dubbo接口功能介绍

客户端输入uncleyong(当然,也可以是其他字符串),服务端返回hello uncleyong

此dubbo接口开发:https://www.cnblogs.com/uncleyong/p/10732747.html

开发dubbo服务jmeter客户端

idea中创建模块dubbo_jmeter5

默认输入uncleyong,也可以修改这个值

package com.uncleyong.dubbotest;

import com.uncleyong.dubbotest.service.SayHelloToClient;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.springframework.context.support.ClassPathXmlApplicationContext;



public class DubboJmeterNotFixArgs extends AbstractJavaSamplerClient {
    String param = "UncleYong";

    public Arguments getDefaultParameters(){
        Arguments params = new Arguments();
        params.addArgument("name", param);
        System.out.println(params);
        return params;
    }

    public void setValues(JavaSamplerContext args){
        param = args.getParameter("name",param);
    }

    public SampleResult runTest(JavaSamplerContext args) {
        setValues(args);
        SampleResult sr = new SampleResult();
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                new String[] { "dubbo_jmeter.xml" });
        sr.sampleStart();
        context.start();  // 启动上下文
        SayHelloToClient say = (SayHelloToClient) context.getBean("sayhellotoclient");
        String out = say.sayHello(param);
        sr.setResponseData("From dubbo provider:" + out, null);
        sr.setDataType(SampleResult.TEXT);
        sr.setSuccessful(true);
        return sr;
    }

}

jmeter客户端打jar包

 

项目的target目录下

将上面的jar包复制到jmeter的ext目录下,即:D:\apache-jmeter-5.1.1\lib\ext

jmeter测试dubbo接口

启动zookeeper、provider

重新启动jemter

添加线程组、java取样器、查看结果树后,

选择上面编写的类,展示了我们设置的参数名和参数值

运行脚本

运行结果,返回:From dubbo provider:hello, Uncleyong

修改参数值,改为jenkins

再次运行,返回:From dubbo provider:hello, jenkins

至此,jmeter测试dubbo接口的脚本开发完成。

 

posted @ 2019-04-14 10:07  全栈测试笔记  阅读(5323)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end