1
votes

I have this links.csv file:

METHOD,HOST,PATH,HITS
GET,google.com,/,7
GET,facebook.com,/,3

I want to create a JMeter test plan using Ultimate Thread Group (UTG) that randomize the hits based on the last column in the CSV above (HITS).

When viewing the results tree, I want to see something like this:

1. google.com
2. google.com
3. facebook.com
4. google.com
5. google.com
6. google.com
7. google.com
8. google.com
9. facebook.com
10. facebook.com

Ideally, I want to set the UTG to use the following settings:

  • Start Threads Count = sum of all hits in the CSV file (e.g. 7 + 3)
  • Initial Delay = 0
  • Startup Time = 60
  • Hold Load For = 30
  • Shutdown Time = 0

How to achieve this? I appreciate code samples and screenshots since I'm still new to JMeter.

1
If you pass the Host name like ${url} to the sampler name, you can view the url nameChandra Sekhar Y

1 Answers

0
votes

I can only think of generating a new CSV file out of your original one in order to:

  1. Get the "sum" of "HITS"
  2. Generate a line containing method, host and path per "hit"

In order to achieve this:

  1. Add setUp Thread Group to your Test Plan
  2. Add JSR223 Sampler to the Thread Group
  3. Put the following code into "Script" area:

    def entries = new File('/path/to/original.csv').readLines().drop(1)
    def sum = 0
    def newCSV = new File('/path/to/generated.csv')
    newCSV << 'METHOD,HOST,PATH' << System.getProperty('line.separator')
    
    entries.each { entry ->
        def values = entry.split(',')
        def hits = values[3] as int
        sum += hits
        1.upto(hits, {
            newCSV << values[0] << ',' << values[1] << ',' << values[2] << System.getProperty('line.separator')
        })
    }
    
    props.put('threads', sum as String)
    
  4. Use __P() function like ${__P(threads,)} in the Ultimate Thread Group
  5. Use the new "generated" CSV file in the CSV Data Set Config in the Ultimate Thread Group