0
votes

I have Jmeter java sampler to generate messages.

Testplan
- Threadgroup
     - Javasampler Publish message " $var3 population was $var1 in $var2 $_getthreadnumder"
     - Userdefined variables
          -var1 = {_stringfromfile(a.txt,,,) //file has values like 10, 20 till 5000
          -var2 = {_stringfromfile(b.txt,,,)   //file has values like 2000, 2001,... till 2017
      - Userdefined variables
          -var3 =   {_stringfromfile(c.txt,,,) 

This c.txt has around 500 names.

London
Madrid
Newyork
Paris
...
..

How to make each thread refer this file only once & stick to it till they execute last iteration.

For example, If I give 3 thread & 50 loops It should behave like :

First thread takes London & till it executes it 50th iteration, value should not change. Second thread takes Madrid & till it executes it 50th iteration, value should not change. Third thread takes Newyork & till it executes it 50th iteration, value should not change.

Output :

London population was 10 in 2000  1
Madrid population was 10 in 2000  2
Newyork population was 10 in 2000 3
London population was 20 in 2001  1
Madrid population was 20 in 2001  2
Newyork population was 20 in 2001 3
---
---

so on

I have tried once only & Sharing mode (all, current thread, current thread group)

Either they all the thread take London or they all share all the values from the top.

I want them to this var3 file only once & stick to it till end.

Any Ideas?

1

1 Answers

1
votes

you would use beanshell preProcessor to set the ${message} value in each thread with the corresponding value from the text file

import java.io.BufferedReader;
import java.io.InputStreamReader;

FileInputStream linesStream = new FileInputStream(pathToFile);
BufferedReader br = new BufferedReader(new InputStreamReader(linesStream));
int threadNum=ctx.getThreadNum();
//skipping lines that belong to other threads
for (int i = 1; i <= threadNum; ++i) {
   br.readLine();
}
String line = br.readLine();
br.close();
linesStream.close();
vars.put("message",line);

in the sampler call ${message} to use it