jmeter Uncaught Exception java.lang.NoSuchMethodError: 'java.lang.String org.bson.types.ObjectId.toHexString()'

huangapple go评论104阅读模式
英文:

jmeter Uncaught Exception java.lang.NoSuchMethodError: 'java.lang.String org.bson.types.ObjectId.toHexString()'

问题

以下是翻译的内容:

我正在使用 JMeter 测试 MongoDB。我按照 https://dzone.com/articles/mongodb-performance-testing-with-jmeter 中的指示进行操作。

在远程服务器上,我安装了 MongoDB,并将 /etc/mongodb.conf 更改为使用公共 IP 地址绑定 bindIP。从我的本地系统中,我调用了 'mongo' 命令,并创建了一个名为 jmeter_test 的 MongoDB 数据库和一个名为 blazemeter_tutorial 的集合。

    > use jmeter_test
    切换到数据库 jmeter_test
    > db.createCollection("blazemeter_tutorial")
    { "ok" : 1 }
    > show collections
    blazemeter_tutorial
    >

我安装了 JMeter 5.3,还从 lib/ext 下载了 bson-4.1.0.jar、groovy-3.0.5.jar 和 mongo-java-driver-3.12.7.jar。我创建了一个新的测试计划,其中包含连接脚本所需的适当的 'User Defined Variables'。

mongoHost: 192.168.1.6
mongoPort: 27017
databaseName: jmeter_test
collectionName: blazemeter_tutorial

在网页上找到的连接脚本如下:

import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import java.util.Arrays;
try {
MongoClientSettings settings = MongoClientSettings.builder()
.applyToClusterSettings {builder -> 
builder.hosts(Arrays.asList(new ServerAddress(vars.get("mongoHost"),vars.get("mongoPort").toInteger())))}
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase(vars.get("databaseName"));
MongoCollection<Document> collection = database.getCollection(vars.get("collectionName"));
vars.putObject("collection", collection);
return "Connected to " + vars.get("collectionName");
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode("500");
SampleResult.setResponseMessage("Exception: " + e);
}

当我通过 JMeter 运行此脚本时,我得到以下错误:

2020-08-27 12:58:35,230 INFO o.a.j.e.StandardJMeterEngine: Running the test!
...
java.lang.NoSuchMethodError: 'java.lang.String org.bson.types.ObjectId.toHexString()'
...

我不是 Java 专家,但在我看来,这似乎是内部错误或某种错误,与脚本无关?有人以前见过这种情况吗?可以请您帮忙吗?

英文:

I am using jmeter to test mongodb.I following the instructions in https://dzone.com/articles/mongodb-performance-testing-with-jmeter

On a remote server I installed mongodb, and changed the /etc/mongodb.conf to use bindIP public IP address. From my local system, I invoked 'mongo' command and I created a mongodb database called jmeter_test and a collection called blazemeter_tutuorial.

    &gt; use jmeter_test
    switched to db jmeter_test
    &gt; db.createCollection(&quot;blazemeter_tutorial&quot;)
    { &quot;ok&quot; : 1 }
    &gt; show collections
    blazemeter_tutorial
    &gt; 

I installed jmeter 5.3 and also downloaded into lib/ext bson-4.1.0.jar groovy-3.0.5.jar and mongo-java-driver-3.12.7.jar. I created a new test plan with appropriate 'User Defined Variables' needed for the connection script.

mongoHost: 192.168.1.6
mongoPort: 27017
databaseName: jmeter_test
collectionName: blazemeter_tutorial

The connection script found on that web page is as follows:

import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.bson.Document;
import java.util.Arrays;
try {
MongoClientSettings settings = MongoClientSettings.builder()
.applyToClusterSettings {builder -&gt; 
builder.hosts(Arrays.asList(new ServerAddress(vars.get(&quot;mongoHost&quot;),vars.get(&quot;mongoPort&quot;).toInteger())))}
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase(vars.get(&quot;databaseName&quot;));
MongoCollection&lt;Document&gt; collection = database.getCollection(vars.get(&quot;collectionName&quot;));
vars.putObject(&quot;collection&quot;, collection);
return &quot;Connected to &quot; + vars.get(&quot;collectionName&quot;);
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode(&quot;500&quot;);
SampleResult.setResponseMessage(&quot;Exception: &quot; + e);
}

When I run this script though jmeter I get the following error:

2020-08-27 12:58:35,230 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-08-27 12:58:35,231 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-08-27 12:58:35,246 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-08-27 12:58:35,326 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : test1
2020-08-27 12:58:35,326 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group test1.
2020-08-27 12:58:35,327 INFO o.a.j.e.StandardJMeterEngine: Thread will stop on error
2020-08-27 12:58:35,327 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2020-08-27 12:58:35,328 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-08-27 12:58:35,328 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-08-27 12:58:35,335 INFO o.a.j.t.JMeterThread: Thread started: test1 1-1
2020-08-27 12:58:35,430 INFO o.a.j.t.JMeterThread: Thread finished: test1 1-1
2020-08-27 12:58:35,432 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[test1 1-1,6,main]
java.lang.NoSuchMethodError: &#39;java.lang.String org.bson.types.ObjectId.toHexString()&#39;
	at com.mongodb.connection.ClusterId.&lt;init&gt;(ClusterId.java:47) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.connection.DefaultClusterFactory.createCluster(DefaultClusterFactory.java:182) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.internal.MongoClientImpl.createCluster(MongoClientImpl.java:209) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.internal.MongoClientImpl.&lt;init&gt;(MongoClientImpl.java:63) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients.create(MongoClients.java:114) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients.create(MongoClients.java:50) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients$create.call(Unknown Source) ~[?:?]
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.3.jar:3.0.3]
	at Script4.run(Script4.groovy:14) ~[?:?]
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.3.jar:3.0.3]
	at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
	at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:222) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72) ~[ApacheJMeter_java.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) ~[ApacheJMeter_core.jar:5.3]
	at java.lang.Thread.run(Thread.java:834) [?:?]
2020-08-27 12:58:35,434 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-08-27 12:58:35,437 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)
2020-08-27 13:01:01,795 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-08-27 13:01:01,796 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-08-27 13:01:01,799 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-08-27 13:01:01,877 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : test1
2020-08-27 13:01:01,877 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group test1.
2020-08-27 13:01:01,877 INFO o.a.j.e.StandardJMeterEngine: Thread will stop on error
2020-08-27 13:01:01,878 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2020-08-27 13:01:01,879 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-08-27 13:01:01,879 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-08-27 13:01:01,884 INFO o.a.j.t.JMeterThread: Thread started: test1 1-1
2020-08-27 13:01:01,976 INFO o.a.j.t.JMeterThread: Thread finished: test1 1-1
2020-08-27 13:01:01,977 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[test1 1-1,6,main]
java.lang.NoSuchMethodError: &#39;java.lang.String org.bson.types.ObjectId.toHexString()&#39;
	at com.mongodb.connection.ClusterId.&lt;init&gt;(ClusterId.java:47) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.connection.DefaultClusterFactory.createCluster(DefaultClusterFactory.java:182) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.internal.MongoClientImpl.createCluster(MongoClientImpl.java:209) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.internal.MongoClientImpl.&lt;init&gt;(MongoClientImpl.java:63) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients.create(MongoClients.java:114) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients.create(MongoClients.java:50) ~[mongo-java-driver-3.12.7.jar:?]
	at com.mongodb.client.MongoClients$create.call(Unknown Source) ~[?:?]
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) ~[groovy-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) ~[groovy-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139) ~[groovy-3.0.3.jar:3.0.3]
	at Script5.run(Script5.groovy:14) ~[?:?]
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) ~[groovy-jsr223-3.0.3.jar:3.0.3]
	at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.3.jar:3.0.3]
	at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
	at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:222) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72) ~[ApacheJMeter_java.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) ~[ApacheJMeter_core.jar:5.3]
	at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) ~[ApacheJMeter_core.jar:5.3]
	at java.lang.Thread.run(Thread.java:834) [?:?]
2020-08-27 13:01:01,979 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-08-27 13:01:01,980 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

I am not an expert in Java, but to me it looks like an internal error or some sort and not related the script? Has anyone seen this before? could you please help?

答案1

得分: 1

抱歉.. 我发现 lib/ 目录下有 mongo-java-driver-2.11.3.jar 和 groovy-3.0.3.jar。

  1. 我从 lib 目录中移除了 mongo-java-driver-2.11.3.jar
  2. 移除了我下载的 ext/groovy-3.0.5.jar。

然后重新运行了 jmeter 连接脚本,它成功运行了!

线程名称:test1 1-1
采样开始时间:2020-08-27 15:58:19 CDT
加载时间:2054
连接时间:0
延迟:0
字节大小:32
发送的字节:0
头部字节大小:0
正文字节大小:32
采样次数:1
错误次数:0
数据类型("文本"|"二进制"|""):文本
响应代码:200
响应消息:OK

SampleResult 字段:
内容类型:
数据编码:UTF-8
英文:

oops.. I found that lib/ has mongo-java-driver-2.11.3.jar and also groovy-3.0.3.jar.

  1. I removed the mongo-java-driver-2.11.3.jar from lib
  2. Removed the ext/groovy-3.0.5.jar that I had downloaded.

and re-ran the jmeter connect script and it worked!

Thread Name:test1 1-1
Sample Start:2020-08-27 15:58:19 CDT
Load time:2054
Connect Time:0
Latency:0
Size in bytes:32
Sent bytes:0
Headers size in bytes:0
Body size in bytes:32
Sample Count:1
Error Count:0
Data type (&quot;text&quot;|&quot;bin&quot;|&quot;&quot;):text
Response code:200
Response message:OK


SampleResult fields:
ContentType: 
DataEncoding: UTF-8

答案2

得分: 0

一个有点冒险的尝试,但 mongo-java-driver-3.12.7.jar 应该已经包含了 org.bson.types.ObjectId 类,并且引入一个单独的版本可能会导致您得到一个没有 toHexString 方法的版本。我建议尝试将 bson-4.1.0.jar 从项目中移除,看看会发生什么。

英文:

A bit of a long shot, but the mongo-java-driver-3.12.7.jar should already contain the org.bson.types.ObjectId class and pulling in a separate version might have given you one without the toHexString method. I would try removing the bson-4.1.0.jar from the equation to see what happens.

huangapple
  • 本文由 发表于 2020年8月28日 02:19:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63622051.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定