在加载负载测试期间的编译错误

时间:2017-10-16 08:33:02

标签: scala mqtt load-testing gatling gatling-plugin

我正在尝试编写模拟,我希望能够运行模拟。 尝试$ mvn gatling时遇到错误:执行。

我的pom有以下依赖项:

<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-charts</artifactId>
    <version>2.2.5</version>
</dependency>
<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-core</artifactId>
    <version>2.2.5</version>
</dependency>

以及以下插件:

<build>
    <plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <scalaVersion>2.12.3</scalaVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>2.2.4</version>
            <executions>
                <execution>
                    <id>performanceTests</id>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <simulationClass>simulations.SimulationClass</simulationClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

这是我遇到的错误:

12:50:36.313 [main][WARN ][ZincCompiler.scala:141] i.g.c.ZincCompiler$ - 
Pruning sources from previous analysis, due to incompatible CompileSetup.
java.lang.ClassNotFoundException: io.gatling.app.Gatling
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:42)
    at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)

包含依赖:

<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-app</artifactId>
    <version>2.2.5</version>
</dependency>

但现在我收到了一个新错误:

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.NoSuchMethodError: scala.Product.$init$(Lscala/Product;)V
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocolOptionPart.<init>(MqttProtocol.scala:124)
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocol$.apply(MqttProtocol.scala:24)
at com.github.mnogu.gatling.mqtt.protocol.MqttProtocolBuilder$.apply(MqttProtocolBuilder.scala:13)
at com.github.mnogu.gatling.mqtt.Predef$.mqtt(Predef.scala:9)
at simulations.SimulationClass.<init>(SimulationClass.scala:10)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.Runner.run0(Runner.scala:79)
at io.gatling.app.Runner.run(Runner.scala:64)
at io.gatling.app.Gatling$.start(Gatling.scala:59)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:43)
at io.gatling.app.Gatling$.main(Gatling.scala:35)
at io.gatling.app.Gatling.main(Gatling.scala)

...

关于这个问题的任何线索都会有很大的帮助。

谢谢

2 个答案:

答案 0 :(得分:1)

您的错误表明您缺少以下依赖项,

<!-- https://mvnrepository.com/artifact/io.gatling/gatling-app -->
<dependency>
    <groupId>io.gatling</groupId>
    <artifactId>gatling-app</artifactId>
    <version>2.2.5</version>
</dependency>

<强>更新

您的第二个错误主要是因为您的代码在运行时引用的jar文件与编译时使用的jar文件不同。因此,请确保在编译和运行时使用相同的jar。

为此,您可以删除相关jar文件,清理项目并重新编译并运行程序。

答案 1 :(得分:1)

看起来我使用的外部jar只与gatling core 2.2.3兼容。将gatling核心版本恢复为2.2.3,将scala版本恢复为2.11.8解决了这个问题。

以下是我的pom现在的样子:

<dependency>
        <groupId>io.gatling.highcharts</groupId>
        <artifactId>gatling-charts-highcharts</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-core</artifactId>
        <version>2.2.3</version>
    </dependency>
    <dependency>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-app</artifactId>
        <version>2.2.3</version>
    </dependency>

<plugins>
        <plugin>
            <groupId>net.alchim31.maven</groupId>
            <artifactId>scala-maven-plugin</artifactId>
            <version>3.3.1</version>
            <configuration>
                <scalaVersion>2.11.8</scalaVersion>
            </configuration>
        </plugin>
        <plugin>
            <groupId>io.gatling</groupId>
            <artifactId>gatling-maven-plugin</artifactId>
            <version>2.2.3</version>
            <executions>
                <execution>
                    <id>performanceTests</id>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <simulationClass>simulations.SimulationClass</simulationClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>