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; /** * Provides a DoubleSum function that adds two or more Double values. * Mostly copied from LongSum */ public class DoubleSum extends AbstractFunction { private static final List<String> desc = new LinkedList<String>(); private static final String KEY = "__doubleSum"; static { desc.add("First double to add"); desc.add("Second long to add - further doubles can be summed by adding further arguments"); desc.add("Name of variable in which to store the result (optional),The author is guanyf"); } private Object[] values; /** * No-arg constructor. */ public DoubleSum() { } /** * {@inheritDoc} */ @Override public synchronized String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { JMeterVariables vars = getVariables(); Double sum = 0D; String varName = ((CompoundVariable) values[values.length - 1]).execute().trim(); for (int i = 0; i < values.length - 1; i++) { sum += Double.parseDouble(((CompoundVariable) values[i]).execute()); } try { sum += Double.parseDouble(varName); varName = null; // there is no variable name } catch (NumberFormatException ignored) { } String totalString = Double.toString(sum); if (vars != null && varName != null && varName.length() > 0) {// vars will be null on TestPlan vars.put(varName, totalString); } return totalString; } /** * {@inheritDoc} */ @Override public synchronized void setParameters(Collection<CompoundVariable> parameters) throws InvalidVariableException { checkMinParameterCount(parameters, 2); values = parameters.toArray(); } /** * {@inheritDoc} */ @Override public String getReferenceKey() { return KEY; } /** * {@inheritDoc} */ @Override public List<String> getArgumentDesc() { return desc; } }

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

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

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

  2. jmeter添加自定义扩展函数之if判断

    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的使用--添加自定义函数和导入自定义jar

    1.添加自定义函数,增加  号码生成函数 MobileGenerator和身份证生成函数IdCardGenerator 在package org.apache.jmeter.functions;中增加 ...

随机推荐

  1. C#将数据写入本地文件

    在平时开发过程中,可能会碰到内网测试没问题,但是更新到外网时会报错,这时我们又无法在外网进行调试.如果我们分析完业务可能产生的问题还是无法得到报错的原因,那么可以在关键的地方加上异常处理,然后将异常或 ...

  2. onblur和onkeyup事件

    onblur:事件会在对象失去焦点时发生 提示:onblur 相反事件为onfocus事件 . onkeyup: 事件会在键盘按键被松开时发生. 提示:与onkeyup 事件相关的事件发生次序: on ...

  3. Lua中C API栈操作

    向栈中压入数据: lua_pushnil(lua_State*); lua_pushboolean(lua_State*, bool); lua_pushnumber(lua_State*, lua_ ...

  4. 浏览器调起摄像头(jquery+layui)

    /* 实例化camvas配置参数 config = { video:{width:Number(scale*4),height:Number(scale*3)},//视频比例4:3 canvasId: ...

  5. eclipse 从git取项目,导入为maven项目,新加的方法,报加载主类错误

    eclipse 从git取项目,导入为maven项目,新加的方法,报加载主类错误 具体描述: 整体编译能够编译成功,但新加一个java,里面创建一个main方法,运行时,报无法加载主类的错误, 整体编 ...

  6. 怎么区分PV、IV、UV以及网站统计名词解释(pv、曝光、点击)

    PV(Page View)访问量,即页面访问量,每打开一次页面PV计数+1,刷新页面也是. IV(Internet Protocol)访问量指独立IP访问数,计算是以一个独立的IP在一个计算时段内访问 ...

  7. Pull Request的正确打开方式(如何在GitHub上贡献开源项目)

    Pull Request的正确打开方式(如何在GitHub上贡献开源项目) GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/f ...

  8. windos忘记密码登陆如何修复

    一.简单的方法: 开机启动windows,进入欢迎界面后,会出现输入用户名密码提示框,这时候,同时按住Ctrl+Alt+Delete,会跳出一个账号窗口,输入用户名:administer,按回车即可. ...

  9. UIWindow与UIView

    UIView与UIWindow * 一般应用程序只有一个UIWindow对象.所有的控件都是在UIWindow上展现的.每个UIView对象都有一个window属性,表示当前view显示在哪个窗体上. ...

  10. Kintex7 XC7K325T 板卡五兄弟

    Kintex 7五兄弟 1.     基KC705E 增强版基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡(136) 本板卡是Xilinx公司芯 ...