我正在尝试使用 JSR223 Sampler 连接到 Jmeter 中的 MongoDB。这是我的代码:
import com.mongodb.MongoClientURI;
import com.mongodb.MongoClient;
import org.bson.Document;
import com.mongodb.BasicDBObject;
import com.mongodb.ConnectionString;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCursor;
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 java.util.Arrays;
import com.mongodb.Cursor;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
try {
MongoClientURI connectionString = new MongoClientURI("mymongodb.com:27017");
MongoClient mongoClient = MongoClients.create(connectionString);
MongoDatabase database = mongoClient.getdatabse("mydatbase");
MongoCollection<Document> collection = database.getCollection("employee");
}
catch (Throwable ex) {
log.error("Error in Beanshell", ex);
throw ex;
}
我收到错误:
错误 o.a.j.p.j.s.J.JSR223 采样器:Beanshell 中出现错误 groovy.lang.MissingMethodException:没有方法签名:静态 com.mongodb.client.MongoClients.create() 适用于参数类型:(com.mongodb.MongoClientURI) 值:[mymongodb.com:27017] 可能的解决方案:create()、create(com.mongodb.ConnectionString)、create(com.mongodb.MongoClientSettings)、create(java.lang.String)、create(com.mongodb.ConnectionString、com.mongodb.MongoDriverInformation)、create (com.mongodb.MongoClientSettings、com.mongodb.MongoDriverInformation) 在 groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518) ~[groovy-all-2.4.16.jar:2.4.16] 在 groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504) ~[groovy-all-2.4.16.jar:2.4.16] 在 org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52) ~[groovy-all-2.4.16.jar:2.4.16] 在 org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-all-2.4.16.jar:2.4.16] 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116) [groovy-all-2.4.16.jar:2.4.16] 在 org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128) [groovy-all-2.4.16.jar:2.4.16] 在 Script11.run(Script11.groovy:44) [脚本:?] 在 org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:321) [groovy-all-2.4.16.jar:2.4.16] 在 org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) [groovy-all-2.4.16.jar:2.4.16] 在 javax.script.CompiledScript.eval(CompiledScript.java:89) [java.scripting:?] 在 org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) [ApacheJMeter_core.jar:5.1.1 r1855137] 在 org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.1.1 r1855137] 在 org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:622) [ApacheJMeter_core.jar:5.1.1 r1855137] 在 org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:546) [ApacheJMeter_core.jar:5.1.1 r1855137] 在 org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:486) [ApacheJMeter_core.jar:5.1.1 r1855137] 在 org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:253) [ApacheJMeter_core.jar:5.1.1 r1855137] 在 java.lang.Thread.run(Thread.java:834) [?:?]
有人有什么想法吗?非常感谢!
最佳答案
您的代码依赖于 diamond operator Beanshell 不支持该功能。
请注意 starting from JMeter 3.1 you should be using JSR223 Test Elements and Groovy language对于脚本编写,请考虑选择 groovy
作为脚本语言,您的代码应该开始正常工作
您可能还对 MongoDB Performance Testing with JMeter 感兴趣文章
关于java - groovy.lang.MissingMethodException : Error on Jmeter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61020518/