简体   繁体   中英

How can I subset the Jmeter CSV entries?

I have a 100 users CSV file, for several reasons I always need to run tests with a subset of users.

I need for example to run the 1st 10 users 10 times each, eventhough i have a 100 users file.

Setting the sharing mode to current thread makes that all the threads start with the same user (the 1st one).. but what i need is to start in order.

Thread 1: user 1 
Thread 2: user 2
Thread 3: user 3
...

Just like it happens when you have sharing mode to "All Threads".. the problem is that, in this case, when it reaches the number of threads (say 10), it continues with the rest of the CSV entries for the rest of the loop.. so when it reaches Thread 10: user 10, then it goes to Thread 1: user 11.. when what I need is to continue to run tests with the first 10 users, in this case restart with thread 1: user 1 its 2nd run.

Any idea how to achieve ignoring rows 11-100? and run with 1-10?

Thanks!

The easiest solution is to manipulate the original file itselt, ie

  1. Make the backup of original CSV file
  2. Take first 10 rows and write it into the original file (so now it will be 10 lines instead of 100)
  3. Once your test is finished go back to the original the status quo by restoring the file from the backup

Example implementation:

  • setUp Thread Group

    • JSR223 Sampler

       import java.nio.file.Files def maxLines = 10 // amend this as required def file = new File('users.csv') def backup = new File('users.csv.bak') Files.copy(file.toPath(),backup.toPath()) file.delete() Files.lines(backup.toPath()).limit(maxLines).each {line -> file << line << System.getProperty('line.separator') } props.put('backup', backup) props.put('file', file) 
  • Normal Thread Group
  • tearDown Thread Group

    • JSR223 Sampler

       import java.nio.file.Files import java.nio.file.StandardCopyOption def file = props.get('file') def backup = props.get('backup') Files.copy(backup.toPath(),file.toPath(), StandardCopyOption.REPLACE_EXISTING) backup.delete() 

See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter

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