io.metersphere.utils.JMeterVars Maven / Gradle / Ivy
package io.metersphere.utils;
import com.alibaba.fastjson.JSON;
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.extractor.JSR223PostProcessor;
import org.apache.jmeter.extractor.RegexExtractor;
import org.apache.jmeter.extractor.XPath2Extractor;
import org.apache.jmeter.extractor.json.jsonpath.JSONPostProcessor;
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jorphan.collections.HashTree;
import java.util.*;
public class JMeterVars {
private JMeterVars() {
}
/**
* 数据和线程变量保持一致
*/
private static Map variables = new HashMap<>();
/**
* 线程执行过程调用提取变量值
*
* @param testId
* @param vars
* @param extract
*/
public static void addVars(String testId, JMeterVariables vars, String extract) {
JMeterVariables vs = variables.get(testId);
if (vs == null) {
vs = new JMeterVariables();
}
if (!StringUtils.isEmpty(extract) && vars != null) {
List extracts = Arrays.asList(extract.split(";"));
if (CollectionUtils.isNotEmpty(extracts)) {
for (String item : extracts) {
String nrKey = item + "_matchNr";
Object nr = vars.get(nrKey);
JMeterVariables jMeterVariables = new JMeterVariables();
if (nr != null) {
int nrv = 0;
try {
nrv = Integer.valueOf(String.valueOf(nr));
} catch (Exception e) {
}
if (nrv > 0) {
List