5

Is it possible to stop a Thread, or force a failure from within a BeanShell PreProcessor? I tried accessing the "stop()" function/method from the ThreadGroup Class and a few others, but I'm not sure I'm doing it right or if its possible.

I wanted to force my Test to stop inside my BeanShell PreProcessor if this one particular if statement inside my script resulted in TRUE... Is this possible? I did read a little of the "Failure" and "FailureMessage" functions, but wasn't sure the end result of using those was.

Any thoughts or suggestion would be greatly appreciated!

Thanks in Advance,
Matt

0

1 Answer 1

5

In a beanshell pre processor, you could try this:

org.apache.jmeter.engine.StandardJMeterEngine.stopThread(Thread.currentThread().getName()); 

In a beanshell post processor:

if (condition) prev.setStopThread(true);

If you can express your condition as an if-controller though, I would prefer to use a Test Action.

5
  • Thanks for the reply. Ok cool, I'll give that a shot thanks! Question regrading PreProcessors. If you have a BeanShell PreProcessor placed at the Thread Group level, *For example inside a Thread Group it has this from the top of the tree down, HTTP Request Defaults, Cookie Manager, Random Variable, BeanShell PreProcessor, HTTP Request #1, HTTP Request #2, HTTP Request #3... In that instance would the BeanShell PreProcessor get executed before EVERY HTTP Request, or just before all of those HTTP Request samplers begin, because I think it executed 3 times and there are 3 HTTP Samplers?
    – Matt
    Commented May 1, 2015 at 15:40
  • BTW, that first line of code you posted did stop the test... Thanks Again!
    – Matt
    Commented May 1, 2015 at 15:57
  • Post the question in the comments as a new question please. A screen shot of your plan would help.
    – RaGe
    Commented May 1, 2015 at 19:21
  • I didnot know that we can stop the thread in preprocessor. Thanks for the info.
    – vins
    Commented May 1, 2015 at 21:12
  • Ok done. I thought it did not make sense to stop the thread in the pre-processor. It could be useful in some cases.
    – vins
    Commented May 2, 2015 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.