0
votes

My goal is to POST to some URL from every thread in my thread group, which will create an asset somewhere. If all goes right, the first request will create the asset, then subsequent requests will see that the asset is already created (or in the process of being created), and will reuse that same asset.

The test plan:

  • Create N threads
    • HTTP Request - POST to some URL
    • Regular Expression Extractor - extract part of the response (the assetId generated by the POST request)
  • Verify that every thread extracted the same string from the response

My question:

What I don't have a clue how to do is the last step - verify that the value extracted from each thread is the same. How can this be done in JMeter?

2

2 Answers

2
votes

To achieve your requirement, we need to share the value among all the threads.

Properties:

We can use properties to share a value. Lets assume a prop 'shared' is created with default value as blank "". Add the below code in the beanshell assertion. If it is blank, then a thread will add the value extracted from the RegEx. All other threads will just compare the value and if it does not match, it will fail it.

if(props.get("shared")==""){
    props.put("shared") = "extracted";
}else{
    if(!props.get("shared").equals("extracted")){
        Failure = true; 
    }
}

Bsh.shared:

We can use the bsh.shared shared namespace to share the value among the threads and compare if the all the threads have the same value.

1.setup threadgroup will contain beanshell code like this to create a hashset.

import java.util.*;

if (bsh.shared.hashSet == void){
    bsh.shared.hashSet=new HashSet();
}
bsh.shared.hashSet.clear();

2.The regular thread group will contain the code for extracting the value. Once the value is extracted, add it to the hashset which stores only the unique values. Any duplicate values are simply ignored.

bsh.shared.hashSet.add("value extracted");

3.teardown threadgroup will group will check the hashset for the size. If the size is more than 1, then it failed.

log.info(String.valueOf(bsh.shared.hashSet.size()));
1
votes

I guess you can use Response Assertion.

  • The test plan:
    • Create N threads
    • HTTP Request - POST to some URL
  • Verify that every request has the same string in the response with Response Assertion enter image description here

When you place this assertion on the Test plan level it applies to all the threads.