How to call Java class/function in Jmeter from third-party jar file

2,656 views
Skip to first unread message

Hung dao quang

unread,
Jun 11, 2014, 9:19:15 PM6/11/14
to jmeter-...@googlegroups.com

Hi all,

I'm going to performance for Chat server using XMPP protocol, so I configure Jmeter as below:

Creating User Define Variable, with 3 variables CHAT_HOST, CHAT_PORT, CHAT_SERVICE , and assign value to them.

Putting 2 Smack 3.2.2 file to /lib folder of Jmeter and creating the Beanshell sampler with the code as below:

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;


ConnectionConfiguration config = new ConnectionConfiguration();
ConnectionConfiguration.init(vars.get("CHAT_HOST"), vars.get("CHAT_PORT"), vars.get("CHAT_SERVICE"));
XMPPConnection connection = new XMPPConnection(config);
connection.connect();

But, when running the console shows error as below:

WARN  - jmeter.protocol.java.sampler.BSFSampler: BSF error org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: ``import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.s . . . '' : Typed variable declaration : Undefined argument: HOST  : at Line: 7 : in file: inline evaluation of: ``import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.s . . . '' : ( HOST , PORT , SERVICE ) 
 BSF info: script at line: 0 column: columnNo
    at bsh.util.BeanShellBSFEngine.eval(BeanShellBSFEngine.java:199)
    at org.apache.jmeter.protocol.java.sampler.BSFSampler.sample(BSFSampler.java:104)
    at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:429)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257)
    at java.lang.Thread.run(Unknown Source)

Would you like to tell me how to handle this error, and the way to call a class from third party Jar file as I did - is it right or wrong ? If wrong, please instruct me.

Thanks,

gli...@gmail.com

unread,
Jun 12, 2014, 9:59:16 AM6/12/14
to jmeter-...@googlegroups.com
Hi 

Try amending your script as follows:

        ConnectionConfiguration config = new ConnectionConfiguration(vars.get("CHAT_HOST"), Integer.parseInt(vars.get("CHAT_PORT")), vars.get("CHAT_SERVICE"));

       
XMPPConnection connection = new XMPPConnection(config);
        connection
.connect();

It looks like that following inconsistencies are present in your code snippet:

  1. ConnectionConfiguration empty constructor is not allowed. 
  2. ConnectionConfiguration.init method is private, so cannot be called this way. 
  3. JMeterVariables are stored as Strings (or Objects) and ConnectionConfiguration expects Integer as port. 
You can get more informative error messages rather than Sourced file: inline evaluation of by wrapping your Beanshell code into try/catch block as

    try {
         
// do something
   
} catch (Exception ex) {
        log
.error("Something went wrong", ex);
       
throw ex;
   
}

This will print out quite informative exception stacktrace to jmeter.log file which usually lives under /bin folder of your JMeter installation. 

And finally: 


Each BeanShell test element has its own copy of the interpreter (for each thread). If the test element is repeatedly called, e.g. within a loop, then the interpreter is retained between invocations unless the "Reset bsh.Interpreter before each call" option is selected. For intensive load testing, it is recommended to use a JSR223 scripting language whose ScriptingEngine implements Compilable, see JSR223 section below for more details.


So if you want to performance test your XMPP server I would suggest considering switching to JSR223 Sapmler and Groovy as a language or write your own implementation of Java Request Sampler to achieve optimal performance as it evidenced by Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! comparison benchmark.   

Hope this helps. 

Hung dao quang

unread,
Jun 13, 2014, 2:57:30 AM6/13/14
to jmeter-...@googlegroups.com
Thank for your help - Glinius.



--
You received this message because you are subscribed to a topic in the Google Groups "jmeter-plugins" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jmeter-plugins/tUVhNbl_XK0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jmeter-plugin...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cki...@gmail.com

unread,
May 7, 2015, 10:24:53 AM5/7/15
to jmeter-...@googlegroups.com, gli...@gmail.com
i need to do load testing on mobile chat application, i am new to jmeter, i've used the same code and library with the changes you have suggested. Still i am getting same error. could you please suggest what to do.


2015/05/07 19:40:49 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.s . . . '' : TargetError 
2015/05/07 19:40:49 WARN  - jmeter.protocol.java.sampler.BeanShellSampler: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.s . . . '' : TargetError 
2015/05/07 19:40:49 INFO  - jmeter.threads.JMeterThread: Thread is done: Thread Group 1-1 
2015/05/07 19:40:49 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2015/05/07 19:40:49 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2015/05/07 19:40:49 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 
Reply all
Reply to author
Forward
0 new messages