NAS文件夹位置

huangapple go评论82阅读模式
英文:

NAS Folder Location

问题

希望一切都很好,我是从 Stack Overflow 链接跳转到这里的。

我参考了位于 https://stackoverflow.com/questions/38049311/save-body-request-in-jmeter 的 BeanShell 代码,稍微修改了一下,就可以按我想要的命名约定创建文件。

我正在创建定制的 XML 请求,它们非常庞大,需要创建大约 50 到 80 K 个 XML 文件。

创建文件不是问题,使用修改后的代码保存 XML 请求对我有效,它将文件保存到了 jmeter 的 bin 文件夹中。

请在下面找到稍微修改后的代码:

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);

上述代码段创建了像这样的 XML 文件:

MPOS_300008-15-20201010063800.xml

上述代码将文件写入了 jmeter 的 bin 位置。问题是,我不想将 XML 输出文件写入 jmeter 的 bin 位置,因为那么我就必须手动将其复制到 NAS 位置,这会带来太多的开销,而且系统可能在复制所有这些文件时出问题。因此,我的想法是一旦创建 XML,我就将 XML 放在 NAS 文件位置,是否有办法在上述代码中定义一个路径,以便在特定位置输出文件?

我所说的位置是 NAS 文件监视器位置,其路径类似于以下内容:

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

最好的祝愿。

英文:

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

I referred the bean shell code at https://stackoverflow.com/questions/38049311/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

答案1

得分: 1

  1. 最简单的方法是将你的NAS共享映射为Windows网络驱动器,并将文件路径更改为从该网络驱动器开始,例如:

    假设你将字母N分配给你的网络驱动器:

     FileUtils.writeStringToFile(new File("N:/MPOS_" + ${__P(batchno)} + "-" + ${p_Sequence} + "-" + "${__time(yyyyMMddhhmmss)}" + ".xml"),data);
    
  2. 自 JMeter 3.1 起,你应该使用JSR223测试元素和Groovy语言进行脚本编写。

  3. 请勿将JMeter函数或变量内联到Groovy脚本中,所以进行更改:

    • ${__P(batchno)} 改为 props.get("batchno")
    • ${p_Sequence} 改为 vars.get("p_Sequence")
    • 等等。

    更多信息:Top 8 JMeter Java Classes You Should Be Using with Groovy

如果无法映射网络驱动器,请考虑使用JCIFS库,该库可以将文件写入网络共享文件夹。

英文:
  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

huangapple
  • 本文由 发表于 2020年10月10日 17:42:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/64292030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定