Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以在jmeter中线程组的所有线程中使用变量吗?_Jmeter_Rate Limiting_Test Plan - Fatal编程技术网

我可以在jmeter中线程组的所有线程中使用变量吗?

我可以在jmeter中线程组的所有线程中使用变量吗?,jmeter,rate-limiting,test-plan,Jmeter,Rate Limiting,Test Plan,我正在尝试为限速行为创建一个测试计划。 我设置了一个每分钟阻塞X个请求的规则,我想检查在到达X个请求之前,我是否得到了响应代码200,然后,得到429。我创建了一个在所有线程之间共享的计数器,但它看起来很混乱,因为它不是线程安全的 这是我的beanshell“一次性控制器”: 这是beanshell的断言: String props_pre_fix = props.get("props_pre_fix" + ${section_id}); //log.info("p

我正在尝试为限速行为创建一个测试计划。 我设置了一个每分钟阻塞X个请求的规则,我想检查在到达X个请求之前,我是否得到了响应代码200,然后,得到429。我创建了一个在所有线程之间共享的计数器,但它看起来很混乱,因为它不是线程安全的

这是我的beanshell“一次性控制器”:

这是beanshell的断言:

String props_pre_fix = props.get("props_pre_fix" + ${section_id});
//log.info("props_pre_fix " + props_pre_fix);

//extract my counter from props
int my_counter = Integer.parseInt(props.get(props_pre_fix + "_my_counter"));

//extract last response code
String last_response_code = props.get(props_pre_fix + "_last_response_code");
log.info("last_response_code " + last_response_code);

//if last seconds is greater than current seconds it means we are in a new minute - set counter to zero
if(last_response_code.equals("429") && ResponseCode.equals("200")){
    log.info("we moved to a new minute - my_counter should be zero");
    my_counter = 0;
}

//increase counter
my_counter++;
log.info("set counter with value: " + my_counter);
//save counter
props.put(props_pre_fix + "_my_counter", my_counter + "");
log.info("counter has set with value: " + my_counter);

if (ResponseCode.equals("200")) {
    props.put(props_pre_fix + "_last_response_code", "200");
    if(my_counter <= ${current_limit}){
        Failure = false;
    } 
    else {
        Failure = true;
        FailureMessage = "leakage of " + (my_counter - ${current_limit}) + " requests";
    }
} 
else if (ResponseCode.equals("429")) {
    props.put(props_pre_fix + "_last_response_code", "429");
     if(my_counter > ${current_limit}){
            Failure = false;
    } 
}
String props\u pre\u fix=props.get(“props\u pre\u fix”+${section\u id});
//日志信息(“道具预修复”+道具预修复);
//从道具中提取我的计数器
int my_counter=Integer.parseInt(props.get(props_pre_fix+“_my_counter”);
//提取最后一个响应代码
字符串last_response_code=props.get(props_pre_fix+“_last_response_code”);
log.info(“上次响应代码”+上次响应代码);
//如果最后的秒数大于当前的秒数,这意味着我们进入了一个新的分钟数-将计数器设置为零
if(最后一个响应代码等于(“429”)&响应代码等于(“200”)){
log.info(“我们进入了新的一分钟-my_计数器应为零”);
我的计数器=0;
}
//递增计数器
我的计数器++;
log.info(“使用值设置计数器:“+my_计数器”);
//保存计数器
道具。放置(道具前固定+“\u我的计数器”,“我的计数器+”);
log.info(“计数器已设置值:“+my_计数器”);
如果(响应代码等于(“200”)){
道具放置(道具前固定+“\u最后一次响应代码”,“200”);
if(我的计数器${current\u limit}){
失败=错误;
} 
}
我使用道具来分享柜台,但我显然觉得这不是正确的方式。
你能建议我怎么做吗?

我认为不可能使用JMeter断言自动测试此要求,因为您无法访问当前吞吐量,因此我建议考虑交叉检查和图表(可以使用)

所有
200
429
响应都可以使用如下配置的响应断言标记为成功:

如果出于某种原因,您仍然希望以编程方式执行此操作,那么您可能希望查看用于在STDOUT中显示当前吞吐量的类源


另外请注意,对于脚本编写。

我认为不可能使用JMeter断言自动测试此需求,因为您无法访问当前吞吐量,因此我建议考虑交叉检查和图表(可以使用)

所有
200
429
响应都可以使用如下配置的响应断言标记为成功:

如果出于某种原因,您仍然希望以编程方式执行此操作,那么您可能希望查看用于在STDOUT中显示当前吞吐量的类源

另请注意,对于脚本编写,请参见
String props_pre_fix = props.get("props_pre_fix" + ${section_id});
//log.info("props_pre_fix " + props_pre_fix);

//extract my counter from props
int my_counter = Integer.parseInt(props.get(props_pre_fix + "_my_counter"));

//extract last response code
String last_response_code = props.get(props_pre_fix + "_last_response_code");
log.info("last_response_code " + last_response_code);

//if last seconds is greater than current seconds it means we are in a new minute - set counter to zero
if(last_response_code.equals("429") && ResponseCode.equals("200")){
    log.info("we moved to a new minute - my_counter should be zero");
    my_counter = 0;
}

//increase counter
my_counter++;
log.info("set counter with value: " + my_counter);
//save counter
props.put(props_pre_fix + "_my_counter", my_counter + "");
log.info("counter has set with value: " + my_counter);

if (ResponseCode.equals("200")) {
    props.put(props_pre_fix + "_last_response_code", "200");
    if(my_counter <= ${current_limit}){
        Failure = false;
    } 
    else {
        Failure = true;
        FailureMessage = "leakage of " + (my_counter - ${current_limit}) + " requests";
    }
} 
else if (ResponseCode.equals("429")) {
    props.put(props_pre_fix + "_last_response_code", "429");
     if(my_counter > ${current_limit}){
            Failure = false;
    } 
}