0
votes

I have multiple test CSV files (approx. 20 files with a million records (just one column of IDs) in each file) in a folder. I want to run a performance test using this data.

To loop through the files, I have made progress but I am stuck at one issue. First I will explain what I have accomplished so far and then the issue I am running into.

  1. Added a BeanShell sampler (script is below) under Thread Group. It creates file variables with file paths as values.
    e.g. file_1 = /Users/Code/JMeter-Campaign/data/file_1.txt
import java.io.*; 

File fileDir = new File("/Users/Code/JMeter-Campaign/data"); 
File[] fList = fileDir.listFiles(); 

int counter = 1; 

for (File file:fList) {
    if (! file.isHidden()) {
        vars.put("file_" + counter, file.getAbsolutePath());
        log.info("file_" + counter + "=" + vars.get("file_" + counter));    
        counter++;
    }
}
  1. Add ForEach controller to loop. Fields and values are below.

Input variable prefix : file
Start index for loop : 0
Output variable name: USER_FILE
Add _ before number - checked

  1. Added Beanshell Preprocessor as a child of ForEach controller. Converts vars in props.

    props.put("UserFile", vars.get("USER_FILE")); 
    
  2. Added CSV Data Set config as a child of ForEach controller.

Filename : ${__P(UserFile,)}
Delimeter: ,

First, I am testing a simple scenario - 3 files (file_1, file_2 and file_3) with 1 record in each.

It's looping through all 3 files (debugged using log.info, debug sampler, view results tree) however the data is coming from the last file only. So for file_1, data is from file_3

Also observer in the jmeter.log, jmeter.services.FileServer always points to the 3rd file.

Is there a better way to parameterize test CSV files? I want to my run the test with all records in the first file and then second file and so on. This will prevent server side caching.

1
I have edited your post to help make it more readable. Please look it over and make sure it makes sense, and further edit it if I have made it less clear.Dan Lowe

1 Answers

2
votes

You cannot parameterize CSV Data Set Config this way as file paths are being populated during test tree loading. All you can do is to define a property via i.e. -J command line argument like

jmeter -Jpath=/some/path.csv -n -t ....

and use __P() function like ${__P(path,)} in the CSV Data Set Config. But this way you won't be able to iterate.

So I would suggest considering __CSVRead() function which is evaluated during its execution time hence it may contain variables.

See Functions and Variables User Manual chapter and How to Use JMeter Functions post series for more detailed information on above and other JMeter Functions.