0
votes

In Bean shell sampler I am getting the line count how to pass the line count to the Threadgroup

import org.apache.commons.io.FileUtils; 

int lines = FileUtils.readLines(new File("path to data file")).size(); 
vars.put("lines", String.valueOf(lines));

this lines variable I want to use to thread group how I can achieve this please help me on this

Updating the output of Debugsampler

JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage@1e59359f
START.HMS=081505
START.MS=1449648905577
START.YMD=20151209
TESTSTART.MS=1449652524822
applicationname=test
buildinfo=../data/Test.csv
env=Test
lines=77
package=.zip
2

2 Answers

0
votes

First, you can use Debug sampler to verify if you are successfully getting the desired value in your variable.

Second, you can simply call the this variable just like other user defined variables in JMeter. Put ${lines} where required.

If you still face any issues, then let me know in comment or edit your question to add further details.

0
votes

You cannot configure Thread Group loop count this way as it is being populated on JMeter launch. Here are the options:

  1. Use Loop Controller instead, it is possible to set the number of loops via variable
  2. Define "Loop Count" in Thread Group as a property, like ${__P(loops,)}. In that case you can get CSV file lines count before the test i.e. using the relevant OS command like:

    • type c:\temp\file.csv | find /c /v "~~~" - for Windows
    • cat /tmp/file.csv | wc -l for *nix

    and pass the resulting value to JMeter via -J command line key as:

    jmeter -Jloops=XX -t /path/to/your/testplan.jmx ...
    

See Apache JMeter Properties Customization Guide for more information on JMeter properties and ways of setting and overriding them.