I have several JSR 223 samplers with scripts inside the Thread group, which doing
some work before the HTTP requests are invoked.
The problem is that the JSR 233 samplers are included in the final summary report
My question is how can I Exclude those JSR 223 samplers from the final calculations?
UPDATE
When I try to set pre processor JSR 223
I'm getting this error as the if controller after the pre processor JSR 223
does not recognize the variable I set in the vars.put. it only recognize it when I use JSR 223 sampler.
2017/08/24 16:07:37 ERROR - jmeter.control.IfController: If Controller: error while processing [${my_foo_var} >=0]
org.mozilla.javascript.EvaluatorException: missing ; before statement (<cmd>#1)
at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)
at org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64)
at org.mozilla.javascript.Parser.addError(Parser.java:188)
at org.mozilla.javascript.Parser.addError(Parser.java:166)
at org.mozilla.javascript.Parser.reportError(Parser.java:256)
at org.mozilla.javascript.Parser.reportError(Parser.java:243)
at org.mozilla.javascript.Parser.reportError(Parser.java:236)
at org.mozilla.javascript.Parser.autoInsertSemicolon(Parser.java:1100)
at org.mozilla.javascript.Parser.statementHelper(Parser.java:1077)
at org.mozilla.javascript.Parser.statement(Parser.java:934)
at org.mozilla.javascript.Parser.parse(Parser.java:573)
at org.mozilla.javascript.Parser.parse(Parser.java:511)
at org.mozilla.javascript.Context.compileImpl(Context.java:2488)
at org.mozilla.javascript.Context.compileString(Context.java:1476)
at org.mozilla.javascript.Context.compileString(Context.java:1465)
at org.mozilla.javascript.Context.evaluateString(Context.java:1216)
at org.apache.jmeter.control.IfController$RhinoJsEngine.evaluate(IfController.java:105)
at org.apache.jmeter.control.IfController.evaluateCondition(IfController.java:187)
at org.apache.jmeter.control.IfController.next(IfController.java:240)
at org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:222)
at org.apache.jmeter.control.GenericController.next(GenericController.java:176)
at org.apache.jmeter.control.LoopController.next(LoopController.java:123)
at org.apache.jmeter.threads.AbstractThreadGroup.next(AbstractThreadGroup.java:87)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
at java.lang.Thread.run(Unknown Source)
You can tell Jmeter Listeners to ignore the previous SampleResult using "prev.setIgnore();"
in a JSR223 PostProcessor.
You can use this for all Samplers. This solution works for JMeter 4 and 5
You can use Filter Results Tool to remove the unwanted sample(s) from the final report, it has --exclude-label-regex parameter where you can provide sampler name(s) pattern(s).
You can install Filter Results Tool (as well as any other plugin) and keep it up-to-date using JMeter Plugins Manager
[
Assuming successful installation you should be able to find FilterResults.bat and FilterResults.sh tool startup scripts under "bin" folder of your JMeter installation.
All Samplers are included so you can move your code to JSR 223 Post/Pre Processor and put it under different existing Sampler in Hierarchy.
That way the code won't be calculated in reports.
Related
We recently updated apache jmeter from v4.0 to the latest v5.4.3.
The tests are running fine, but we have strange results.
The requests appear with 3 different labels (without suffix or -0 / -1 appended).
timeStamp, label, responseCode, threadName
1643834640785, API call, 200, Load Group 1 1-1
1643834640785, API call-0, 302, Load Group 1 1-1
1643834641189, API call-1, 200, Load Group 1 1-1
1643834640785, API call, 200, Load Group 1 1-2
....
It seems to me this happens, when the same thread calls the API multiple times.
I am not a jmeter and I am not sure why this happens and how to fix it. Also I don't know what information is needed to analyze the problem correctly.
Thanks in advance!
I'm seeing HTTP Status 302 which means redirection (for example from HTTP to HTTPS or from global website to country-specific website), in that case JMeter generates additional Sub-Result.
The "strange" labels is how JMeter calculates throughput for embedded resources and the cumulative execution time of the parent sampler in case of redirects as well.
The question is what do you want to do with this.
The options are in:
Take it for granted given the above explanation
If you want the "strange" labels to be resolved into real URLs - tick "Functional Testing" box in the Test Plan
or add the next line to user.properties file:
subresults.disable_renaming=true
If you want to get rid of these subresults completely - add the next line to user.properties file:
jmeter.save.saveservice.subresults=false
More information:
Configuring JMeter
JMeter Properties Reference
in my project I need to have a jmx (let's call it main.jmx) script that will have a bunch of TestFragments (of which each of them will be a UserJourney composed by multiple requests and "flows") and I want to have other jmx files that might point to some of the test fragments of the main.jmx to use only some of them. I know that there is the IncluderController but if I am not wrong, it does not allow me to execute parts from other script but the script as a whole.
The idea is to have a single jmx (main.jmx) that would "store" all the UserJourneys and have other multiple jmxs that would be able to call some UJs from the main script.
Is there a way to have something that allow me to do the job without needing to create a jmx for each UserJourney and set them in multiple IncluderControllers?
Thanks in advance.
You need to have a proper Single Test Plan in place.
(UserJourney.jmx)
Test Plan
-Thread Group
-Transaction Controller#1 (main)
-Data sampler (jdbc etc)
-Request Sampler / TestFragments
-Response Extraction(json extractor/regular exp extractor)
-Transaction Controller#2 (UserJourney)
-Request Sampler / UserJourney (takes response from main controller as request params)
-Listeners
Cheers!
I have a situation where I check the response data and if there is a specific variable exist then I like to simulate a test failure even though that HTTP req code was 200. For example in Bean Post Processor I have:
if ( (prev.getResponseDataAsString().indexOf(Z2) >= 0) || (matches > 1) ){
System.out.println(ctx.getCurrentSampler().getName() +" --> Failed ....")
}
I know how to do it when I want to set the result to success (prev.setResponseOK();) how do I do it if I want to set it to fail? so the GUI shows red and not green?
Thank you
See in JSR223 Sampler
Unlike the BeanShell Sampler, the JSR223 Sampler does not set the ResponseCode, ResponseMessage and sample status via script variables. Currently the only way to changes these is via the SampleResult methods:
SampleResult.setSuccessful(true/false)
prev is a SampleResult object so you can mark it as failed:
prev.setSuccessful(false)
prev - (SampleResult) - gives access to the previous SampleResult
Sounds like a use case for a Response Assertion which you can use in order to conditionally set pass/fail criteria for a Sample basing on presence/absence of certain patterns in the response data.
Here is an example of failed HTTP Request sampler with 200 status code due to absence of the anticipated data in the response:
See How to Use JMeter Assertions in Three Easy Steps for more details.
With regards to JMeter Best Practices which you're violating by the way by using Beanshell PostProcessor:
You should be using built-in JMeter test elements where possible
If you have to go for scripting make sure to choose the most performing option which is unfortunately not Beanshell
What is the main cause of the following error log?
2015/09/09 10:47:42 ERROR - jmeter.threads.JMeterThread: Test failed!
java.lang.StackOverflowError at
java.util.LinkedHashMap$EntryIterator.(LinkedHashMap.java:412)
at java.util.LinkedHashMap.newEntryIterator(LinkedHashMap.java:419)
at java.util.HashMap$EntrySet.iterator(HashMap.java:1078) at
java.util.Collections$SynchronizedCollection.iterator(Collections.java:1632)
at
org.apache.jmeter.testelement.AbstractTestElement.recoverRunningVersion(AbstractTestElement.java:499)
at
org.apache.jmeter.control.GenericController.reInitialize(GenericController.java:131)
at
org.apache.jmeter.control.GenericController.nextIsNull(GenericController.java:257)
at
org.apache.jmeter.control.GenericController.next(GenericController.java:175)
at
org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:229)
at
org.apache.jmeter.control.GenericController.next(GenericController.java:180)
at
org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:226)
at
org.apache.jmeter.control.GenericController.next(GenericController.java:180)
at
org.apache.jmeter.control.GenericController.nextIsAController(GenericController.java:226)
at
org.apache.jmeter.control.GenericController.next(GenericController.java:180)
at
org.apache.jmeter.control.LoopController.next(LoopController.java:123)
at
org.apache.jmeter.control.LoopController.nextIsNull(LoopController.java:151)
{repeats for the next ~ 900 lines}
My test plan looks as follows:
Testplan
- Authentication Transaction Controller
- Forever Loop
- Random Order Controller
- Simple Controller A
- Only Once Controller
- Parameterized Controller
- Module Controller (to "Simple Controller 1")
- For Each Loop (loops variables set by "BeanShell Post Processor 1")
- Module Controller (to "Simple Controller 2")
- Simple Controller B
- Simple Controller C
Disabled Thread Group
- Simple Controller 1
- Transaction Controller
- HTTP Request
- BeanShell Post Processor 1 (for JSON Extraction)
- Simple Controller 2
- Transaction Controller
- HTTP Request
- BeanShell Post Processor 2 (for JSON Extraction)
Note: I am handling with user variables a lot.
My expectation is that the problem lives somewhere in your Beanshell PostProcessors, for instance there is some code which causes endless loop or something. If you could post response and Beanshell PostProcessor code I could be more specific. For now I can recommend the following:
Consider switching from Beanshell PostProcessors to JSONPath Extractor if extracting JSON is their only duty
If not - in general it isn't recommended to use Beanshell as it has some known performance problems and it's abandoned for > 10 years. Switch to JSR223 Post Processors and groovy language instead. Groovy is even more Java-compatible than Beanshell so if you didn't use anything Beanshell-specific you won't have to rewrite a single line of code. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! for Beanshell versus JSR223 benchmark, installation instructions for groovy scripting engine and scripting best practices.
I am new into Apache Jmeter. Basically I want to load test our couple of thrift APIs but have no clue where to start with. It is in java where api takes 2 parameter and then send java object as response.
Any pointer would be very helpful.
JMeter isn't especially for it but it's flexible enough to support your use case.
There is an extensibility mechanism which uses BeanShell. JMeter provides BeanShell Sampler which is capable of invoking Java code, including using external jars.
Simple usage:
Start with empty JMeter project
Create a Thread Group with all defaults (you can play with number of threads, ramp-up, etc)
Add a BeanShell Sampler with following code:
Thread.sleep(2000L);
Add View Results Tree listener
Save and run
You should see a green triangle (or triangles) basing on your number of threads and loops) with output like following:
Thread Name: Thread Group 1-1
Sample Start: 2013-11-02 14:48:11 GMT+03:00
Load time: 5030
Latency: 0
Size in bytes: 0
Headers size in bytes: 0
Body size in bytes: 0
Sample Count: 1
Error Count: 0
Response code: 200
Response message: OK
If you use any of techniques to analyze results, i.e.
JMeter embedded listeners like Aggregate Report, Summary Report, Graph Resuls, etc.
Storing results to CSV file and opening them with Excel or equivalent (see jmeter.properties file under /bin directory of your JMeter installation. Properties prefix is "jmeter.save.saveservice."
JMeter Ant Task (see Test.jmx and build.xml in /extras folder under your JMeter installation)
JMeter Results Analysis Plugin
You'll see your request(s) success rate, min/max/average times (something like 2 seconds I guess) and some more information (depending on your configuration).
Particular your use case assumes
IMPORTANT Placing thrift (or whatever) jars under lib/ext folder (or you won't be able to access your APIs
importing classes you need to test somewhere in BeanShell Sampler
import yourpackage.YourClass;
Invoking methods you want to test from BeanShell Sampler
(optional) do some assertions on responses. i.e.
if (yourresponse != yourexpectedresponse){
IsSuccess=false;
ResponseMessage= "Test Failed";
}
Hope this helps
You can use JSR223 Sampler + Groovy (add groovy-all.jar in jmeter/lib) and look at this client example, see NonblockingClient code for an example:
http://www.javacodegeeks.com/2012/03/apache-thrift-quickstart-tutorial.html
Make your groovy code call a least the following at end:
SampleResult.setSuccessful(true/false)
SampleResult.setResponseCode("code")
SampleResult.setResponseMessage("message")
See:
http://jmeter.apache.org/usermanual/component_reference.html#JSR223_Sampler
And of course, ensure you add the required dependencies in jmeter/lib.
I have writtena CustomThriftSampler for JMeter to load test HBase through thrift service. You can get the details about it at my blog - http://1-st.blogspot.in/2013/12/load-testing-thrift-services-custom.html . Couldn't create a generalized code. Anyway its simple and starightforward java code. Anyone could try it. If time permit I shall write a generalised code and commit to github!!