Search code examples
javajmeterjmeter-pluginsbeanshelljmeter-5.0

NAS Folder Location


Hope you are doing great, I came here from the stack overflow link

I referred the bean shell code at Save body request in JMeter ,I modifed it just a little bit and I can create the files with the naming convention I want.

I am creating Custom XML requests which are huge and would need to create bulk of then close to 50 to 80 K xmls file.

Creating the file is not the problem and saving the xml request with the modified code works for me which saves the files to the jmeter bin folder.

Please find the slightly modified code below

import org.apache.commons.io.FileUtils;

String data = ctx.getCurrentSampler().getArguments().getArgument(0).getValue();

FileUtils.writeStringToFile(new File("MPOS_" + ${__P(batchno)} + "-" + ${p_Sequence} + "-" +"${__time(yyyyMMddhhmmss)}" + ".xml"),data);

The code creates the xml files with the names like

MPOS_300008-15-20201010063800.xml

The above piece of code writes the files to jmeter bin location, the thing is I don't want to write the xml output file to the jmeter bin location, because then I wil have to copy it to the NAS location manually which is too much of overhead and the system might die copying all those files. So the idea is as soon as the XML is created I put the XMLS in the NAS file locations, is there a way I can define a path in the code above to output the file at a specific location ?

The location I am talking about is a NAS file watcher location having the path like the below

\\xxx1prd-xxxxxx\ABC-Xxxxxxxxxxxxxx-XXXX\XXX\XXX\XXX\XXXXXX

Best Regards


Solution

    1. The easiest would be mapping your NAS share as Windows network drive and changing the file path to start from this network drive like:

      assuming that you assign letter N to your network drive:

       FileUtils.writeStringToFile(new File("N:/MPOS_" + ${__P(batchno)} + "-" + ${p_Sequence} + "-" +"${__time(yyyyMMddhhmmss)}" + ".xml"),data);
      
    2. You should be using JSR223 Test Elements and Groovy language for scripting since JMeter 3.1

    3. You should NOT inline JMeter Functions or Variables into Groovy scripts so change:

      • ${__P(batchno)} to props.get("batchno")
      • ${p_Sequence} to vars.get("p_Sequence")
      • etc.

      More information: Top 8 JMeter Java Classes You Should Be Using with Groovy

    If you cannot map the network drive - go for JCIFS library which provides possibility to write files to network shares