I am evaluating performance of my transport library and it will be helpful if I get suggestions on the following:
I use a Junit sampler to perform the following:
HTTP POST test: I send a HTTP POST request: This will cause a DB write. I have to evaluate all the parameters (throughput, avg. response time) holistically for POST + DB_WRITE operation. As response to this POST request, I get a unique id. So if I send 1000 successful POST requests, I will have 1000 unique ids.
Now my question is how can I use these unique ids for my next test case, perform a HTTP GET on each of created unique ids.
I can parse the HTTP POST response and write the unique id into a file and try using that file for my HTTP GET test. But the problem is if I create a thread group of 10 different threads, there will be issues of synchronization on file writing.
Is there any PostProcessor I can use to record results in filesystem?
As for me looks like you can avoid usage of file to store and then read generated id's.
Logic is the following:
execute your POST request;
parse response returned from POST - using Regular Expression Extractor or any other post-processor attached to the request - to extract your ID;
store extracted ID in user-unique / thread-unique variable - in the same post-processor;
how to do this for Regular Expression Extractor see below: ${__javaScript('${username}'+'UnicID')} generates unique variable for each user/thread, to avoid interference in multi-user cases;
seems that can also use threadNum function instead of ${username} variable;
if POST request completed successfully, ID extracted and stored in variable - execute your GET request were extracted ID is used as param;
use ${__V(${username}UnicID)} construction to get back previously saved ID.
You may add also add Debug PostProcessor to POST request sampler - to monitor generated variables and their values.
Seems that's all.
Thread Group
Number of Threads = X
Loop Count = N
. . .
HTTP Request POST
checkingReturnCode // Response Assertion
extractUniqueID // Regular Expression Extractor (e.g.)
Reference Name = ${__javaScript('${username}'+'UnicID')}
Regular Expression = ...
Template = $1$
Match No. = 1
Default Value = NOTFOUND
IF Controller // execute GET only if POST was successful
Condition = ${JMeterThread.last_sample_ok} // you may change this to verify that variable with extracted ID is not empty
HTTP Request GET
param = ${__V(${username}UnicID)}
. . .
Hope this will help.
There won't be any problems with synchronization (they are resolved by file system). In every thread (which is POST-ing) you should open your file for writing and append a new line to it. Again, don't worry about synchronization, OS will take care of it.
Related
I need to make around 100 POST request.
The body of every post request needs to have a different ID.
Sample BODY
{
id: 1,
name: "ABC",
city: "NY"
}
All 100 requests should have different 'id' , but rest of the data can be the same
Can I attain this through Postman ? ..or some other tool?
Tried:
Assigned value to a variable, and used that as value for ID in Postman, but unable to change this variable for every request
You can add {{$randomInt}} to the POST body, save that request and then open the Collection Runner.
In the iteration count, type 100 and start the run. That will create a random id value for each request between 1 - 1000. As this is "random" this is the potential for the same value to be sent more than once.
Alternatively, you could add a {{id}} variable to the POST request body. Then create a CSV file with a single column which has id as the header - add the ID values you want as 100 new rows in the column.
In the Collection Runner, select the created CSV file and run that with your request.
There are a number of different ways that this can be done, it's just finding the use case that suits your context.
You can the pre-request scripts in postman to send multiple request.
You can use
postman.setNextRequest("request_name");
To keep sending request till some condition is reached
I am new to jmeter (I am using version 3.3) and I created a test plan with the goal of sending an email on Assertion failure.
in this email I want to add some information about the name of the request and its reason
so I have added and if controller with this condition:
${JMeterThread.last_sample_ok}
a beanshell preprocess with this script:
and an SMTP Sampler with this body:
and a response assertion:
I want to get an email anytime it hits the condition of response code=500 and the info described above.
I got to receive the email on that condition but the body message is literally this:
${body}
this is the assertion result:
what am I doing wrong?
How to get what I need?
Thanks
Your prev variable is not defined in the Beanshell PreProcessor (it exists only for PostProcessor and Listener, I would suggest using ctx.getPreviousResult() instead where ctx stands for JMeterContextService instance.
You also need to enable your HTTP Request GET - posts as this will be this "previous result" you're interested in.
Be aware that starting from JMeter 3.1 it is recommended to use Groovy for any form of scripting so consider migrating to JSR223 PreProcessor and Groovy language on next available opportunity. You should be even able to re-use the same code as I don't see any Beanshell-specific features in it. See Apache Groovy - Why and How You Should Use It article for more information on Groovy scripting in JMeter.
The script is sending an email if the last sampler is ok, therefore the assertion is ok too, so the body variable won't hold any value.
Just adjust your if statement to !${JMeterThread.last_sample_ok}, and then move up your HTTP sampler HTTP Request - POST/articles above the if controller.
This will make your script send an email if the sampler failed and you will have the body variable holding the failure message.
I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement
POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.
The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)
Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)
Now the Second Response should come from Server with Status 200 OK and Thumbnail URL
is it feasible with one REST API? (Async/similar)
or should I split it to 2 API calls, Please suggest
No. In http, one request gets one response. The client must send a second request to get a second response.
You can use WebSockets for that.
If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.
You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.
On the client side second request must be callback of first request.
The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).
You can return two response using custom middlewares in asp.net (however not recommended).
Return response from one middleware and subsequently you can invoke next middleware and return second response from second middleware
I am creating a REST service in Java ,and have a doubt with regards to params for the GET method .
I have to pass the below params in a GET request
Function
"GET" File status :
Params:
Time Range:(String)
FlowId:(String)
ID_A= or ID_B= or Both (String)
IS_ADD_A= or IS_ADD_B= or both (String)
Regex=(String)
Cookie=XXXXX
So as there are 6 params,so passing it as a query string would not be an efficient way and can't but the same in body(as it is against the HTTP GET specification)
Making this as a POST call would be against the REST principle as I want to get data from the server ,
What would be an efficient way of solving this ,would passing the params as query string is out of question,passing it in body which is against the HTTP spec ,making this as headers which may also be not good ,making this as POST request which will voilate the fielding's REST principle .
Passing data in the body of an HTTP GET call is not only against the spec but causes problems with various server-side technologies which assume you don't need access to the body in a GET call. (Some client side frameworks also have some issues with GET and a query in the body) If you have queried with long parameters I'd go with POST. It's then using POST for getting data but you'd not be the only one having to go this way to support potentially large queries.
If your parameters values aren't very long, using query string is your best option here. 6 params is not a lot, as long you don't exceed the IE limit of characters in the path - 2,048 (http://www.boutell.com/newfaq/misc/urllength.html). For example Google search engine uses many more params then 6. If there is a possibility that the URL path will exceed the limit above, you should use POST instead.
I am using JMeter to do some testing.
I have to do a HTTP GET on a URL like www.acme.com/documents/next.
This shall return me a document ID, then i need to do a POST based on that document ID like
www.acme.com/document/{document_id}. This document ID shall be the one returned by the previous GET request.
I will need to run this in many threads, so if there needs to be a variable used to store the result of the GET, it should be stored in something like a ThreadLocal because each one will get a unique id when it called the GET method.
You should use postprocessor to extract variable. Your test plan will look like this:
Thread Group
- GET request to /documents/next
--- Regular Expression Extractor (with reference name=variable)
- POST request to /document/${variable}