Search code examples
jmeterjsr223

How to store a custom object in JSR223?


I make my custom listener in Jmeter as JSR223 Listener.

Currently it appends records to text file then listener invoked, during test run (i think it's not good for test accuracy), but i'd like ot collect all data (by listeners) and save it in one peace after end of test (on teardown section)

Google finds a lot ways to store single variables like string, but it's not acceptable if I want to store tonns of complex sets of data. Is it possible to store somehow Java array (or something simular) of my custom objects via JSR223 as global variable (creates somewhere at setUp stage), available for every JSR223 lisneners/Samplers and etc?

If I made "datakeeper" singleton will it works as I expect (I don't know how GC works for JSR223, will it clean this or not, and will it available for other JSR223 instances) and is it good folution for my purposes?


Solution

  • Just use props shorthand which stands for normal Properties which in its turn:

    1. global and is accessible in other Thread Groups and everywhere in this JVM instance
    2. can store whatever Object you want, not only the String

    So if you do something like:

     props.put('myObject', yourObject)
    

    in the setUp Thread Group

    you will be able to get the value as props.get('myObject') anywhere else

    More information on this props and other JMeter API shorthands - Top 8 JMeter Java Classes You Should Be Using with Groovy