Я написал следующий скрипт в Jmeter для вставки документа в MongoDB. Мой скрипт успешно выполняется, но не выполняет необходимую задачу, т.е. не вставляет запись в базу данных. Что мне не хватает? Может кто-нибудь PLZ помочь
import com.mongodb.client.MongoClients;
import com.mongodb.client.MongoClient;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoCollection;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
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");
//String json = ('{"EmployeeOID":12345,"EmployeeName":"Test Automation through Jmeter","Employee_Type_OID":4,"Rank":0,"Rating":0,"Score":0,"Supervisor_OID":56789,"TRGEmpID":"012345T"}');
//DBObject insertEmployee = (DBObject)JSON.parse(json);
BasicDBObject insertEmployee = new BasicDBObject();
insertEmployee.put("EmployeeOID",12345);
insertEmployee.put("EmployeeName", "Test Automation through Jmeter");
insertEmployee.put("Employee_Type_OID",4);
insertEmployee.put("Rank",0);
insertEmployee.put("Rating",0);
insertEmployee.put("Score",0);
insertEmployee.put("Supervisor_OID",56789);
insertEmployee.put("CompanyID","012345T");
collection.insert(insertEmployee);
DBCursor cursorDoc = collection.find();
while (cursorDoc.hasNext()) {
System.out.println(cursorDoc.next());
}
}
catch (Exception e) {
SampleResult.setSuccessful(false);
SampleResult.setResponseCode("500");
SampleResult.setResponseMessage("Exception: " + e);
}