Search code examples
jmeter

Jmeter error while fetching big dataset from a JSON response body


Am trying to fetch the all the account name(please refer the details below) from the response body but I am getting error. Is the output is too huge to handle ? any clue ? I see the output as a json format.

Have added the code block, along with the error message and the part of sample output.

Code Block:

import groovy.json.JsonSlurper;

def responseBD = new groovy.json.JsonSlurper().parse(prev.getResponseData());
def studyName = [];
responseBD.accounts.name { studyNameFetched->
    //studyName << studyNameFetched
    log.info("Reference Value : "+studyNameFetched)
}

Error Details:

2023-05-30 12:11:22,577 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-05-30 12:11:22,577 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-05-30 12:11:22,577 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-05-30 12:11:22,619 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-05-30 12:11:22,619 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-05-30 12:11:22,619 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-05-30 12:11:22,619 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-05-30 12:11:22,624 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-05-30 12:11:22,624 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-05-30 12:11:22,624 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-05-30 12:12:14,933 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223 PostProcessor
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.name() is applicable for argument types: (Script8$_run_closure1) values: [Script8$_run_closure1@68c01c8b]
Possible solutions: any(), max(), take(int), take(int), wait(), size()
            at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.11.jar:3.0.11]
            at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.11.jar:3.0.11]
            at javax.script.CompiledScript.eval(CompiledScript.java:93) ~[java.scripting:?]
            at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.5]
            at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) ~[ApacheJMeter_components.jar:5.5]
            at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:968) ~[ApacheJMeter_core.jar:5.5]
            at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:585) ~[ApacheJMeter_core.jar:5.5]
            at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:501) ~[ApacheJMeter_core.jar:5.5]
            at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:268) ~[ApacheJMeter_core.jar:5.5]
            at java.lang.Thread.run(Thread.java:833) ~[?:?]
Caused by: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.name() is applicable for argument types: (Script8$_run_closure1) values: [Script8$_run_closure1@68c01c8b]
Possible solutions: any(), max(), take(int), take(int), wait(), size()
            at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:70) ~[groovy-3.0.11.jar:3.0.11]
            at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) ~[groovy-3.0.11.jar:3.0.11]
            at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.11.jar:3.0.11]
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.11.jar:3.0.11]
            at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.11.jar:3.0.11]
            at Script8.run(Script8.groovy:7) ~[?:?]
            at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.11.jar:3.0.11]
            ... 9 more
2023-05-30 12:12:14,936 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-05-30 12:12:14,936 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-05-30 12:12:14,937 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-05-30 12:12:14,937 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Response Data

{

    "page": {
        "number": 1,
        "more": 0,
        "rows": 5000
    },

    "accounts": [
        {
            "name": "Enterprise Site Management",
            "uuid": "6656dae1-159a-4062-9cbb-5382d5202cd8"
        },
        {
            "name": "R2_Single QC",
            "uuid": "197650ca-d8fc-451d-9332-50d801b5c426"
        },
        {
            "name": "GUAC",
            "uuid": "ac7adabd-8040-498b-87ed-9c69d678ad49"
        },
        {
            "name": "PushkarTIMS-0501",
            "uuid": "0210da27-1724-40bb-a618-005103bb5970"
        },
        {
            "name": "ppp",
           "uuid": "8b982528-5fef-49d6-a016-e56c1de25c89"
        }, <***contd..***>

enter image description here


Solution

  • The error means that instead of name attribute at some point you're getting a JSON Array

    The only thing I can suggest is reconsidering your approach and using JSON Extractor instead. You could use a deep scan operator like $..name and -1 as the "Match

    enter image description here

    Assuming the above setup you will get JMeter Variables like:

    studyNameFetched_1=Enterprise Site Management
    studyNameFetched_2=R2_Single QC
    studyNameFetched_3=GUAC
    studyNameFetched_4=PushkarTIMS-0501
    studyNameFetched_5=ppp
    studyNameFetched_ALL=Enterprise Site Management,R2_Single QC,GUAC,PushkarTIMS-0501,ppp
    studyNameFetched_matchNr=5
    

    in case you want to have them in form of an array you could transform them using a Groovy script, something like

    def studyName = []
    
    1.upto(vars.get('studyNameFetched_matchNr') as int, { index ->
        studyName.add(vars.get('studyNameFetched_' + index))
    })
    

    enter image description here