jmeter添加自定义扩展函数之DoubleSum
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的更多相关文章
- jmeter添加自定义扩展函数之图片base64编码
打开eclipse,新建maven工程,在pom中引入jmeter核心jar包: <!-- https://mvnrepository.com/artifact/org.apache.jmete ...
- jmeter添加自定义扩展函数之if判断
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之小写转换大写
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之大写转换小写
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之MD5加密
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之Strng---base64解密
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之String---base64加密
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- jmeter添加自定义扩展函数之图片base64
原文连接:---------https://www.cnblogs.com/qiaoyeye/p/7218770.html----------- 打开eclipse,新建maven工程,在pom中引用 ...
- jmeter的使用--添加自定义函数和导入自定义jar
1.添加自定义函数,增加 号码生成函数 MobileGenerator和身份证生成函数IdCardGenerator 在package org.apache.jmeter.functions;中增加 ...
随机推荐
- Python的一些高级特性
内容基本上来自于廖雪峰老师的blog相当于自己手打了一遍,加强加强理解吧. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493 ...
- 关于static以及final关键字
Static关键字: 可以用来修饰类中的属性.类中的方法.以及具体的某一个类. 1.用于修饰属性: 则表示该属性属于整个类,不论有多少个对象实例,所有的实例共同拥有一个static静态的成员变量.该变 ...
- HTML5-新增type属性
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- phpstudy开启PHPSocket扩展(windows系统)
PHP开启Socket扩展 一.windows系统(本地电脑) 1.打开phpstudy,设置——>配置文件——>打开php.ini(我安装的是PhpStudy v8.0,其他版本请自己找 ...
- 《JAVA设计模式》之桥接模式(Bridge)
在阎宏博士的<JAVA与模式>一书中开头是这样描述桥梁(Bridge)模式的: 桥梁模式是对象的结构模式.又称为柄体(Handle and Body)模式或接口(Interface)模式. ...
- [Python3] 021 面向对象 第一弹
目录 1. 面向对象概述 1.1 OOP 思想 1.2 几个名词 1.3 类与对象 2. 类的基本实现 2.1 类的命名 2.2 如何声明一个类 2.3 如何实例化一个类 2.4 如何访问对象成员 2 ...
- [Linux] 013 其他文件搜索命令
1. 文件搜索命令:locate 命令名称:locate 命令所在路径:/bin/locate 执行权限:所有用户 语法:locate 文件名 功能描述:在文件资料库中查找文件 范例: $ locat ...
- LeetCode #807. Max Increase to Keep City Skyline 保持城市天际线
https://leetcode-cn.com/problems/max-increase-to-keep-city-skyline/ 执行用时 : 3 ms, 在Max Increase to Ke ...
- pandas分组聚合案例
美国2012年总统候选人政治献金数据分析 导入包 import numpy as np import pandas as pd from pandas import Series,DataFrame ...
- Day6----Python的pyinstall库的使用
Python的pyinstaller库 pyinstaller的安装 介绍:pyinstaller是Python的第三方库,主要用于将Python代码打包成 可执行文件 ,以此达到就算没安装P ...