jMeter-初始化文件中的Beanshell bsh.shared哈希图数据? [英] jMeter - Beanshell bsh.shared hashmap data in init file?

查看:332
本文介绍了jMeter-初始化文件中的Beanshell bsh.shared哈希图数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个jMeter项目,该项目引发了各种各样的问题.主要是由于在整个运行过程中都存储和定义了可变数据.

I have a jMeter project I'm working on which has thrown up all sorts of problems. Mainly due to storing and scoping of variable data throughout the run.

我现在有很多工作要做,并且我正在使用Beanshell共享哈希图通过运行来存储数据.我不需要担心线程安全,因为我的工作方式.

I now have things pretty much working and I'm using a Beanshell shared hashmap to store data through the run. I don't need to worry about thread safety due to the way I'm doing it.

它可以工作,但是每次线程组运行时都会重新初始化自己.尽管将初始化步骤放在了所有线程组之外.

It works, but it re-initialises itself each time a thread group runs. Despite putting the initialisation step outside all thread groups.

因此,据我了解,解决方案是将所有启动数据放入初始化文件,该文件在启动时仅运行一次.但是我不知道该怎么做?我已经将以前使用的Beanshell预处理器中的代码复制到了".bshrc"文件中,并用".bshrc"文件的位置更新了jMeter属性文件,但是它似乎无法正常工作.它实际上似乎并没有做任何事情.当我运行测试时,不存在任何值,并且一切都会失败.

So, as I understand it, the solution is to put all the startup data into an initialisation file which is only run once on startup. But I can't figure out how I'm supposed to do that? I've copied the code from the Beanshell Preprocessor I was using previously into a ".bshrc" file and updated the jMeter properties file with the location of my ".bshrc" file, but it doesn't seem to work. It doesn't actually seem to have done anything. When I run the test, no values are present and everything fails.

我尝试使用:

beanshell.init.file = ../bin/data.bshrc 和 beanshell.preprocessor.init = ../bin/data.bshrc

beanshell.init.file=../bin/data.bshrc and beanshell.preprocessor.init=../bin/data.bshrc

我试图找到某种用于设置init文件的白痴指南,但找不到任何有用的东西.这是我第一次必须认真使用Beanshell,而我的Java知识充其量是非常有限的!

I've tried to find some sort of idiots guide to setting up an init file, but I can't find anything helpful. This is the first time I've had to make much serious use of Beanshell and my Java knowledge is VERY limited at best!

此刻,我通过启用原始Beanshell预处理程序运行一次测试来解决这个问题.这将设置哈希图,并且它们从此开始就驻留在内存中.我停止了此运行,禁用了预处理器,随后的所有运行都很好.

At the moment, I'm getting round it by running my test once with the original Beanshell pre-processor enabled. This sets up the hashmaps and they stay resident in memory from there on. I stop this run, disable the pre-processor, and all subsequent runs work just fine.

有人吗?

推荐答案

我建议使用 setUp线程组(将在其他线程组之前执行),并使用

I would suggest using setUp Thread Group which is being executed prior to any other Thread Groups and define your test data there with a Beanshell Sampler like

bsh.shared.myMap = new java.util.HashMap();
bsh.shared.myMap.put("foo","bar");
// any other operations

之后,您可以在主线程组中以

After that in your main Thread Group(s) you can access myMap values in any Beanshell-enabled test element (Sampler, Pre/Post Processor, Assertion) as

log.info("foo = " + bsh.shared.myMap.get("foo"));

2014/07/22 10:06:48信息-jmeter.util.BeanShellTestElement:foo = bar

2014/07/22 10:06:48 INFO - jmeter.util.BeanShellTestElement: foo = bar

请参见如何使用BeanShell:JMeter最喜欢的内置组件指南,以获取有关Apache JMeter中的Beanshell脚本和Beanshell食谱的更多详细信息.

See How to use BeanShell: JMeter's favorite built-in component guide for more details on Beanshell scripting in Apache JMeter and a kind of Beanshell cookbook.

如果您将Beanshell用于大量"操作,我建议您考虑切换到 JSR223采样器时髦的语言,因为在这种情况下,您将获得性能与本地Java代码相当.

If you use Beanshell for "heavy" operations I would recommend considering switching to JSR223 Sampler and Groovy language as in that case you'll get performance comparable to native Java code.

这篇关于jMeter-初始化文件中的Beanshell bsh.shared哈希图数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆