1
votes

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}.

  1. 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?

  2. Is JMeterThread a JMeter Java class or Java object?

  3. Besides last_sample_ok , what other method can be applied to JMeterThread object?

Thanks.

2

2 Answers

2
votes
  1. 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.

  2. JMeterThread is a class in the org.apache.jmeter.threads package .

  3. 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.
0
votes

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