Я хочу вставить один раз и обновить несколько раз в MongoDb через JMeter. В случае необходимости MOngoDb работает в Docker. У меня возникают проблемы при подключении, но, похоже, я пытаюсь подключиться к MongoDb неправильно.
Я уверен, что MongoDb запущен и работает, так как я могу успешно подключиться и добавить в него данные из Spring с такими параметрами:
spring:
data:
mongodb:
host: localhost
port: 27017
database: demodb
authentication-database: admin
username: root
password: rootpassword
Я попробовал два подхода в JMeter, и оба возвращают ошибки:
ПЕРВЫЙ ТЕНТИВАТИВ *
С лямбда. Я где-то читал, что лямбда не работает с Grovy, но я пытаюсь использовать Java (я ничего не знаю о Grovy). Я добавил эту деталь здесь, потому что, когда я ищу людей, сталкивающихся с проблемами с «->» в Jmeter, ответы всегда связаны с «Grovy не работает с Lambda». Я проигнорировал этот ответ, так как я использую Java. По крайней мере, я предполагаю, что правильно выбрал Java, щелкнув правой кнопкой мыши по группе потоков -> Образец -> Образец JSR 223 -> в поле «Язык сценариев». Я поднял java (Bean Shell2.0b6 / Bean Shell Engine 1.0)
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("localhost"),vars.get("27017").toInteger())))}
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase(vars.get("demodb"));
MongoCollection<Document> collection = database.getCollection(vars.get("transfers"));
vars.putObject("collection", collection);
Document document = new Document("id", "3")
.append("origem", "Jimis")
.append("destino", "drpc")
.append("status", 1);
collection.insertOne(document);
return "Connected to " + vars.get("transfers");
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode("500");
SampleResult.setResponseMessage("Exception: " + e);
}
При таком подходе я получаю этот журнал ошибок:
2020-04-03 16:11:23,519 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-04-03 16:11:23,519 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-04-03 16:11:23,520 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-04-03 16:11:23,529 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2020-04-03 16:11:23,529 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2020-04-03 16:11:23,530 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2020-04-03 16:11:23,530 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2020-04-03 16:11:23,531 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-04-03 16:11:23,533 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-04-03 16:11:23,534 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2020-04-03 16:11:23,542 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: In file: inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' Encountered ">" at line 10, column 103.
in inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' at line number 10
javax.script.ScriptException: In file: inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' Encountered ">" at line 10, column 103.
in inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' at line number 10
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:82) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
at java.lang.Thread.run(Thread.java:834) [?:?]
2020-04-03 16:11:23,544 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2020-04-03 16:11:23,544 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2020-04-03 16:11:23,544 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-04-03 16:11:23,545 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)
ВТОРАЯ ПРОДОЛЖИТЕЛЬНОСТЬ)
Как избежать лямбды на случай, если она поможет мне двигаться вперед.
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 {
MongoClient mongoClient = MongoClients.create("demodb://root:rootpassword@localhost:27017/?authSource=admin&ssl=true");
MongoDatabase database = mongoClient.getDatabase(vars.get("demodb"));
MongoCollection<Document> collection = database.getCollection(vars.get("transfers"));
vars.putObject("collection", collection);
Document document = new Document("id", "3")
.append("origem", "Jimis")
.append("destino", "drpc")
.append("status", 1);
collection.insertOne(document);*
return "connected";
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode("500");
SampleResult.setResponseMessage("Exception: " + e);
}
И журналы:
2020-04-03 16:14:18,684 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-04-03 16:14:18,685 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-04-03 16:14:18,685 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-04-03 16:14:18,746 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2020-04-03 16:14:18,746 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2020-04-03 16:14:18,746 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2020-04-03 16:14:18,746 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2020-04-03 16:14:18,747 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-04-03 16:14:18,747 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-04-03 16:14:18,747 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2020-04-03 16:14:18,752 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: In file: inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' Encountered "=" at line 16, column 46.
in inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' at line number 16
javax.script.ScriptException: In file: inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' Encountered "=" at line 16, column 46.
in inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' at line number 16
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:82) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:225) ~[ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:627) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:551) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:490) [ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257) [ApacheJMeter_core.jar:5.2.1]
at java.lang.Thread.run(Thread.java:834) [?:?]
2020-04-03 16:14:18,753 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2020-04-03 16:14:18,753 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2020-04-03 16:14:18,753 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-04-03 16:14:18,753 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)
В первом эксперименте кажется, что он жалуется использовать здесь лямбду
MongoClientSettings settings = MongoClientSettings.builder().applyToClusterSettings {builder -> builder.hosts(Arrays.asList( new ServerAddress(vars.get("localhost"),vars.get("27017").toInteger())))}
.build();
А во втором предварительном кажется, что он жалуется на сигнал равенства но я не думаю, что мое понимание верно.
message: javax.script.ScriptException: In file: inline evaluation of: ``import com.mongodb.client.MongoClients; import com.mongodb.client.MongoClient; i . . . '' Encountered "=" at line 16, column 46.
*** Проблема авторизации (насколько я вижу, я использую ту же конфигурацию, успешно зарегистрированную из Spring в MongoDb
import com.mongodb.*
import com.mongodb.BasicDBObject
import org.bson.*
MongoCredential coreCredential = MongoCredential.createCredential("root", "demodb", "rootpassword".toCharArray());
MongoClient coreMongoClient = new MongoClient(new ServerAddress("localhost", 27017), Arrays.asList(coreCredential));
DB coreDB = coreMongoClient.getDB("demodb");
DBCollection coll = coreDB.getCollection("transfer");
BasicDBObject document = new BasicDBObject("id", "3")
.append("origem", "Jimis")
.append("destino", "drpc")
.append("status", 1);
coreDB.getCollection('transfer').insert(document);
Новая ошибка:
-06 18:59:39,561 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2020-04-06 18:59:39,588 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "errmsg" : "Authentication failed." , "code" : 18 , "codeName" : "AuthenticationFailed"}
javax.script.ScriptException: com.mongodb.CommandFailureException: { "serverUsed" : "localhost:27017" , "ok" : 0.0 , "errmsg" : "Authentication failed." , "code" : 18 , "codeName" : "AuthenticationFailed"}
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:324) ~[groovy-all-2.4.16.jar:2.4.16]
at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:72) ~[groovy-all-2.4.16.jar:2.4.16]
at javax.script.CompiledScript.eval(CompiledScript.java:89) ~[java.scripting:?]
at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:223) ~[ApacheJMeter_core.jar:5.2.1]
at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:71) [ApacheJMeter_java.jar:5.2.1]
PS .: Я где-то читал, я должен обновить JMeter MongoDb jar, так что я сделал (сейчас mon go - java -driver-2.13.2.jar)
*** Другое предварительное
Когда я пытаюсь
import com.gmongo.*;
import com.mongodb.*;
import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;
import com.mongodb.DBCollection;
DB db = MongoDBHolder.getDBFromSource("demodb://root:rootpassword@localhost:27017/?authSource=admin&ssl=true", "demodb");
DBCollection collection = db.getCollection("transfer");
long count = collection.getCount();
String result = String.valueOf(count); // convert long to String
//log.info("Log Resultado:" + result));
SampleResult.setResponseData("SampleResult Resultado: " + result,"UTF-8");
Я получаю
* 1 044 *
Кажется, он жалуется на MongoDB Source Config. Хорошо искал на Inte rnet Я не нашел, как настроить его в JMeter