Jmeter wont read csv file with line feed properly - jmeter

I have a thread which writes data to a csv file and data looks like this in that file, as you see below each data is separated by a , then line feed.
ApiKey
20a145260241463194bf84f43952da9c:dut8ghdt+iQrsmYEgKzHzF1It79aWRIjb/d1wM8U3WE=,
93,
d0e29bb7-476d-4a52-9527-e5d9bb0ac34a
In another thread I am trying to read the data so I have done the following. Added a "CSV Data Set Config" with correct filename variables X,Y,Z and my Delimiter I have tried all these A=,n or B=n or C=n, I am not able to get Y and Z properly. What am I doing wrong?

Synchronization of data between thread groups using CSV files is not the best idea as you will have to implement a form or read/write lock to ensure that only one thread is writing data to the CSV file at a time and that will cause throughput degradation.
So I would recommend going for one of the following solutions:
Use __setProperty() function to convert the data from JMeter Variables into JMeter Properties. JMeter Properties are global for the whole JVM therefore they can be accessed from another Thread Group(s). See Knit One Pearl Two: How to Use Variables in Different Thread Groups article for more information.
Use Inter-Thread Communication plugin which implements FIFO queue so you can block threads in 2nd thread group unless data from 1st thread group is available. You can install Inter-Thread Communication Plugin using JMeter Plugins Manager
Both approaches are in-memory therefore you will not need to store data in interim files.

Related

Can we parameterize Thread schedule details like Start Thread count, Initial delay etc. in Ultimate thread Group using csv/txt files?

We are trying to parameterize Thread schedule details like Start Thread count, Initial delay etc.
Since we have 50+ thread groups and handling them has become an issue.
Would like to know if Jmeter has any unknown feature for this or a workaround to achieve this?
Can we parameterize these values from a csv/txt file?\
Note: We have 50+ thread groups, hence using ${__CSVRead} and retrieve different values didn't work out.
Have tried out ${__CSVRead} but since we need different values for each thread, this isn't working out.
I can only think of "known" feature - using either user.properties file or a custom .properties file, i.e.
thread.group.1.start.threads=10
thread.group.1.initial.delay=5
thread.group.2.start.threads=50
thread.group.1.initial.delay=20
etc.
and you will be able to use __P() function in the Ultimate Thread Group to read the values from the .properties file:
If you put the values into user.properties file - you won't need to do anything else, the file will be picked up automatically, if you decide going for the custom .properties file - you will need to pass it via -q command-line argument:
jmeter -q /path/to/your/thread/group.properties -n t .....
More information:
Configuring JMeter
Apache JMeter Properties Customization Guide
Full list of command-line options

How to stop the concurrency between two transaction controller in two different thread groups

Here is my problem, I have two different thread groups which contains two different transaction controller named Upload a CSV file and Upload a XLS file to my target application. Is there any way I can prevent the concurrency between these two controller. Basically the objective is at same point of time two or more than two files (CSV and XLS type) shouldn't upload to my system.
At current I have put a Random Timers, like in the first thread group I am generating a value between 1sec-5sec and in the second thread group I am using 6sec-10sec. (please check the image)
Think Timer for CSV:
Think Timer for XLS:
Is there any better approach to do this? where non of the file upload should be at the same time.
Note: I am using all different set of users for these two request.
Do you realize that given your requirement you will be able to upload only one file at a time therefore it doesn't make a lot of sense to use more than one thread and to have more than one thread group?
Whatever.
There is a Critical Section Controller which ensures that it's child(ren) are only run using one thread at a time
You can also consider using Inter-Thread Communication Plugin so i.e. upload XLS will wait until upload CSV is done or vice versa.

JMETER Write and Read from the same CSV file between threadgroups

In JMeter, I have a thread group which creates order, I capature the relavant details of the order and write to a csv file.
I have another thread group which searches these orders, the data for which I am currently creating as part of the above thread group as a prerequsite for this step.
Rather I wanted to check if there is an option to write and read from the same csv file, just to avoid the data preparation ahead. Any suggestions on how I can achieve this? Any constraints forseen on running with multiple user writing and reading from the same file. Thanks
With 1 thread - yes.
With > 1 thread - still yes, but it will be dangerous due to race condition, writing into the same file by multiple threads will result in data corruption.
If you need to pass values between Thread Groups there are following options:
Inter-Thread Communication Plugin
__setProperty() function in 1st Thread Group and __P() function in the 2nd Thread Group if you don't want or cannot use the plugin
You can use Inter Thread Communication plugin to share data between thread groups.
You can put a string value into a queue from one thread, and then get that value from another thread, even in another Thread Group. This allows you having separate Thread Groups with some synchronization and parameter passing between them. There may be any number of FIFOs and they differ by "queue name".
Use the Inter-thread communication Post-processor to write the order information
User the Inter-thread communication Pre-processor to read the order information from another thread group
Sample Test Plan 1 Test Plan 2

Is there a way to pass user defined variable through csv file in JMeter?

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

JMeter - reusing random variables in another thread group

I currently have a test plan where I use a random variable to submit a post request to a given URL (/app/${app_id}).
I want to also re-use the random variable app_id to poll the status of that app (/app/${app_id}/status). Note there would be multiple requests to the status URL.
My current idea is to:
have one thread group that submits the posts
save a list of the randomly generated app_ids
in another thread group, read the list of app_ids and for each app_id, loop the status request
Is this a sensible approach? If so, how can I go about saving the randomly generated app_ids and then reading them?
Also, if there is a better approach to this situation, I'm all ears :)
You can pass the values from one thread group to another one using __setProperty() function like:
${__setProperty(appid-${__counter(FALSE)},${your_variable_holding_appid},)}
Each time the function will be called it will generate a JMeter Property in form of
appid-1=foo
appid-2=bar
appid-3=baz
etc.
Where numbers like 1, 2, etc. are coming from __counter() function
In another Thread Group you will be able to access the generated values using __P() function like:
${__P(appid-${__counter(FALSE)},)}
Demo:
See Apache JMeter Functions - An Introduction for more information on JMeter Functions concept.
There is more "advanced" way of passing JMeter variables between threads and even thread groups, moreover you will be able to synchronise your threads, i.e. don't start thread in 2nd thread group until variable is not set using Inter-Thread Communication plugin.
Solution with Thread Groups is feasible, although you also can do all that in one thread group, by configuring one of the threads to be "monitor", while remaining threads submit posts. Something like this:
Thread Group
If [${__threadNum} == 1]
Samplers to check status
If [${__threadNum} != 1]
Samplers to submit posts
One reason to use 1 thread group for both types of users is if you need any sort of synchronization between writing and reading app_id list - that is easier to achieve in one thread group. Or if you already have many thread groups.
As for providing app_id to various threads/thread groups, you can use one of the approaches:
To pass IDs from one thread group to the other without a file, you can use one of the methods described here (using properties is the most popular way).
In your case, probably the easiest is to save them in one property with some delimiter, e.g. ID1,ID2,.... The "status" thread then can get this property, split it using either script or __split function to convert property into serialized variables: app_id_1, app_id_2, etc. Those variables are a natural choice for ForEach Controller.
Also first thread group could be saving app_ids into file, while the other reads from the same file with CSV Data Set Config. A bit of caution here though, if they are doing it at the same time.
If app-ids can be pre-generated, a more economical approach would be to have SetUp Thread, which generates them and saves them to CSV file (you will only need one script, e.g. BeanShell to do that, see example here). And then both thread groups read from that file using CSV Data Set Config

Resources