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接口的脚本开发完成。
来源:oschina
链接:https://my.oschina.net/u/4356754/blog/3572773