Blazemeter JSR223 Script unable to resolve class groovy.json.JsonBuilder

49 Views Asked by At
  1. We run performance test infrequently because we rarely make serious updates to our legacy app
  2. A line of code that has been unchanged for over a year is now causing a failure in Blazemeter
  3. Not only has the line not changed, but the entire script has not been touched in over 9 months and Perf testing has been run dozens of times in Blazemeter, especially in the fall of 2023.
  4. Same script runs in Jmeter but no longer runs in Blazemeter.
  5. The Line: String json = new groovy.json.JsonBuilder(map).toString()
  6. The error: Script1.groovy: 140: unable to resolve class groovy.json.JsonBuilder
  7. We tried adding "import groovy.json.JsonBuilder" to the script but it too caused the same error. Script Language displayed in JMeter: Groovy 3.0.17/Groovy Scripting Engine 2.0

Blazemeter log Extract | Jsr223-Setup JWT | FAIL | 0.00% | 0.677 | javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: | | | | | | Script1.groovy: 140: unable to resolve class groovy.json.JsonBuilder | | | | | | @ line 140, column 23. | | | | | | String json = new groovy.json.JsonBuilder(map).toString() | | | | | | ^ | | | | | | | | | | | | 1 error

2

There are 2 best solutions below

0
Ivan G On

I think queries like this should go to BlazeMeter support

So far I can only state that I cannot reproduce the error using:

  1. Simple test with single JSR223 Sampler with the following code:

    def map = ['foo':'bar']
    def json = new groovy.json.JsonBuilder(map).toString()
    log.info('Generated json: ' + json)
    
  2. JMeter 5.5 and Java 8:

    enter image description here

Everything is good:

enter image description here

Here is the test plan just in case:

<?xml version="1.0" encoding="UTF-8"?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.6.2">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Test Plan" enabled="true">
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <boolProp name="TestPlan.tearDown_on_shutdown">false</boolProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Thread Group" enabled="true">
        <stringProp name="ThreadGroup.on_sample_error">continue</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <stringProp name="LoopController.loops">1</stringProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
        </elementProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.ramp_time">1</stringProp>
        <boolProp name="ThreadGroup.delayedStart">false</boolProp>
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <boolProp name="ThreadGroup.same_user_on_next_iteration">true</boolProp>
      </ThreadGroup>
      <hashTree>
        <JSR223Sampler guiclass="TestBeanGUI" testclass="JSR223Sampler" testname="JSR223 Sampler" enabled="true">
          <stringProp name="cacheKey">true</stringProp>
          <stringProp name="filename"></stringProp>
          <stringProp name="parameters"></stringProp>
          <stringProp name="script">def map = [&apos;foo&apos;:&apos;bar&apos;]
def json = new groovy.json.JsonBuilder(map).toString()
log.info(&apos;Generated json: &apos; + json)</stringProp>
          <stringProp name="scriptLanguage">groovy</stringProp>
        </JSR223Sampler>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

Here is a link to report just in case: https://a.blazemeter.com/app/?public-token=jyKrcAxFd2CgIP0oSICvvAddNoaL5LpabGrFv8RDZOX9gzX3YM#/accounts/40956/workspaces/32841/projects/75310/masters/71695094/summary

but you have to be quick, I don't think it will live forever.

0
always learning On

Thanks for the info Ivan. Script was failing for us with Jmeter Version 5.5, and when I changed Blazemeter config to Jmeter Version '(Latest) 5.6.2' it worked!
Surprised and disappointed that it was something that small.