As the title suggests, I am trying to figure out how to change the File Upload path in JMeter after X amount of seconds. I need this since I am testing an API that uses 60 files and I need to cycle through each file every minute. I already have an idea of using CSV Data Set Config but I'm not sure if that will change the File Path every minute like I need it to. Or maybe even read from the CSV file once per minute?
Use __P() function to read the path to the file from a JMeter Property path
${__P(path,)}
Add another Thread Group to your Test Plan and use a Debug Sampler in combination with CSV Data Set Config to read the next filename from the CSV file into path JMeter Variable
Add a Constant Timer or Flow Control Action sampler to introduce 60 seconds of sleep between iterations
And finally add a JSR223 PostProcessor to convert path variable into path property:
props.put('path', vars.get('path'))
see Top 8 JMeter Java Classes You Should Be Using with Groovy article to learn what do these props and vars shorthands mean
That's it, Debug Sampler will be executed each 60 seconds, the CSV Data Set Config will read next value from the CSV file and the JSR223 PostProcessor will update the path property value with the new filename or file path.
Related
Using jMeter to set up a soak / load test that needs to run each request with different data. The structure I currently have is
Thread Group (2 Users, 2 Loops)
- Simple controller
-- Java Sampler (Custom Plugin) to convert CSV Formula data into NewThreadData.csv (as variable)
-- Java Sampler (Custom Plugin) to create directory of files created with NewThreadData.csv merged into a template
-- While Controller Condition - js NewThreadData column not = EOF
--- CSV Data Set Config NewThreadData.csv (Recycle False / Stop of EOF False) - filename passed as variable
--- JMS PUblisher with the FileName a variable using the filename column from within NewThreadData.csv
My problem is the on the second loop, the data is updated in NewThreadData.csv, but the CSV in the while loop never runs again.
Appears that the CSV Data Set Config "knows" it has been run, regardless of the actual CSV data.
Questions
How can I get the CSV Data Set Config to be rerun / re executed in this scenario?
Are there undocumented variables or means of getting the config to reprocess?
Is there a way to spawn a new thread on each iteration rather than reusing the existing thread, as the CSV does execute once for each "User"[thread]. I also tried Stop on EOF : True, but that stopped the second loop.
Aim is to eventually ramp up the user count and the number of loops (changing to forever); with there being about about 100 different combinations of data to be inserted on each loop. The formula I am using has time and thread number to give me data uniqueness along with other data that is dynamically created from a formula. Recycle on EOF is not feasible as I need to regenerate the csv contents on each loop. A super-csv I don't think is feasible to cover the load and soak scenarios.
Thanks in anticipation. Andrew
I don't think it's possible to "reset" the CSV Data Set Config, it's a configuration element hence once it reads the file in its current state it will "stick" to its content.
If you're manipulating file content dynamically I would rather recommend going for __CSVRead() function instead which is evaluated in the runtime just where it's placed therefore it doesn't reserve file and it "rewinds" to the beginning of the file when the last line is read.
More information: How to Pick Different CSV Files at JMeter Runtime
CSV Data Set Config element is executed first and only once even though you have placed it within the while controller. Hence CSV Data Set Config element is not suitable for your requirement.
You could use JSSR223 Pre-processor to work with the dynamic CSV files using a supported programming language/script (Java , Groovy)
There are multiple API thread groups and each thread group will have different configuration for threads, ramp up time, duration, throughput controller percent execution variable etc.
Can I pass these variable from a .csv file? My aim is to create a config file and pass as a input in non gui mode during execution.
I have seen option for setting property from command line like using J_ or defining property but as number of thread groups are huge I won't be able to use this option. Also CSV data, beanshell preprocessor config cannot be used as i have to set thread group level details.
You can use JMeter Plugin Variables From CSV to pass the variable from a CSV file to Thread Groups.
Create the test data in variable=value format
Install the plugins manager
Install the Plugin Variables From CSV through plugins manager
Add Variables From CSV config element and configure to read the variables and click on Test button
Copy the variables
Paste into the thread groups
I have created a test plan in Jmeter which executes certain queries and store elapsed time in csv file. I need to save row count against each sampler request. How can I achieve this?
Below is my CSV file configuration
Don't use any of JMeter Listeners to store test results, they don't add any value and create memory and disk IO overhead instead. You should be running your tests in command-line non-GUI mode like
jmeter -n -t test.jmx -l result.jtl
and when your test is finished either open result.jtl file with the listener of your choice or generate HTML Reporting Dashboard from it.
Coming back to your question. Given you have a JMeter Variable holding some "interesting" value and you would like this variable value to be added to test results just define sample_variables property and put the variable name there. For example, if you have JMeter Variable called rowcount add the next line to user.properties file:
sample_variables=rowcount
and next time you run your test you will see an extra column in the .jtl results file called rowcount holding the variable value for each and every sampler. See Sample Variables User Manual chapter for more details.
I do the same scenario that was already described in other topics not at once: I'm trying to save Jmeter results to database from csv file.
I have an Aggregate Report listener that saves results to csv file, and everything is OK here.
I also added TearDown Thread Group to my scenario that gets strings from this csv file (by CSV DataSet config) and processes it to database. This part also works fine with static CSV.
Two problems here:
Aggregate Report listener is added on the top level of scenario. So, it adds all samplers from TearDown group to results file as well. So, it's like a recursion: if I do teardown until end of result file, I'll never reach the end, as every new iteration adds some new rows.
At the moment when CSV dataset config takes csv file, it's still in memory only and not finalized to disk. So, file is just empty. How to tell Jmeter that it should write the content from memory to a file and close input stream?
Any ideas how to solve it?
I know that I can move Listener into threads, but in this case I have to duplicate it for every thread group. It's always better to have one listener in one place as I can potentially change its settings.
Thanks in advance.
There is a JMeter Property jmeter.save.saveservice.autoflush defaulting to false
# AutoFlush on each line written in XML or CSV output
# Setting this to true will result in less test results data loss in case of Crash
# but with impact on performances, particularly for intensive tests (low or no pauses)
# Since JMeter 2.10, this is false by default
#jmeter.save.saveservice.autoflush=false
You can amend its value by setting it to true so JMeter will write down each single line of results into the file and closing the file once done. It can be done in 2 ways:
Permanent: add the following line to user.properties file (located in JMeter's "bin" folder)
jmeter.save.saveservice.autoflush=true
You will need to restart JMeter to pick the change up
Ad-hoc: pass the property via -J command-line argument
jmeter -Jjmeter.save.saveservice.autoflush=true -n -t .....
I am using JMS publisher and have a request xml copied on text message area , this xml has a node where i have put a beanshell script so that at each request new timestamp gets appends to the node to keep each request unique. How can i get the list of that node for each request sent?
Amend your Beanshell code to store generated timestamp into a JMeter Variable like:
${__BeanShell(long ts = System.currentTimeMillis(); vars.put("timestamp"\,String.valueOf(ts)); return ts;)}
It will store generated timestamp into a JMeter Variable called ${timestamp}
Add the following line to user.properties file (lives under /bin folder of your JMeter installation)
sample_variables=timestamp
Next time you run JMeter you'll be able to see generated timestamp values in the last column of .jtl results file.
See Sample Variables User Manual chapter for details.
By the way, you can generate timestamp without calling Beanshell, JMeter provides __time() function which can return current time in different formats. See How to Use JMeter Functions article for comprehensive explanation.