JMeter - Velocity JSR223 脚本无法使用 JMeter variables/environment
JMeter - Velocity JSR223 script can't use JMeter variables/environment
我可以在 JMeter 4/5 中加载 ,
我添加了 velocity-engine-core-2.0.jar
和 velocity-engine-scripting-2.0.jar
,其中包括 JSR223 语言列表中的速度,
(也尝试了最新速度 2.1 versions)
任何给出的文本都被忽略的问题,即使我输入了无效的语法它也不会抛出任何异常(与其他语言一样),或者使用 vars
、log
.. .
好像没有执行脚本,如何执行velocity JSR223脚本?我需要添加配置或罐子吗?
还是对速度有一些 JMeter/Java 限制?
试过例如:
log.info("Hello Velocity");
vars.put("a","Hello Velocity");
System.out.println("Hello Velocity");
NoExists.out.println("Hello Velocity");
我好像有velocity runtime dependencies
slf4j-api 1.7.25 Yes Yes Yes you'll also need an slf4j binding at runtime
commons-lang 3.5 Yes Yes Yes
库包含 slf4j-api-1.7.25.jar
commons-lang3-3.8.1.jar
并添加 slf4j-simple-1.7.25.jar
到默认 JMeter 库
日志:
2019-06-05 11:48:05,739 DEBUG o.a.j.c.GenericController: Calling next on: class org.apache.jmeter.control.GenericController
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Preparing class org.apache.jmeter.protocol.java.sampler.JSR223Sampler
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting scriptLanguage=velocity
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting parameters=
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting filename=
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting cacheKey=false
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting script=log.info("Hello Velocity");
vars.put("a","Hello Velocity");
System.out.println("Hello Velocity");
NoExists.out.println("Hello Velocity");
2019-06-05 11:48:05,739 DEBUG o.a.velocity: Initializing Velocity, Calling init()...
2019-06-05 11:48:05,739 TRACE o.a.velocity: *****************************
2019-06-05 11:48:05,739 DEBUG o.a.velocity: Starting Apache Velocity v2.0
2019-06-05 11:48:05,739 TRACE o.a.velocity: RuntimeInstance initializing.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: Default Properties resource: org/apache/velocity/runtime/defaults/velocity.properties
2019-06-05 11:48:05,741 TRACE o.a.v.loader: ResourceManager initializing: class org.apache.velocity.runtime.resource.ResourceManagerImpl
2019-06-05 11:48:05,741 DEBUG o.a.velocity: ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
2019-06-05 11:48:05,741 TRACE o.a.v.l.file: FileResourceLoader: initialization starting.
2019-06-05 11:48:05,741 DEBUG o.a.v.l.file: FileResourceLoader: adding path '.'
2019-06-05 11:48:05,741 TRACE o.a.v.l.file: FileResourceLoader: initialization complete.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
2019-06-05 11:48:05,741 TRACE o.a.v.loader: Default ResourceManager initialization complete.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Stop
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Define
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Break
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Macro
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Parse
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Include
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
2019-06-05 11:48:05,743 DEBUG o.a.v.parser: Created '20' parsers.
2019-06-05 11:48:05,743 TRACE o.a.v.macro: initialization starting.
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: "velocimacro.library" is not set. Trying default library: VM_global_library.vm
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: Default library not found.
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInline = true: VMs can be defined inline in templates
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInlineToOverride = false: VMs defined inline may NOT replace previous VM definitions
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInlineLocal = false: VMs defined inline will be global in scope if allowed.
2019-06-05 11:48:05,744 DEBUG o.a.v.macro: autoload off: VM system will not automatically reload global library macros
2019-06-05 11:48:05,744 TRACE o.a.v.macro: Velocimacro: initialization complete.
2019-06-05 11:48:05,744 TRACE o.a.velocity: RuntimeInstance successfully initialized.
2019-06-05 11:48:05,744 DEBUG o.a.j.c.GenericController: Calling next on: class org.apache.jmeter.control.GenericController
编辑
似乎无效的速度上下文会引发错误,
例如用于调用不存在的速度变量 $a
2019-06-05 12:39:28,804 DEBUG o.a.v.rendering: Null reference [template '<unknown>', line 2, column 7]: $a cannot be resolved.
但问题仍然是 JMeter 无法在其上下文中使用速度变量
编辑
解决方法是添加 velocity LogTool (velocity-tools-generic-3.0.jar) 并使用 $log
$log.debug( "Hello Velocity");
但不能将 JMeter 变量用作
$log.debug( "Hello " + vars.get("a"));
我发现了问题,在 Velocity 中你需要在上下文变量名称前添加 $
,
所以不用 vars
使用 $vars
:
$log.debug( "Hello " + $vars.get("a"));
进行了改进
我可以在 JMeter 4/5 中加载
我添加了 velocity-engine-core-2.0.jar
和 velocity-engine-scripting-2.0.jar
,其中包括 JSR223 语言列表中的速度,
(也尝试了最新速度 2.1 versions)
任何给出的文本都被忽略的问题,即使我输入了无效的语法它也不会抛出任何异常(与其他语言一样),或者使用 vars
、log
.. .
好像没有执行脚本,如何执行velocity JSR223脚本?我需要添加配置或罐子吗? 还是对速度有一些 JMeter/Java 限制?
试过例如:
log.info("Hello Velocity");
vars.put("a","Hello Velocity");
System.out.println("Hello Velocity");
NoExists.out.println("Hello Velocity");
我好像有velocity runtime dependencies
slf4j-api 1.7.25 Yes Yes Yes you'll also need an slf4j binding at runtime
commons-lang 3.5 Yes Yes Yes
库包含 slf4j-api-1.7.25.jar
commons-lang3-3.8.1.jar
并添加 slf4j-simple-1.7.25.jar
到默认 JMeter 库
日志:
2019-06-05 11:48:05,739 DEBUG o.a.j.c.GenericController: Calling next on: class org.apache.jmeter.control.GenericController
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Preparing class org.apache.jmeter.protocol.java.sampler.JSR223Sampler
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting scriptLanguage=velocity
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting parameters=
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting filename=
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting cacheKey=false
2019-06-05 11:48:05,739 DEBUG o.a.j.t.TestBeanHelper: Setting script=log.info("Hello Velocity");
vars.put("a","Hello Velocity");
System.out.println("Hello Velocity");
NoExists.out.println("Hello Velocity");
2019-06-05 11:48:05,739 DEBUG o.a.velocity: Initializing Velocity, Calling init()...
2019-06-05 11:48:05,739 TRACE o.a.velocity: *****************************
2019-06-05 11:48:05,739 DEBUG o.a.velocity: Starting Apache Velocity v2.0
2019-06-05 11:48:05,739 TRACE o.a.velocity: RuntimeInstance initializing.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: Default Properties resource: org/apache/velocity/runtime/defaults/velocity.properties
2019-06-05 11:48:05,741 TRACE o.a.v.loader: ResourceManager initializing: class org.apache.velocity.runtime.resource.ResourceManagerImpl
2019-06-05 11:48:05,741 DEBUG o.a.velocity: ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.FileResourceLoader
2019-06-05 11:48:05,741 TRACE o.a.v.l.file: FileResourceLoader: initialization starting.
2019-06-05 11:48:05,741 DEBUG o.a.v.l.file: FileResourceLoader: adding path '.'
2019-06-05 11:48:05,741 TRACE o.a.v.l.file: FileResourceLoader: initialization complete.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) with class java.util.Collections$SynchronizedMap cache map.
2019-06-05 11:48:05,741 TRACE o.a.v.loader: Default ResourceManager initialization complete.
2019-06-05 11:48:05,741 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Stop
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Define
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Break
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Evaluate
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Macro
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Parse
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Include
2019-06-05 11:48:05,742 DEBUG o.a.velocity: Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
2019-06-05 11:48:05,743 DEBUG o.a.v.parser: Created '20' parsers.
2019-06-05 11:48:05,743 TRACE o.a.v.macro: initialization starting.
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: "velocimacro.library" is not set. Trying default library: VM_global_library.vm
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: Default library not found.
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInline = true: VMs can be defined inline in templates
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInlineToOverride = false: VMs defined inline may NOT replace previous VM definitions
2019-06-05 11:48:05,743 DEBUG o.a.v.macro: allowInlineLocal = false: VMs defined inline will be global in scope if allowed.
2019-06-05 11:48:05,744 DEBUG o.a.v.macro: autoload off: VM system will not automatically reload global library macros
2019-06-05 11:48:05,744 TRACE o.a.v.macro: Velocimacro: initialization complete.
2019-06-05 11:48:05,744 TRACE o.a.velocity: RuntimeInstance successfully initialized.
2019-06-05 11:48:05,744 DEBUG o.a.j.c.GenericController: Calling next on: class org.apache.jmeter.control.GenericController
编辑
似乎无效的速度上下文会引发错误,
例如用于调用不存在的速度变量 $a
2019-06-05 12:39:28,804 DEBUG o.a.v.rendering: Null reference [template '<unknown>', line 2, column 7]: $a cannot be resolved.
但问题仍然是 JMeter 无法在其上下文中使用速度变量
编辑
解决方法是添加 velocity LogTool (velocity-tools-generic-3.0.jar) 并使用 $log
$log.debug( "Hello Velocity");
但不能将 JMeter 变量用作
$log.debug( "Hello " + vars.get("a"));
我发现了问题,在 Velocity 中你需要在上下文变量名称前添加 $
,
所以不用 vars
使用 $vars
:
$log.debug( "Hello " + $vars.get("a"));
进行了改进