1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这里就不再赘述

2,代码如下:

 package com.mytest.functions;

 import org.apache.jmeter.engine.util.CompoundVariable;

 import org.apache.jmeter.functions.AbstractFunction;

 import org.apache.jmeter.functions.InvalidVariableException;

 import org.apache.jmeter.samplers.SampleResult;

 import org.apache.jmeter.samplers.Sampler;

 import org.apache.jmeter.threads.JMeterVariables;

 import java.util.Collection;

 import java.util.LinkedList;

 import java.util.List;

 public class If extends AbstractFunction {

     private static final List<String> desc = new LinkedList<String>();

     private static final String KEY = "__if";

     static {

         desc.add("Actual value");

         desc.add("Expected value");

         desc.add("Result if actual == expected");

         desc.add("Result if actual != expected");

         desc.add("Name of variable in which to store the result (optional)");

     }

     private Object[] values;

     public If() {

     }

     @Override

     public synchronized String execute(SampleResult previousResult, Sampler currentSampler)

             throws InvalidVariableException {

         String actual = getParameter(0);

         String expected = getParameter(1);

         String result = null;

         if (actual.equals(expected)) {

             result = getParameter(2).toString();

         } else {

             result = getParameter(3).toString();

         }

         JMeterVariables vars = getVariables();

         if (vars != null && values.length > 4) {

             String varName = getParameter(4).trim();

             vars.put(varName, result);

         }

         return result;

     }

     @Override

     public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException {

         checkMinParameterCount(parameters, 4);

         values = parameters.toArray();

     }

     @Override

     public String getReferenceKey() {

         return KEY;

     }

     @Override

     public List<String> getArgumentDesc() {

         return desc;

     }

     private String getParameter(int i) {

         return ((CompoundVariable) values[i]).execute();

     }

 }

jmeter添加自定义扩展函数之if判断的更多相关文章

  1. jmeter添加自定义扩展函数之图片base64编码

    打开eclipse,新建maven工程,在pom中引入jmeter核心jar包: <!-- https://mvnrepository.com/artifact/org.apache.jmete ...

  2. jmeter添加自定义扩展函数之DoubleSum

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  3. jmeter添加自定义扩展函数之小写转换大写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  4. jmeter添加自定义扩展函数之大写转换小写

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  5. jmeter添加自定义扩展函数之MD5加密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  6. jmeter添加自定义扩展函数之Strng---base64解密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  7. jmeter添加自定义扩展函数之String---base64加密

    1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...

  8. jmeter添加自定义扩展函数之图片base64

    原文连接:---------https://www.cnblogs.com/qiaoyeye/p/7218770.html----------- 打开eclipse,新建maven工程,在pom中引用 ...

  9. Jmeter入门4 添加断言 判断响应数据是否符合预期

    发出请求之后,通过添加断言可以判断响应数据是否是我们的预期结果. 1 在Jmeter中发送一个登录的http请求(参数故意输入错误).结果肯定是登陆失败啦. 但结果树中http请求的图标显示‘绿色’表 ...

随机推荐

  1. jQuery DataTables 问题:Cannot reinitialise DataTable

    解决:  destroy: true, var tabel = $('#userlist').DataTable({        destroy: true,                    ...

  2. mybatis 注解开发CRUD

    mybatis 的常用注解说明 @Insert:实现新增 @Update:实现更新 @Delete:实现删除 @Select:实现查询 @Result:实现结果集封装 @Results:可以与@Res ...

  3. 如何在Python中使用Linux epoll

    如何在Python中使用Linux epoll 内容 介绍 阻塞套接字编程示例 异步套接字和Linux epoll的好处 epoll的异步套接字编程示例 性能考量 源代码 介绍 从2.6版开始,Pyt ...

  4. 基于vux的Vue路由切换动画

    const history = window.sessionStorage history.clear() let historyCount = history.getItem('count') * ...

  5. 《JAVA设计模式》之观察者模式(Observer)

    在阎宏博士的<JAVA与模式>一书中开头是这样描述观察者(Observer)模式的: 观察者模式是对象的行为模式,又叫发布-订阅(Publish/Subscribe)模式.模型-视图(Mo ...

  6. Struts2之获取ServletAPI

    1.通过ServletActionContext类 //获取request对象 HttpServletRequest request = ServletActionContext.getRequest ...

  7. 记一次用Linux curl命令获取Django url返回值异常的问题

    问题描述: curl 检测 URL 返回值以判断服务器是否正常 原命令:curl -I -m 10 -o /dev/null -s -w %{http_code} --insecure $url 问题 ...

  8. Web前端基础学习-1

    HTML5/CSS简介 首先来说一说什么是HTML5,HTML5可以认为是字面上的意义,也就是HTML的第五代产品,当然从另一个角度来说它是一种新的富客户端解决方案. HTML5 将成为 HTML.X ...

  9. DTS

    一.DTS的加载过程   如果要使用Device Tree,首先用户要了解自己的硬件配置和系统运行参数,并把这些信息组织成Device Tree source file.通过DTC(Device Tr ...

  10. 一、asp的写法

    一.asp的写法  vs从来都不支持asp,但是可以用vscode写,好多年前写asp的时候,用的是dreamwaver,asp还有创建项目这一说法?调试搭个iis就行了   <html> ...