I planned to create Test Plan in my JMeter like below
Test Plan
Thread Group
Loop Controller
HTTP Request Sampler 1
HTTP Request Sampler 2
HTTP Request Sampler 3
HTTP Request Sampler 4
HTTP Request Sampler 5
HTTP Request Sampler 6
HTTP Request Sampler 7
HTTP Request Sampler 8
If Controller condition ${JMeterThread.last_sample_ok}==false
SMTP Sampler
I would like to run the test 24/7.
If one (or more) HTTP Request Sampler returns error for what ever reason, then execute the SMTP sampler and send email to me.
If none of the HTTP Request Sampler returns error , then do not execute SMTP sampler but keep repeating the loop forever.
I don't quite understand the if controller condition ${JMeterThread.last_sample_ok}.
What does JMeterThread.last_sample_ok mean?
Last_sample_ok means only the last HTTP Request sampler (in my case HTTP Request Sampler 8 only) ? If I want to check the condition for every sampler 1-8, what can be done here?
Is JMeterThread a JMeter Java class or Java object?
Besides last_sample_ok , what other method can be applied to JMeterThread object?
Thanks.
JMeterThread.last_sample_ok is a static String field of the JMeterThread class.
This line from the source code of JMeterThread class shows that LAST_SAMPLE_OK will be set to String representation of the parent.isSuccessful() boolean variable, where parent is a SampleResult object:
threadContext.getVariables().put(LAST_SAMPLE_OK, Boolean.toString(parent.isSuccessful()));
Basically, LAST_SAMPLE_OK will indicate if the last sample was successful (until it gets reset by the next sampler).
Yes, if JMeterThread.last_sample_ok is true then the last sampler was successful. In your case it is HTTP Request Sampler 8.
You can add all your HTTP Samplers as children of a Transaction Controller and select the "Generate a parent sample" checkbox.
This will make JMeter generate a parent sample for all the inner samples of a Transaction Controller. If one of the child samplers fails, the parent sample will fail as well.
Add your If Controller right after the Transaction Controller.
Now JMeterThread.last_sample_ok will relate to the generated parent sample.
JMeterThread is a class in the org.apache.jmeter.threads package .
LAST_SAMPLE_OK is not a method, but a static field. There is one more field and a number of methods in the JMeterThread class.
One way you could do this is using Jenkins Email Extension Plugin which you can set to email you when there is a failure on you build.
(so you could fail the build when the script has a failed HTTP request.)
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin
Related
I need to configure a parser which can add few default fields(such as default labels) in the request body of underlying BQ HTTP request whenever any query is run via this bqserv instance (like mentioned in the code snippet below). How to build bqserv?
bqserv.query(QueryJobConfiguration.newBuilder(query).build)
I found BigQueryOptions.newBuilder().setTransportOptions() to set transport options, but I am unable to figure out exactly how to configure/(or set a parser for) HTTP request body ? I came across com.google.cloud.spark.bigquery.repackaged.com.google.api.client.util.ObjectParser as well, but again not sure how to use it and create bqserv (class com.google.cloud.spark.bigquery.repackaged.com.google.cloud.bigquery.BigQueryImpl) object.
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 saw the below post from "cmd" which was posted couple of years back. And "Wojtek Owczarczyk" was answered this one. I am good with all the answer, except last line.
My Confusion is, If we return immediately with ACCEPTED status. Then, we will lost the track of the request.
So i am planning to implement below steps. Please correct me if i am wrong.
1) As soon as the request hits service api - I will create one Job Id and persist my request detail and send back the client with ACCEPTED status code along with Job id.
2) Then, i will create the new thread for that request to continue with the requested operation.
3) After successful completion of Operation, I will send back the client with all status of the request.
4) Finally, in callbackCompletion register i will remove the job id from my persistence list.
To implement the above logic, i need client to send his listener information along with request (basically URI). This is to update the request status to client back, after processing the request.
REST with JAX-RS - Handling long running operations
This is not how REST is meant to work in my opinion. I would do the following approach instead:
Client makes a request for a long operation
Create a job id and run the job asynchronously
Return the accepted status together with the a URI to request the status for the job. For example: http://.../resources/jobs/1234
The client is now responsible e.g. to poll the URI to get the current status of the job execution.
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}
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.