1
votes

I am trying to extract the results from my JBDC Request sampler using Bean shell assertion

I added a beanshell assertion to my sampler to extract the results and I got an error while running it. The Code in question is :

if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {

FailureMessage = "!!!!!!!!!!! No connection to the database or data not 
received !!!!!!!!!!!";
Failure = true; 
prev.setStopThread(true):

}    

Where dataFromDB is the result variable name of my JBDC Request Sampler

The Error is : Assertion failure message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval

1

1 Answers

0
votes

There are at least 2 problems with your code:

  1. FailureMessage definition should be at one line or you should concatenate 2 strings on 2 lines
  2. prev.setStopThread(true); should end with the semicolon

Additionally:

  1. Ensure that your vars.getObject("dataFromDB") expression doesn't produce null
  2. Surround your code in try block so if anything goes wrong - you will see the relevant message in jmeter.log file

Assuming all above the suggested fixes would look like:

try {
    if (!ResponseCode.equals("200") || vars.getObject("dataFromDB").size() == 0) {
        FailureMessage = "!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!";
        Failure = true;
        prev.setStopThread(true);
    }
} catch (Exception ex) {
    log.error("Script failure", ex);
}

Be aware that since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for any form of scripting so consider migrating to JSR223 Assertion, the required code amendments would look like:

if (!prev.getResponseCode().equals("200") || vars.getObject("dataFromDB").size() == 0) {
    AssertionResult.setFailure(true);
    AssertionResult.setFailureMessage("!!!!!!!!!!! No connection to the database or data notreceived !!!!!!!!!!!");
}