smicyk / groovy-jmeter

A Groovy-based DSL for building and running JMeter test plans from command line and more.
Apache License 2.0
13 stars 1 forks source link

Troubleshoot for no output #119

Closed AntonioSun closed 7 months ago

AntonioSun commented 7 months ago

Running under Mac:

$ java -version
openjdk version "11.0.21" 2023-10-17
OpenJDK Runtime Environment Homebrew (build 11.0.21+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.21+0, mixed mode)

$ groovy -v
Groovy Version: 3.0.17 JVM: 11.0.21 Vendor: Homebrew OS: Mac OS X

$ groovy example0.groovy --help
Usage: groovy [-chw] [--no-run] [--jmx-out=<file>] [-r=<hostname:port>]
. . .

$ groovy example0.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.vmplugin.v9.Java9 (file:/Users/myid/.sdkman/candidates/groovy/current/lib/groovy-3.0.17.jar) to method sun.nio.fs.UnixFileSystem.getPath(java.lang.String,java.lang.String[])
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.vmplugin.v9.Java9
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
WARN StatusConsoleListener The use of package scanning to locate plugins is deprecated and will be removed in a future release
Warning: Nashorn engine is planned to be removed from a future JDK release

$ cat example0.groovy
@GrabConfig(systemClassLoader=true)
@Grab('net.simonix.scripts:groovy-jmeter')

@groovy.transform.BaseScript net.simonix.dsl.jmeter.DefaultTestScript script

start {
    plan {
        group {
            http 'GET http://www.example.com'
        }

        // optional element, shows execution progress
        summary(file: 'log.jtl')
    }
}

The typical output on console is not there. How to troubleshoot the problem pls?

AntonioSun commented 7 months ago

I've just tried it under Linux (Ubuntu 20.04.6 LTS) and I'm getting the same result as well.

smicyk commented 7 months ago

Hi, so your test should look like this:

@GrabConfig(systemClassLoader=true)                                                                                                                                                      
@Grab('net.simonix.scripts:groovy-jmeter')                                                                                                                                               

@groovy.transform.BaseScript net.simonix.dsl.jmeter.TestScript script                                                                                                                    

start {                                                                                                                                                                                  
     plan {                                                                                                                                                                               
         group {                                                                                                                                                                                                                                                                                     
              http 'GET http://www.example.com'                                                                                                                                        
         }                                                                                                                                                                                

         // optional element, shows execution progress                                                                                                                                    
        summary(file: 'log.jtl', enabled: true)                                                                                                                                          
     }                                                                                                                                                                                    
}

The important thing here is the enabled: true property which actually enabled the logging. By default all listeners are off so they don't consume resources when running on test server.

The second thing is the DefaultTestScript you should change it to TestScript as the latter have command line support.

AntonioSun commented 7 months ago

Thanks, I think the new command line support is giving the following errors:

$ groovy example0.groovy --help
Caught: java.lang.NoClassDefFoundError: picocli/CommandLine$ParameterException
java.lang.NoClassDefFoundError: picocli/CommandLine$ParameterException
    at net.simonix.dsl.jmeter.TestScript.run(TestScript.groovy:49)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: java.lang.ClassNotFoundException: picocli.CommandLine$ParameterException

I tried my best to fix it myself

$ cat example0.groovy
GrabConfig(systemClassLoader=true)                                             
@Grab('info.picocli:picocli-groovy')
@Grab('net.simonix.scripts:groovy-jmeter')                                     

@groovy.transform.BaseScript net.simonix.dsl.jmeter.TestScript script          

start {                                                                        
     plan {                                                                    
         group {                                                               
              http 'GET http://www.example.com'                                
         }                                                                     

         // optional element, shows execution progress                         
        summary(file: 'log.jtl', enabled: true)                                
     }                                                                         
}

please help.

smicyk commented 7 months ago

Hi, sorry it seems that I didn't add @ character before GrabConfig.

My original answer is updated.

AntonioSun commented 7 months ago

Ah, I looked at it many times but didn't notice the missing @, 😊

It's working now. Thanks!!

AntonioSun commented 7 months ago

The important thing here is the enabled: true property which actually enabled the logging. By default all listeners are off so they don't consume resources when running on test server.

Ah, found that it was enabled before when I used the project last time. No wonder all my old scripts seemed to be "stopped working".