I have been using jmeter with the below logic:
- Get all items
- get all item_ids in a variable using json extractor
- Using beanshell pre-processor choose one item_id
- Get all sub items for selected item_id
- Get all sub_item_ids in a variable using json extractor
- Choose sub_item_id using beanshell pre-processor
- Edit sub item of sub_item_id
Kindly find the bean shell script below:
import java.util.Random; var item_id_ALL_data=vars.get("item_id_ALL"); int item_id_max=Integer.parseInt(vars.get("item_id_matchNr")); int item_id_min = 1; int item_id_idx; if(item_id_max>1) { item_id_idx= item_id_min + (int) (Math.random() * ((item_id_max - item_id_min) + 1)); } else{ item_id_idx=0; } String item_idx=Arrays.asList(item_id_ALL_data.split(",")).get(item_id_idx); log.info("item_idx:"+item_idx); vars.put("item_id_edit",item_idx);
I had ran jmeter based on the above logic with 5 threads and 50 iterations. But sometimes I am getting the below error:
2022-11-29 18:30:21,719 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import java.util.Random; var item_id_ALL_data=vars.get("item_id_ALL"); i . . . '' : Typed variable declaration : Method Invocation get
This error has been thrown randomly when executed. Also only when executed for multiple times, say multiple loops and threads with all possibilities. How can this be solved?