ngrinder初始化grinder进程的我问题

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

ngrinder初始化grinder进程的我问题

静风
您好,我把ngrinder转成spring boot项目的时候来测试groovy脚本出现下面的问题。

groovy的测试脚本提示这错误很奇怪,源码里面是这样的:
 final List<String> implementationNames;

    try {
      implementationNames =
        allResourceLines(getClass().getClassLoader(),
                         ScriptEngineService.RESOURCE_NAME);
    }
    catch (IOException e) {
      throw new EngineException("Failed to load script engine", e);
    }

其中ScriptEngineService.RESOURCE_NAME=String RESOURCE_NAME = "META-INF/net.grinder.scriptengine";
在项目的groovy的模块里面有路径./resources/META-INF/net.grinder.scriptengine,里面的内容是net.grinder.scriptengine.groovy.GroovyScriptEngineService



所以,我想知道ngrinder是通过传递什么参数告诉grinder初始化JythonEngine还是GroovyEngine。

进程测试的时候代码是这样初始化的:
String newClassPath = classPathProcessor.buildClasspathBasedOnCurrentClassLoader(LOGGER);
Properties systemProperties = new Properties();
                        systemProperties.put("java.class.path", base.getAbsolutePath() + File.pathSeparator + newClassPath);

上面的疑问,我猜测觉得是通过传递jvm参数给grinder,然后在grinder的进程里面通过= classLoader.getResources(resourceName);来找到这个配置;进一步我是否可以理解只要在传递jvm参数里面加上了ngrinder-groovy.jar这个classpath,那么grinder在进程里面就好用GroovyEngine来初始化和执行。

在测试脚本执行后会有下面的日志:
Instrumentation agents: byte code transforming instrumenter for jython;
byte code transforming instrumenter for Java 【错误的时候或者是jython脚本类型】
或者
Instrumentation agents: byte code transforming instrumenter for Java;
byte code transforming instrumenter for Java
 上面日志执行的代码是:
final Instrumenter instrumenter =
        scriptEngineContainer.createInstrumenter();

      m_testRegistryImplementation.setInstrumenter(instrumenter);

      m_logger.info("instrumentation agents: {}",
                    instrumenter.getDescription());


下面的错误日志我觉得是在启动grinder进程的时候没有ngrinder-groovy.jar这个classpath导致用的默认的JythonEngine来初始化的?
2017-10-24 21:27:55,228 ERROR worker-bootstrap: Error running worker process
java.lang.NoClassDefFoundError: org/python/core/PyReflectedFunction
        at net.grinder.scriptengine.jython.JythonScriptEngineService.createInstrumenters(JythonScriptEngineService.java:86)
        at net.grinder.engine.process.ScriptEngineContainer.createInstrumenter(ScriptEngineContainer.java:123)
        at net.grinder.engine.process.GrinderProcess.run(GrinderProcess.java:366)
        at net.grinder.engine.process.WorkerProcessEntryPoint.run(WorkerProcessEntryPoint.java:87)
        at net.grinder.engine.process.WorkerProcessEntryPoint.main(WorkerProcessEntryPoint.java:60)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyReflectedFunction
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 5 common frames omitted
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/core/PyReflectedFunction
        at net.grinder.scriptengine.jython.JythonScriptEngineService.createInstrumenters(JythonScriptEngineService.java:86)
        at net.grinder.engine.process.ScriptEngineContainer.createInstrumenter(ScriptEngineContainer.java:123)
        at net.grinder.engine.process.GrinderProcess.run(GrinderProcess.java:366)
        at net.grinder.engine.process.WorkerProcessEntryPoint.run(WorkerProcessEntryPoint.java:87)
        at net.grinder.engine.process.WorkerProcessEntryPoint.main(WorkerProcessEntryPoint.java:60)
Caused by: java.lang.ClassNotFoundException: org.python.core.PyReflectedFunction
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 5 more


由于grinder里面的代码很难调试,所以我不确定上面的逻辑是否正确,希望能回答我的问题,谢谢!