0
votes

I am trying to send HTTP requests using jmeter for which I am using a HTTP sampler. The http requests have a parameter TaskID and these parameters read from a CSV file. I just wanted to make changes on how the HTTP request will be send.

The CSV file looks like this

Time TaskID
9000 42353456
9000 53463464
9000 65475787
9300 42354366
9300 23423535
9600 43545756
9600 53463467
9600 23435346

Now I want to send request based on the Time. For example in Time 9000 there are 3 TaskID. So I want to send 3 HTTP requests with those TaskIDs at a time. Similarly for the other Times as well. Any idea on how to do it?

Update: enter image description here

1
I do not understand whether your "Time" is just a way of grouping TaskIDs or if you actually talk about time as in "3 TaskIDs after 9000 seconds, 2 TaskIDs another 300 seconds later, ...". Could you please clarify!monhelm
It is just a way to group TaskIDs. I am not calculating it.Afsana Khan

1 Answers

1
votes

I created a minimal working example for one possible solution.

enter image description here

Basically I read the csv in a JSR223 Sampler and group it with following groovy code in "read csv" sampler:

import org.apache.jmeter.services.FileServer

current_dir = FileServer.getFileServer().getBaseDir().replace("\\","/")
csv_lines = new File(current_dir + "/test.csv").readLines()

times = []

csv_lines.each { line ->
    line = line.split(",")
    time = line[0]
    task_id = line[1]
    if (vars.getObject(time)){
        tasks = vars.getObject(time)
        tasks.add(task_id)
        vars.putObject(time, tasks)
    }
    else{
        times.add(time)
        vars.putObject(time, [task_id])
    }
}

times.eachWithIndex { time, i ->
    vars.put("time_" + (i+1), time)
    }

Notes:

  • (i+1) is used because the ForEach Controller will not consider the 0th element

  • I used "," as csv separator and omitted the header line

  • the "initialize task_ids" sampler holds following code:

.

time = vars.get("time")
tasks = vars.getObject(time)
   
tasks.eachWithIndex {task, i ->
    vars.put(time + "_" + (i+1), task)
}

I hope, this helps!