0

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.

    > use jmeter_test
    switched to db jmeter_test
    > db.createCollection("blazemeter_tutorial")
    { "ok" : 1 }
    > show collections
    blazemeter_tutorial
    > 

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 -> 
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);
}

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: 'java.lang.String org.bson.types.ObjectId.toHexString()'
    at com.mongodb.connection.ClusterId.<init>(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.<init>(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: 'java.lang.String org.bson.types.ObjectId.toHexString()'
    at com.mongodb.connection.ClusterId.<init>(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.<init>(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?

2 Answers 2

1

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 ("text"|"bin"|""):text
Response code:200
Response message:OK


SampleResult fields:
ContentType: 
DataEncoding: UTF-8
Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Rerunning after removing bson gives me similar error. 2020-08-27 15:40:23,086 ERROR o.a.j.JMeter: Uncaught exception in thread Thread[test1 1-1,6,main] java.lang.NoSuchMethodError: 'java.lang.String org.bson.types.ObjectId.toHexString()'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.