Jmeter timestamp in jssrpreprocessor is same for multiple requests - jmeter

We have script, jssr preprocess which will copy the file from one bucket and paste it to another bucket in Amazon s3and http request which will take the file and do further processing.
Before copying file we do renaming filename with timestamp(function help builder). Everytime we do performance testing it has to pick unique file name.
But when I run send requests for 5 minutes, timestamp remain same, it's taking first timestamp through there is some second difference between each request. Is there any way each request to generate unique timestamp within jssr preprocessor

It's not very possible to come up with the solution without seeing your "script".
Blind shot: if you're using __time() function inside the JSR223 PreProcessor only first occurrence will be evaluated, on subsequent executions the same value will be used.
If this is the case either move the __time() function to the Parameters input field or use System.currentTimeMillis() function instead
Demo:
More information:
JSR223 Sampler Documentation
Apache Groovy - Why and How You Should Use It

Related

jMeter how to re-execute CSV Data Set Config

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)

How do I record a script in JMeter which adds a record in a website?

Currently, I am recording a script in jmeter by which I am adding a record in a website , but a problem is that while recording a script I am able to add a record in a website, but once recording has been done and after that if I will run a script again then, a script is not adding a record in a website.
can you please help me with this?
In the absolute majority of cases you will not be able to replay the recorded script without performing correlation.
Modern web applications widely use dynamic parameters for session management or CSRF protection so once you record your test you get "hardcoded" values and they need to be dynamic.
Assuming all above my expectation is that your test doesn't add record due to failed login or something like that. Inspect requests and responses using View Results Tree listener - this will allow you to identify which exact step is failing.
The process of implementing the correlation looks as follows:
Identify the element which looks to be dynamic either manually inspecting request parameters and look for "suspicious" patterns or record your test one more time and compare the recorded scripts looking for the parameters which differ
Inspect previous response and extract the dynamic value using a suitable post-processor. For HTML response times the best option is CSS Selector Extractor. It will allow you to extract the dynamic parameter value and store in into a JMeter Variable
Replace hardcoded recorded value with the variable from the step 2
Repeat for all dynamic parameters
Don't forget to add HTTP Cookie Manager to your Test Plan.

JMeter - How to make post processors reusable and use them on top of a test fragment on demand

Here is my scenario:
I created a test fragment for a sampler which is being used in many thread groups present in different jmx scripts. I sometimes would like to extract few values of this sampler result using few post processors.
Question:
How do I group and make these post processors reusable? I do not want to include as part of the test fragment itself as I don't need/want to execute post processor action every time.
Here is what I have tried:
I am able to save those post processors as a separate test fragment and include it in my test script right after the test fragment with the sampler whenever I want to execute them. I can save the sampler result to a jmeter variable and use it inside my post processor test fragment.
Is this a good approach? Please guide me.
Having Post-Procesors at the same level as all other Samplers is not a very good idea as they will be executed for each Sampler in their scope
Saving response data into a variable each time is also an overhead as according to your question you need the value sometimes
I would recommend using JSR223 Sampler to copy previous sampler response data and apply necessary Post-Processor(s) to it as child(ren).
The relevant code to copy the previous sampler response data would be as simple as:
SampleResult.setResponseData(ctx.getPreviousResult().getResponseData())
Where:
SampleResult - stands for current SampleResult
ctx - stands for JMeterContext
Check out Apache Groovy - Why and How You Should Use It article to learn more about Groovy scripting in JMeter conctept
The JSR223 Sampler can be saved as a Test Fragment as well.
Adding to #Dmitri T answer, in JSR PostProcessor you can save similar code in script file and reuse it
Script file A file containing the script to run, if a relative file path is used, then it will be relative to directory referenced by "user.dir" System property
Use the same script file in several post processors for re-usability:

Proper way to save Jmeter Results to csv - how to finalize results file

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 .....

how to get parameter from request sent in JMS Jmeter

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.

Resources