Kafkameter NoClassDefFoundError

时间:2017-03-23 16:46:15

标签: java jmeter apache-kafka load-testing jmeter-plugins

我希望通过jMeter extension安装的jMeter plugin manager向Kafka消费者发送动态生成的消息来加载测试Kafka。

我的Kafka已经完美配置,设置和运行。我跟着these instructions设置了一个Kafka测试计划并运行它,但是每次我设置并运行它时,我都会在日志中收到此错误:

2017/03/23 10:35:48 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.assertions.BSFAssertion 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.extractor.BSFPostProcessor 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.modifiers.BSFPreProcessor 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/html is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xhtml+xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for application/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.sampler.HTTPSamplerBase: Parser for text/css is org.apache.jmeter.protocol.http.parser.CssParser 
2017/03/23 10:35:49 INFO  - jorphan.exec.KeyToolUtils: keytool found at 'keytool' 
2017/03/23 10:35:49 INFO  - jmeter.protocol.http.proxy.ProxyControl: HTTP(S) Test Script Recorder SSL Proxy will use keys that support embedded 3rd party resources in file /Users/jordan/Downloads/apache-jmeter-3.1/bin/proxyserver.jks 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.protocol.java.sampler.BSFSampler 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.protocol.mongodb.config.MongoSourceElement 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.protocol.mongodb.sampler.MongoScriptSampler 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.timers.BSFTimer 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.visualizers.BSFListener 
2017/03/23 10:35:49 INFO  - jmeter.gui.util.MenuFactory: Skipping org.apache.jmeter.visualizers.MonitorHealthVisualizer 
2017/03/23 10:35:49 INFO  - jmeter.samplers.SampleResult: Note: Sample TimeStamps are START times 
2017/03/23 10:35:49 INFO  - jmeter.samplers.SampleResult: sampleresult.default.encoding is set to ISO-8859-1 
2017/03/23 10:35:49 INFO  - jmeter.samplers.SampleResult: sampleresult.useNanoTime=true 
2017/03/23 10:35:49 INFO  - jmeter.samplers.SampleResult: sampleresult.nanoThreadSleep=5000 
2017/03/23 10:38:54 INFO  - jmeter.services.FileServer: Default base='/Users/jordan' 
2017/03/23 10:38:54 INFO  - jmeter.gui.action.Load: Loading file: /Users/jordan/Downloads/apache-jmeter-3.1/bin/test-plans/kafka-test.jmx 
2017/03/23 10:38:54 INFO  - jmeter.services.FileServer: Set new base='/Users/jordan/Downloads/apache-jmeter-3.1/bin/test-plans' 
2017/03/23 10:38:54 INFO  - jmeter.save.SaveService: Testplan (JMX) version: 2.2. Testlog (JTL) version: 2.2 
2017/03/23 10:38:54 INFO  - jmeter.save.SaveService: Using SaveService properties file encoding UTF-8 
2017/03/23 10:38:54 INFO  - jmeter.save.SaveService: Using SaveService properties version 3.1 
2017/03/23 10:38:54 INFO  - jmeter.save.SaveService: All converter versions present and correct 
2017/03/23 10:38:54 INFO  - jmeter.save.SaveService: Loading file: /Users/jordan/Downloads/apache-jmeter-3.1/bin/test-plans/kafka-test.jmx 
2017/03/23 10:38:54 INFO  - jmeter.services.FileServer: Set new base='/Users/jordan/Downloads/apache-jmeter-3.1/bin/test-plans' 
2017/03/23 10:39:04 INFO  - jmeter.engine.StandardJMeterEngine: Running the test! 
2017/03/23 10:39:04 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2017/03/23 10:39:04 INFO  - jmeter.samplers.SampleEvent: List of sample_variables: [] 
2017/03/23 10:39:04 INFO  - jmeter.protocol.java.sampler.JavaSampler: Created class: co.signal.kafkameter.KafkaProducerSampler. Uses tearDownTest: true 
2017/03/23 10:39:04 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*) 
2017/03/23 10:39:05 INFO  - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group 
2017/03/23 10:39:05 INFO  - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group. 
2017/03/23 10:39:05 INFO  - jmeter.engine.StandardJMeterEngine: Thread will continue on error 
2017/03/23 10:39:05 INFO  - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false 
2017/03/23 10:39:05 INFO  - jmeter.threads.ThreadGroup: Started thread group number 1 
2017/03/23 10:39:05 INFO  - jmeter.engine.StandardJMeterEngine: All thread groups have been started 
2017/03/23 10:39:05 INFO  - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1 
2017/03/23 10:39:05 ERROR - jmeter.threads.JMeterThread: Test failed! java.lang.NoClassDefFoundError: org/apache/log4j/Logger
    at kafka.utils.Logging$class.logger(Logging.scala:24)
    at kafka.utils.VerifiableProperties.logger(VerifiableProperties.scala:23)
    at kafka.utils.Logging$class.info(Logging.scala:66)
    at kafka.utils.VerifiableProperties.info(VerifiableProperties.scala:23)
    at kafka.utils.VerifiableProperties.verify(VerifiableProperties.scala:180)
    at kafka.producer.ProducerConfig.<init>(ProducerConfig.scala:57)
    at co.signal.kafkameter.KafkaProducerSampler.setupTest(KafkaProducerSampler.java:90)
    at org.apache.jmeter.protocol.java.sampler.JavaSampler.sample(JavaSampler.java:193)
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475)
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 12 more

2017/03/23 10:39:05 INFO  - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1 
2017/03/23 10:39:05 INFO  - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test 
2017/03/23 10:39:05 WARN  - jmeter.engine.StandardJMeterEngine: Error encountered during shutdown of org.apache.jmeter.protocol.java.sampler.JavaSampler@51cd3642 java.lang.NullPointerException
    at co.signal.kafkameter.KafkaProducerSampler.teardownTest(KafkaProducerSampler.java:96)
    at org.apache.jmeter.protocol.java.sampler.JavaSampler.testEnded(JavaSampler.java:292)
    at org.apache.jmeter.engine.StandardJMeterEngine.notifyTestListenersOfEnd(StandardJMeterEngine.java:216)
    at org.apache.jmeter.engine.StandardJMeterEngine.run(StandardJMeterEngine.java:437)
    at java.lang.Thread.run(Thread.java:745)

2017/03/23 10:39:05 INFO  - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*) 

所以,我得到的错误说它找不到org/apache/log4j/logger,但我不知道如何解决这个问题。我看过other known issues其他人遇到的问题,看看他们是否与我的相似,但无济于事。我想也许我写的测试计划错了,但我找不到任何问题。对于我做错了什么有什么建议吗?

2 个答案:

答案 0 :(得分:2)

  

java.lang.ClassNotFoundException此异常表示该   类路径上找不到类。这表明我们是   试图加载类定义,并且该类不存在   classpath。

尝试添加log4j jar。

如果是maven项目,您可以添加以下依赖,随意更改为适当的版本。

<dependency>
   <groupId>log4j</groupId>
   <artifactId>log4j</artifactId>
   <version>1.2.15</version>
</dependency>

如果存在版本冲突,也可能发生这种情况,因为另一个jar中捆绑的log4j jar可能会找出并排除log4j jar。

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka_2.10</artifactId>
    <version>0.8.1.1</version>
    <exclusions>
        <exclusion>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
        </exclusion>
    </exclusions>
</dependency>

答案 1 :(得分:0)

我想出了这个问题。 jMeter在其lib文件夹中缺少log4j jar,当下载并放入所述文件夹时,测试运行没有问题。