How to store request response data concurrently - jmeter-5.0

i'm setting a test plan running this thread groups sequentially:
Execute request A using 10 threads, 500 loops.
Execute request B using 10 thread, 500 loops, and the output from step 1.
My problem is this:
On each request A, i receive an ID that i need to pass to request B.
What is the best way to store all the IDs and then use them on step 2?
At this time, i am "JSonExtracting" each ID from response and store on a CSV file to pass to step 2.
The problem is the concurrence of the treads. Some times i got empty spots on the file or concatenated strings which will produce an error on step 2.
I was not able to store this to an array variable to use on step 2.
To write the IDs to a file, i am using this code on a BeanShell Listener inside my threadGroup. I strongly believe this is not the most correct way to do it.
f = new FileOutputStream("${DocumentIdsFile}", true);
p = new PrintStream(f);
p.println("${DocumentId}");
p.close();
f.close();
log.info("Id: ${Id}");
How can i solve this concurrence problem?

If you receive an ID at the request A, just use it in request B, passing it throug variable:
Parse ID value in request A response using one of the Post-Processors to store it in variable, for example "ID".
Use it's value in your request B as a parametr:
GET https://myserver.com/myapp/getSomethig/${ID}

Related

How to keep certain thread delay between requests and store correlation id for all the request during load test

May i know how to achieve this scenario in JMeter.
Requirement 1 : Request 1 should execute for 15 mins, once 15 mins crossed request 2 should execute and request 1 to be stopped.
Requirement 2 : In request 1, we need to capture all dynamic value and store it some place and same dynamic value we should use it as request body for request 2. We like to run large numbers of users. Not sure, how to store all the response in some files or other alternatives.
Ex : Request 1 - > Trigger -> Store response somewhere(15 min run & 100 iteration) - stopped
Request 2 - > Trigger after 15 min - Execute request with above 100 iteration response)
Either take a look at Runtime Controller, using this guy you can choose how long its child(ren) will be run or just put your requests 1 and 2 into separate Thread Groups
If you want to store full responses into a file take a look at:
Post-Processors to capture the required part of the response into a JMeter Variable
Sample Variables property to tell JMeter to save this variable into .jtl results file
Flexible File Writer if you want to write the values into a separate file

TO check response of particular id should be diff through jmeter

MY response for api is:-
"data":{"shortId":"lu131559"}}
Now i wants to check short id is different for every virtual user.
mns if second hit gone response data is
lu131560
So i want to validate that after 1000 request from virtual user every time i am getting diff id.
If you know the "current" value of the shortId and expect it to be incremented by 1 each time you call your API you can go for Response Assertion and use __intSum() and __counter() functions combination in the pattern like:
lu${__intSum(131559,${__counter(,)},)}
Each time the Assertion will be called it will expect the value to be incremented by one, i.e.
lu131560 - for 1st user or iteration
lu131561 - for 2nd user or iteration
lu131562 - for 3rd user or iteration
etc.
More information: Apache JMeter Functions - An Introduction

How to accumulate several API call responses in Apache Nifi?

I should run an remote API in Nifi and response is a Json like this:
{"data":[{...}, {...}, ...],"nextPage":"http://example.com/nextCall"}
I must continue to call the API and accumulate "data" until nextPage becomes null.
I have implemented it by using attributes and DistributedCacheServer, but it is not optimum, because data has about 1000 element and every element is a Json with several keys and values.
Updated Feb 16 2019:
This is my work flow:
This is my Multipage Handler:
https://gist.github.com/behrouz-s/01f9fe1c09ac9d54d0adf3cdd011ea1d
the idea:
at input you have a valid json as content (for example null), target url in some attribute,
cycle point: set request fragment.identifier=${UUID()} , and fragment.count=2
you transfer this file in two directions:
fragment=0 goes to merge and waits there the second file that will contain http response
fragment=1 goes through invokehttp
merge uses binary concat and always waits for 2 files
if next url is valid goto 2

How to pass response body values from one thread to different threads by incrementing the values in the response body in JMETER

I just wanted to extract value from the response body of thread1(1st thread am running once by passing number of threads and loop count 1 each) and need to pass same for the 2nd thread(2nd thread am running multiple times by passing number of threads 10).
This is my response body from Thread1.
{"availablePhoneNumbers":["3052191421","3052192726","3052192566","3052195123","3052194493","3052199654","3052194684","3052199164","3052190020","3052190352"]}
i just wanted to pick the first data 3052191421 and wanted to run in thread2 for all the HTTP requests.
then 2nd data 3052192726
then 3rd data and so on.
Could you please get the solution for this?
Thanks in advance..
Extract first number from the response. This can be done using JSON Extractor configured like:
Names of created variables: number
JSON Path Expressions: $.availablePhoneNumbers[0]
Later on you will be able to use __longSum() function in order to:
add 1 to ${number} variable
return the value
save the result back into the ${number} variable
Demo:

JMeter variable scope in threads

I have a JMeter tests which does the following:
It makes a GET request. The request returns some ID which is extracted by a Regular Expression Extractor and is set to a variable myId.
Another GET request is made using this ID stored in myId. It is important that the same ID is used as returned by the request before. Not any other ID!
This simple scenario works fine. But when I increase the "Number of Threads (users)" from 1 to (let's say) 5, I run into concurrency problems:
Thread 1 makes the GET request and assigns the ID to myId.
Thread 2 makes the GET request and assigns the ID to myId.
Now thread 1 runs again and makes the second GET request but with the wrong ID as thread 2 has changed it. Now everything breaks.
How can I avoid this?
As you use the same name for the reference myId, if in the second extraction it doesn't find anything then myId will contain the previous extracted value.
What you can do to check this, is to put in Default Value field:
nv_myId
as per:
http://jmeter.apache.org/usermanual/component_reference.html#Regular_Expression_Extractor
You can use a Debug Sampler to show content of variables

Resources