2

I'm able to load Velocity as language to JSR223 in JMeter 4/5,

I added velocity-engine-core-2.0.jar and velocity-engine-scripting-2.0.jar which include velocity in JSR223 languages list,

(Tried also with latest velocity 2.1 versions)

The problem that any text given is ignored, even if I put invalid syntax it doesn't throw any exception (as in other languages), or use vars, log,...

It seems that script isn't executed, how can I execute velocity JSR223 script? do I need to add configurations or jars? Or is there some JMeter/Java restrictions for velocity?

Tried for example:

log.info("Hello Velocity");
vars.put("a","Hello Velocity");
System.out.println("Hello Velocity");
NoExists.out.println("Hello Velocity");

It seems that I have 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

library contains slf4j-api-1.7.25.jar commons-lang3-3.8.1.jar and added slf4j-simple-1.7.25.jar to default JMeter library

Log:

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

EDIT

It seems that Invalid velocity context can raise an error,

e.g. for calling not exists velocity variable $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.

But the problem remains that JMeter can't use the velocity variable in its context

EDIT

workaround is to add velocity LogTool (velocity-tools-generic-3.0.jar) and use $log

$log.debug( "Hello Velocity");

But can't use JMeter variable as

$log.debug( "Hello " + vars.get("a"));
Community
  • 1
  • 1
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • Are you checking log (Options -> Log Viewer) in GUI? Do you have correct log level (Options -> Log Level)? – lojza Jun 05 '19 at 08:40
  • @lojza yes, also `OUT` not working `System.out.println`, and invalid syntax is ignored instead of exception – Ori Marko Jun 05 '19 at 08:42
  • check your log: `"velocimacro.library" is not set` and `Default library not found` – lojza Jun 05 '19 at 08:54
  • It seems irrelevant when check https://stackoverflow.com/questions/5313470/getting-velocity-error-at-statup-vm-global-library-vm if not what is your suggestion? – Ori Marko Jun 05 '19 at 08:55
  • Sorry, I'm out of ideas :-( – lojza Jun 05 '19 at 09:07
  • Have you inquired with the JMeter teamt hat Velocity 2.0+ works with JMeter 5? – Michael-O Jun 05 '19 at 16:20
  • @michael-o JSR223 is open for all scripting languages, velocity is used for JMeter docs and There's an enhancenent to add it https://bz.apache.org/bugzilla/show_bug.cgi?id=63484 – Ori Marko Jun 06 '19 at 03:12
  • So you should test without JMeter through JSR 223 only, if that does not work. Then there is a bug in Velocity. – Michael-O Jun 06 '19 at 07:21
  • @michael-o velocity **can** be executed and log using its `$logTool` inside JMeter, but it can't use JMeter variables, meaning both works, but the integration is lacking – Ori Marko Jun 06 '19 at 07:23
  • This must be then a JMeter issue. – Michael-O Jun 06 '19 at 07:29
  • @Michael-O see my answer, In Velocity need to add `$` in front of the bindings variable name – Ori Marko Jun 06 '19 at 07:54

1 Answers1

1

I found the issue, in Velocity you need to add $ in front of your context variable name,

So instead of vars use $vars:

$log.debug( "Hello " + $vars.get("a"));

There's an enhancement to add Velocity to JMeter as JSR223 language, You can vote

Ori Marko
  • 56,308
  • 23
  • 131
  • 233