Bug 63219 - New function "__StringToFile" to save a string into a file
Summary: New function "__StringToFile" to save a string into a file
Status: VERIFIED CLOSED
Alias: None
Product: JMeter - Now in Github
Classification: Unclassified
Component: Main (show other bugs)
Version: 5.1
Hardware: All All
: P2 enhancement (vote)
Target Milestone: JMETER_5.2
Assignee: JMeter issues mailing list
URL:
Keywords: FixedInTrunk
Depends on:
Blocks:
 
Reported: 2019-03-01 16:30 UTC by Sebastian Boga
Modified: 2020-01-03 15:27 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sebastian Boga 2019-03-01 16:30:30 UTC
We would like to have a simple way to save a specific string (simple or multiple rows) to a file like from JMeter without writing a complicated BeanShell script

If it's too complicated to have a SAMPLER for it, please create a function for this like ${__StringToFile(<string>,<file>)}
Comment 1 Philippe Mouawad 2019-03-07 20:04:37 UTC
Contract:

${__stringToFile(<file path>, <sync_id>, <string to write>)}

sync_id used to synchronize simultaneous calls that write to the same file

Questions:

- This means we would be flushing on every call, should we add a parameter  ?
- Should we use a lock based on file name to synchronize simultaneous calls that write to the same file, or should we add a mandatory sync_id used
Comment 2 Brian Wolfe 2019-03-07 20:29:14 UTC
wouldn't flushing to the file every call cause a performance bottleneck? 
I could definitely see this being useful when building a test, but idk if it is something I would use for full blown performance test.

That being said I don't see any reason we couldn't make a sampler that could write a string that uses "user defined variables" to a given file. That way they can take any data they captured from a sampler and write it to a file.
Comment 3 Philippe Mouawad 2019-03-07 20:34:36 UTC
(In reply to Brian Wolfe from comment #2)
> wouldn't flushing to the file every call cause a performance bottleneck? 

Yes, that's why I was proposing a parameter to control this:
- false : would mean flush smartly (on thread or test end)
- true : flush on every write

> I could definitely see this being useful when building a test,

I agree that for data validation it is very useful.

> but idk if it
> is something I would use for full blown performance test.

> 
> That being said I don't see any reason we couldn't make a sampler that could
> write a string that uses "user defined variables" to a given file. That way
> they can take any data they captured from a sampler and write it to a file.

It is definitely possible today using JSR223 Sampler to do it.
Do you mean create a sampler called "Write to file" ?
We could alternatively add a class to Java Request
Comment 4 Sebastian Boga 2019-03-08 12:46:17 UTC
Yes. 
 A Write to File sampler would be really nice.

 During a test we can compute a dynamic value for a variable and we need a simple way to put this value into a file (of course, we will specify the filename).

The data whithin the file will be used as input data in next step or next JMX script.

 If it's easier to develop this as a function like you mention: ${__stringToFile(<file path>, <sync_id>, <string to write>)} then this is fine also.

If we want to create different files we can use timestamp as filename or UUID, so don't worry about the file being overwritten.

Best regards,
Sebi
Comment 5 UbikLoadPack support 2019-03-26 21:28:19 UTC
PR contributed:

https://github.com/apache/jmeter/pull/454

@UbikLoadPack Team
Comment 6 Philippe Mouawad 2019-04-13 08:26:03 UTC
Author: pmouawad
Date: Sat Apr 13 08:25:35 2019
New Revision: 1857453

URL: http://svn.apache.org/viewvc?rev=1857453&view=rev
Log:
Bug 63219 - New function "__StringToFile" to save a string into a file

Contributed by UbikLoadPack (https://ubikloadpack.com)
Bugzilla Id: 63219

Added:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/StringToFile.java   (with props)
    jmeter/trunk/test/src/org/apache/jmeter/functions/TestStringtoFile.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages.properties
    jmeter/trunk/src/core/org/apache/jmeter/resources/messages_fr.properties
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/functions.xml
Comment 7 Sebastian Boga 2019-04-16 20:32:26 UTC
Tested on Relase: r1857470
It works. Thank you very  much!
Comment 8 Sebastian Boga 2020-01-03 15:27:02 UTC
Verified the issue on JMeter 5.2.1 (production).
It works.
Comment 9 The ASF infrastructure team 2022-09-24 20:38:16 UTC
This issue has been migrated to GitHub: https://github.com/apache/jmeter/issues/5027