zoukankan      html  css  js  c++  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.1libext

    jmeter测试dubbo接口

    启动zookeeper、provider

    重新启动jemter

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

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

    运行脚本

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

    修改参数值,改为jenkins

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

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

  • 相关阅读:
    (转)Linux 信号说明列表
    linux下socket函数之listen的参数backlog
    (转)auto_ptr与shared_ptr
    (转)关于两次fork
    收集外链
    (转+整理)Linux下Makefile的automake生成全攻略
    LINUX socket编程(转载)errno.h
    (转) socket编程——sockaddr_in结构体操作
    k Nearest Neighbor Search by CUDA
    CUDA Anisotropic Diffusion on a 2D Image
  • 原文地址:https://www.cnblogs.com/uncleyong/p/10732754.html
Copyright © 2011-2022 走看看