Jmeter Uploading files using multiple threads - jmeter

I want to test file uploading using Jmeter.
I want to upload files using 5 threads concurrently.
1 Thread successfully uploads all the files but after that all threads says file exist (which makes sense)
Is there a way i can upload all files successfully from all 5 threads, may be generate new file name each time ?

This solution will work for the configurations that you shared, 5 concurrent users uploading 10 files each.
First of all, create separate files for each thread (you have 10 files, copy them into 50) and rename them as below
Thread1_file1_0
Thread1_file2_0
Thread1_file3_0
.
.
Thread1_file10_0
Thread2_file1_0
Thread2_file2_0
.
.
Thread5_file10_0
Then create a csv file and add file extensions in column A. Make sure that row 1 reflects the extension of Threadx_file1_0 and row 2 reflects the extension of Threadx_file2_0 file as below and save the csv file in the same folder of your jmx script
Now to the script configurations, add 2 counters before your POST request (which uploads the files) with below configurations
First counter
Start 0
Increment 1
Reference Name originalName
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration No
Second counter
Start 1
Increment 1
Reference Name Iteration
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration No
Now add a loop controller with loop count set to 10, then add another counter, OS Process Sampler and CSV Data Set Config as children of the loop controller with below configurations
Counter configurations
Start 1
Increment 1
Reference Name fileNumber
Track counter independently for each user Yes
Reset counter on each Thread Group Iteration Yes
CSV Data Set Config
Filename extensionsCSVFile.csv
Variable Names extension
OS Process Sampler configurations
Command cmd
Command parameters
/C
ren {path to your folder}\Thread${__threadNum}_file${fileNumber}_${originalName}.${extension} Thread${__threadNum}_file${fileNumber}_${Iteration}.${extension}
Each line as a separate parameter. Now use file name in your post request as below
{path}\Thread${__threadNum}_file1_${Iteration}.pdf
{path}\Thread${__threadNum}_file2_${Iteration}.pdf
.
.
{path}\Thread${__threadNum}_file10_${Iteration}.docx
This will do the job, but i suggest that you also add a way to revert the names back to Thread1_file1_0. You can do it by following the below steps
Add a BeanShell PostProcessor as a child of the OS Process Sampler with below code in the code area
props.put("lastIteration", vars.get("Iteration"));
Now add a tearDown Thread Group, then copy the loop controller with all its elements from previous above steps and paste into the tearDown Thread Group (except the BeanShell PostProcessor, remove it after you paste).
Now go the OS Process Sampler within the tearDown Thread Group and adjust the second parameter as below
ren {}\Thread${__threadNum}_file${fileNumber}_${__P(lastIteration)}.${extension} Thread${__threadNum}_file${fileNumber}_0.${extension}
Finally, just make sure that number of threads in both main thread group and tearDown Thread Group is the same, which in this case 5. The structure will be as below

Related

Forcing thread to take a particular value from CSV and does not change till the test is completed

I have CSV file which contains Mobile Number, for e.g. number.csv
1276543281
1276543282
1276543283
1276543284
1276543285
Configured CSV Data Set Config with following options
Recycle on EOF? : True
Stop Thread on EOF? : False
Sharing Mode: All Threads
Thread Group settings are given below:
Number of Threads: 5
Ramp-up: 1
Loop Count: 10
Now, when I execute it, threads take any number from CSV and on next iterations based on the thread completion takes the value from CSV.
I want to force Thread1 to take 1st row, Thread2 to take 2nd row and so on... till the loop count is reached or the duration is reached.
You won't be able to achieve the described behaviour using CSV Data Set Config, with the above configuration each thread will pick up the next value on each iteration.
There is no guarantee that 1st thread will pick 1st line and 2nd thread 2nd line.
If you want to "stick" each thread to the respective line from CSV you should use __groovy() function instead like:
${__groovy(new File('/path/to/your/number.csv').readLines().get(ctx.getThreadNum()),)}
where ctx stands for JMeterContext class instance, see Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information.
you can achieve this solution by two ways
You can achieve by keeping the CSV dataset config only once in the controller
You can achieve by using Baolu CSV Data Set Config, in your scenario, set block size for each threads as 1
In these two scenarios, the value picked in first iteration those same values would be picking in next iterations.

JMeter - How to execute multiple CSV Data Sets

I have two CSV files, test1.csv and test2.csv. These two tests are slightly different, but I want to test them through the same test plan and report on them together. Therefore, I thought I would create two test fragments.
I have a thread group called 10 Concurrent Users because it's a thread group that will have 10 threads. I want this thread group to first run the Test 1 Test Fragment and then Test 2 Test Fragment. I want each test fragment to end after the corresponding CSV file reaches EOF.
I understand I can set Stop thread on EOF to true, but I don't want to stop the thread. I just want to "end" this test fragment. How do I do this?
This is what my Thread Group looks like. I don't want it to run infinitely, and I don't want to hard code the number of iterations.
One way I found was to just have two separate thread groups. One thread group for the first CSV file and one thread group for the second CSV file. Set the Thread Groups to "Infinite" and have "Stop Thread on EOF" set to true for each Data Set Module. However, it would be nice to not have to have separate thread groups as they are just duplicates of each other
In same thread group define a While Controller per CSV Data Set Config
Define in While's condition the value you get from CSV
Define an while controller with the Condition as ${url}
And don't recycle list on EOF:
To stop execution after the end of the CSV file is reached: within the CSV Data Set Config set Recycle on EOF? = False and Stop thread on EOF? = True.
If you want to iterate all the values in the CSV file and then continue you can configure the CSV Data Set Config like:
and put your Sampler(s) under the While Controller using the following __jexl3() function as the condition:
${__jexl3("${myVar}" != "<EOF>",)}
Another option is putting the logic under the Loop Controller, the number of lines in the CSV file can be determined dynamically using the following __groovy() function
${__groovy(new File('/path/to/your/file.csv').readLines().size(),)}

jmeter loop through multiple files

I have a Jmeter test with multiple while controler, each looping through data in separate files
I want each while loop to loop through the end of that file.
Structure:
While controller 1
- CSV Data Config 1
- Http sampler 1
While Controller 2
- CSV Data Config 2
- http sampler 2
When I set as an end condition: ${__javaScript(${myVar}!="<EOF>")} with stop thread on end of file to true, it stops the whole test completly.
If I set stop on end of file to false it loops on the also, meaning it loops one time too many
Is there another way to do this?
Thanks
A possible solution would be use beanshell processor and find the number of records in each file. Use the number of lines as the condition to break out of the loop. Please note that you will have to use parseint in the while condition as discussed in this thread.
Another option could be changing your While Controller to do the infinite loop and control thread stopping via CSV Data Set Config.
As per Using CSV DATA SET CONFIG guide:
It is worth mentioning that every CSV Data Set Config is visible to all Thread Groups by default. If you need to use separate CSV Data Set Config for every Thread, you create a number of data files that you need and in every CSV Data Set Config set “Sharing mode” to “Current Thread”
So the following combination:
Recycle on EOF = false
Stop Thread on EOF = true
Sharing mode = Current Thread
Should do the trick for you.

how to use separate csv file for each thread

My scenario is like,
1. Login by multiple users (100 users)
2. Select 50 items by id's specific to user
I have placed id's for each user in separate csv file say user1.csv, user2.csv, user3.csv and so on.
My result should be like Thread 1 should take user1.csv and process all 50 id's in loop controller.
Thread 2 should take user2.csv and so on.
I tried with below example, but still couldn't find the solution.
Eg. I used file path as C:\abc\user${_threadNum}.csv
Or
C:\abc\user${_threadNum}.csv
Variable name in csv file is user_id
Requeat will look like /home/abc/${user_id}
I want thread 1 to use the user1.csv file and substitiue the value of user_id in the request and thread 2 should use user2.csv and so on.
If I execute my above plan, I am getting error as /home/abc/EOF
How is this possible in JMeter? Or any other approach?
Please provide solution with an example, since I am new to JMeter.
Create your files like comman_name_1,comman_name_2,comman_name_3
etc. & select current thread option from dropdown list present in csv data config set.This will allow threads to use different files per thread or put values in a single file and select current thread option.
It's easy, just add CSV Data Set Config to each thread (user1.csv for thread1 and so forth). Configure CSV Data Set config, and select one of this values in Sharing mode field:
Current thread group - each file is opened once for each thread group
in which the element appears
Current thread - each file is opened separately for each thread
UPD: I have done it right now, it works
Script looks like this:
I selected 'Current thread' in each CSV Data Set Config
I was making the mistake of using single underscore in fetching the count of thread.
We need to use double - underscore like this : ${__threadNum}
Note :

Difference between sharing modes "All threads" and "Current thread group" in Jmeter

What is the actual difference between Sharing mode "All threads" and "Current thread group" in Jmeter?
Can anyone explain in detail?
I have one liner definition but i am not able to understand it properly.
Thanks,
Rishil
Well, as per reference:
• All threads - (the default) the file is shared between all the threads.
• Current thread group - each file is opened once for each thread group in which the element appears
So in case of "All threads" if you have in your script more than 1 CSV Data Set Config elements that refer the same file the next CSV Data Set Config element will CONTINUE READING from previously opened file (i.e. in prevoius CSV Data Set Config element), and in case of "Current thread group" each subsequent CSV Data Set Config element will REOPEN your file.
Please look onto example below:
In this case each CSV Data Set Config element:
• uses the same csv-file;
• reads file once and till the EOF;
• reads file from beginning: file is re-opened each time because of Sharing Mode = Current thread group.
If in this case change Sharing Mode to "All threads" WITHOUT any other changes the 2nd (TG-04) and the 3rd (TG-05) CSV Data Set Config elements will read nothing because the csv-file will remain open after TG-03 and file cursor will point to end of file.
Implementation details find in CSVDataSet class description:
The class uses the FileServer alias mechanism to provide the different
share modes. For all threads, the file alias is set to the file name.
Otherwise, a suffix is appended to the filename to make it unique
within the required context. For current thread group, the thread
group identityHashcode is used; for individual threads, the thread
hashcode is used as the suffix.
UPDATE 2012-02-09:
Presume you have configuration as in comment below:
N threads
1 CSV Data Set Config
1 csv data file
N entries in csv data file
So you will get:
1. N appearances - in case of Sharing mode = "All threads" or "Current thread group": each thread will read 1 entry from csv: the 1st thread - the 1st entry, ..., the Nth thread - the Nth entry.
2. N*N appearances - in case of Sharing mode = "Current thread": each thread will read ALL the entries from csv.
Both the statements are for the case when CSV Data Set Config set with the following settings:
Recycle on EOF? = false
Stop thread on EOF? = false
(screenshot above).

Resources