简体   繁体   中英

Jmeter If-controller in Http Request

So, for my question have a look at my Jmeter setup: Jmeter设置

Let me explain what's happening and then move on to my question.

Explanation On the server I have a guava cache (with timeout of 5 seconds) and a DB hooked up to it. Request A sends data (read from csv file) to the server and puts it in cache. It returns a unique ID corresponding with that data. Request B sends a seconds request (with that unique ID) that evicts the item from cache and saves to DB. The third request, C, uses that unique ID again to read from DB and process the data.

Now, to share that unique ID (and some other URL params) between thread groups I put them in a queue in Jmeter (using the jp@gc - Inter-Thread Communication PreProcessor and PostProcessor). All works like it should, both Jmeter and Server.

Question To finish up this setup I need to add one more thing... For each request A only 10% (random) of the unique IDs need to be put in queue A. And again for each request B only 10% (random) of those unique IDs need to be put in queue B. How can I do this last part if Jmeter does not allow if-controllers to be put as part of an http-request?

If anyone is interested in the answer. I found out that the easiest way to do this is to create a random variable (in variable rnd ) and a beanshell postprocessor, both under Http request A. The beanshell code is:

import kg.apc.jmeter.modifiers.FifoMap;

if (vars.get("rnd").equals("1")) {
    FifoMap.getInstance().put("QUEUE_A", "${uniqueId");
}

For Request B, analog to the procedure for Request A. Works perfectly.

Did you try to use Inter-Thread Communication PostProcessor outside of http-request - for instanse, inside "Simple Controller" which is placed after http-request? In this case you can use any logic controllers (if, throughput, etc.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM