SAIR
SAIR

Reputation: 499

Forcing thread to take a particular value from CSV and does not change till the test is completed

I have CSV file which contains Mobile Number, for e.g. number.csv

1276543281
1276543282
1276543283
1276543284
1276543285

Configured CSV Data Set Config with following options

Recycle on EOF? : True
Stop Thread on EOF? : False
Sharing Mode: All Threads

Thread Group settings are given below:

Number of Threads: 5
Ramp-up: 1
Loop Count: 10

Now, when I execute it, threads take any number from CSV and on next iterations based on the thread completion takes the value from CSV.

I want to force Thread1 to take 1st row, Thread2 to take 2nd row and so on... till the loop count is reached or the duration is reached.

Upvotes: 0

Views: 312

Answers (2)

Pradeep Reddy
Pradeep Reddy

Reputation: 5

you can achieve this solution by two ways

  1. You can achieve by keeping the CSV dataset config only once in the controller
  2. You can achieve by using Baolu CSV Data Set Config, in your scenario, set block size for each threads as 1

enter image description here

In these two scenarios, the value picked in first iteration those same values would be picking in next iterations.

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168162

You won't be able to achieve the described behaviour using CSV Data Set Config, with the above configuration each thread will pick up the next value on each iteration.

There is no guarantee that 1st thread will pick 1st line and 2nd thread 2nd line.

If you want to "stick" each thread to the respective line from CSV you should use __groovy() function instead like:

${__groovy(new File('/path/to/your/number.csv').readLines().get(ctx.getThreadNum()),)}

where ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information.

Upvotes: 1

Related Questions