dubbo接口FindMemberInfoTest思路整合

package com.yzb.user_center;

/**
 * @Created by IntelliJ IDEA.
 * @Author tk
 * @Date 2018/7/31
 * @Time 11:43
 */

import com.alibaba.fastjson.JSON;
import com.xkx.service.base.ResponseResult;
import com.xkx.service.usercenter.api.XkxMemberApi;
import com.xkx.service.usercenter.request.data.XkxMemberQueryRequest;
import com.xkx.service.usercenter.response.XkxMemberResponse;
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.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;



public class FindMemberInfoTest extends AbstractJavaSamplerClient {
    private SampleResult results;
    private final String configLocation = "classpath:aplication-context.xml";
    private ApplicationContext appContext = null;
    private XkxMemberApi xkxMemberApi;
    private String memberIds;
    private String source;

    public Arguments getDefaultParameters() {
        Arguments args = new Arguments();
        args.addArgument("memberIds", "1065111");
        args.addArgument("source","13605245");

        return args;
    }
    //调用服务并获取接口对象
    public void setupTest(JavaSamplerContext context) {
        appContext = new ClassPathXmlApplicationContext(configLocation);
        xkxMemberApi = appContext.getBean("xkxMemberApi", XkxMemberApi.class);    }

    public SampleResult runTest(JavaSamplerContext context) {
        results = new SampleResult();
        memberIds=context.getParameter("memberIds", memberIds);
        source = context.getParameter("source",source);

        //方法
        XkxMemberQueryRequest  memberRequest= new  XkxMemberQueryRequest();
        memberRequest.setIsFilter(0);
        //获取memberIds是个list
        List<String> memberIds = new ArrayList<String>();

        memberRequest.setMemberIds(memberIds);
        memberRequest.setIsFilter(1);
        memberRequest.setSource(source);


        results.sampleStart();
        //对象关联方法,方法传入参数,用fiResp接受
        //xkxMemberApi对象,findMemberInfo方法,XkxMemberQueryRequest参数(分为:memberIds(list),isFilter(int整形),source
        ResponseResult<Map<String,XkxMemberResponse>> fiResp = xkxMemberApi.findMemberInfo(memberRequest);
        results.sampleEnd();

        Integer result = fiResp.getResult() == null ? 0 : fiResp.getResult();
        System.out.println("result***"+JSON.toJSONString(fiResp));
        results.setSuccessful(result.equals(1));

        return results;
    }

    public void teardownTest(JavaSamplerContext arg0) {
    }

    public static void main(String[] args) {
        Arguments argu = new Arguments();
        JavaSamplerContext javaSamplerContex = new JavaSamplerContext(argu);
        FindMemberInfoTest maintest = new FindMemberInfoTest();
        maintest.setupTest(javaSamplerContex);
        maintest.runTest(javaSamplerContex);
    }

}

代码思路分析:

1、关键的一句:ResponseResult<Map<String,XkxMemberResponse>> fiResp = xkxMemberApi.findMemberInfo(memberRequest);

xkxMemberApi:对象

findMemberInfo:方法

memberRequest:参数

2、XkxMemberQueryRequest memberRequest= new XkxMemberQueryRequest();

XkxMemberQueryRequest:方法的类型,声明以后就需要对参数就行传值

memberRequest.setMemberIds(memberIds);    传入参数 memberIds

3、和jmeter关联的地方,也是整个脚本比较核心的逻辑关系

 

args.addArgument("memberIds", "1065111");
args.addArgument("source","13605245");

memberIds=context.getParameter("memberIds", memberIds);
source = context.getParameter("source",source);


memberRequest.setMemberIds(memberIds);
memberRequest.setIsFilter(1);
memberRequest.setSource(source);

这三段代码的关系是:
1、jemter面板需要暴露出memberIds和source(即:需要传入的参数)
2、第二段的代码用文本来接受jemter传入的参数
3、第三段代码用方法的类型声明的变量接受memberIds和source并传入(即:memberRequest.setMemberIds(memberIds);)
----这样整体的参数就偶合起来了

 

 

 







 

posted @ 2018-07-31 21:03  尘封~~  阅读(278)  评论(0编辑  收藏  举报